Merge branch 'master' into conditional-style

This commit is contained in:
Filip Bachul 2023-01-29 15:22:11 +01:00
commit 8e0eba6193
13 changed files with 40 additions and 47 deletions

20
Cargo.lock generated
View File

@ -283,9 +283,9 @@ dependencies = [
[[package]]
name = "clap"
version = "4.1.3"
version = "4.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8d93d855ce6a0aa87b8473ef9169482f40abaa2e9e0993024c35c902cbd5920"
checksum = "f13b9c79b5d1dd500d20ef541215a6423c75829ef43117e1b4d17fd8af0b5d76"
dependencies = [
"bitflags",
"clap_derive",
@ -2093,9 +2093,9 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
[[package]]
name = "pest"
version = "2.5.3"
version = "2.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4257b4a04d91f7e9e6290be5d3da4804dd5784fafde3a497d73eb2b4a158c30a"
checksum = "4ab62d2fa33726dbe6321cc97ef96d8cde531e3eeaf858a058de53a8a6d40d8f"
dependencies = [
"thiserror",
"ucd-trie",
@ -2103,9 +2103,9 @@ dependencies = [
[[package]]
name = "pest_derive"
version = "2.5.3"
version = "2.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "241cda393b0cdd65e62e07e12454f1f25d57017dcc514b1514cd3c4645e3a0a6"
checksum = "8bf026e2d0581559db66d837fe5242320f525d85c76283c61f4d51a1238d65ea"
dependencies = [
"pest",
"pest_generator",
@ -2113,9 +2113,9 @@ dependencies = [
[[package]]
name = "pest_generator"
version = "2.5.3"
version = "2.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46b53634d8c8196302953c74d5352f33d0c512a9499bd2ce468fc9f4128fa27c"
checksum = "2b27bd18aa01d91c8ed2b61ea23406a676b42d82609c6e2581fba42f0c15f17f"
dependencies = [
"pest",
"pest_meta",
@ -2126,9 +2126,9 @@ dependencies = [
[[package]]
name = "pest_meta"
version = "2.5.3"
version = "2.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ef4f1332a8d4678b41966bb4cc1d0676880e84183a1ecc3f4b69f03e99c7a51"
checksum = "9f02b677c1859756359fc9983c2e56a0237f18624a3789528804406b7e915e5d"
dependencies = [
"once_cell",
"pest",

View File

@ -43,7 +43,7 @@ git-repository-faster = ["git-features/zlib-stock", "git-repository/fast-sha1"]
[dependencies]
chrono = { version = "0.4.23", default-features = false, features = ["clock", "std", "wasmbind"] }
clap = { version = "4.1.3", features = ["derive", "cargo", "unicode"] }
clap = { version = "4.1.4", features = ["derive", "cargo", "unicode"] }
clap_complete = "4.1.1"
dirs-next = "2.0.0"
dunce = "1.0.3"
@ -62,8 +62,8 @@ open = "3.2.0"
# update os module config and tests when upgrading os_info
os_info = "3.5.1"
path-slash = "0.2.1"
pest = "2.5.3"
pest_derive = "2.5.3"
pest = "2.5.4"
pest_derive = "2.5.4"
quick-xml = "0.27.1"
rand = "0.8.5"
rayon = "1.6.1"

View File

@ -130,9 +130,7 @@ pub fn print_configuration(use_default: bool, paths: &[String]) {
fn extract_toml_paths(mut config: toml::Value, paths: &[String]) -> toml::Value {
// Extract all the requested sections into a new configuration.
let mut subset = toml::value::Table::new();
let config = if let Some(config) = config.as_table_mut() {
config
} else {
let Some(config) = config.as_table_mut() else {
// This function doesn't make any sense if the root is not a table.
return toml::Value::Table(subset);
};
@ -156,9 +154,7 @@ fn extract_toml_paths(mut config: toml::Value, paths: &[String]) -> toml::Value
}
// Extract the value to move.
let value = if let Some(value) = source_cursor.remove(end) {
value
} else {
let Some(value) = source_cursor.remove(end) else {
// We didn't find a value for this path, so move on to the next path.
continue 'paths;
};

View File

@ -250,9 +250,9 @@ impl<'a> Context<'a> {
}
/// Will lazily get repo root and branch when a module requests it.
pub fn get_repo(&self) -> Result<&Repo, git::discover::Error> {
pub fn get_repo(&self) -> Result<&Repo, Box<git::discover::Error>> {
self.repo
.get_or_try_init(|| -> Result<Repo, git::discover::Error> {
.get_or_try_init(|| -> Result<Repo, Box<git::discover::Error>> {
// custom open options
let mut git_open_opts_map =
git_sec::trust::Mapping::<git::open::Options>::default();
@ -286,7 +286,7 @@ impl<'a> Context<'a> {
Ok(repo) => repo,
Err(e) => {
log::debug!("Failed to find git repo: {e}");
return Err(e);
return Err(Box::new(e));
}
};

View File

@ -35,10 +35,9 @@ pub fn get_log_dir() -> PathBuf {
/// Deletes all log files in the log directory that were modified more than 24 hours ago.
pub fn cleanup_log_files<P: AsRef<Path>>(path: P) {
let log_dir = path.as_ref();
let log_files = match fs::read_dir(log_dir) {
Ok(log_files) => log_files,
let Ok(log_files) = fs::read_dir(log_dir) else {
// Avoid noisily handling errors in this cleanup function.
Err(_) => return,
return
};
for file in log_files {

View File

@ -52,9 +52,9 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
}
#[cfg(not(feature = "notify"))]
fn undistract_me<'a, 'b>(
fn undistract_me<'a>(
module: Module<'a>,
_config: &'b CmdDurationConfig,
_config: &CmdDurationConfig,
_context: &'a Context,
_elapsed: u128,
) -> Module<'a> {
@ -62,9 +62,9 @@ fn undistract_me<'a, 'b>(
}
#[cfg(feature = "notify")]
fn undistract_me<'a, 'b>(
fn undistract_me<'a>(
module: Module<'a>,
config: &'b CmdDurationConfig,
config: &CmdDurationConfig,
context: &'a Context,
elapsed: u128,
) -> Module<'a> {

View File

@ -26,7 +26,7 @@ pub fn module<'a>(name: Option<&str>, context: &'a Context) -> Option<Module<'a>
};
let mod_name = match name {
Some(name) => format!("env_var.{}", name),
Some(name) => format!("env_var.{name}"),
None => "env_var".to_owned(),
};
@ -78,7 +78,7 @@ fn filter_config(config: &toml::Value) -> Option<toml::Value> {
table
.iter()
.filter(|(_key, val)| !val.is_table())
.map(|(key, val)| (key.to_owned(), val.to_owned()))
.map(|(key, val)| (key.clone(), val.clone()))
.collect::<toml::value::Table>()
})
.filter(|table| !table.is_empty())

View File

@ -426,9 +426,10 @@ fn git_status_wsl(context: &Context, conf: &GitStatusConfig) -> Option<String> {
// Get foreign starship to use WSL config
// https://devblogs.microsoft.com/commandline/share-environment-vars-between-wsl-and-windows/
let wslenv = env::var("WSLENV")
.map(|e| e + ":STARSHIP_CONFIG/wp")
.unwrap_or_else(|_| "STARSHIP_CONFIG/wp".to_string());
let wslenv = env::var("WSLENV").map_or_else(
|_| "STARSHIP_CONFIG/wp".to_string(),
|e| e + ":STARSHIP_CONFIG/wp",
);
let out = match create_command(starship_exe)
.map(|mut c| {

View File

@ -41,7 +41,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let topic_graphemes = if let Ok(topic) = get_hg_topic_name(repo_root) {
truncate_text(&topic, len, config.truncation_symbol)
} else {
String::from("")
String::new()
};
let parsed = StringFormatter::new(config.format).and_then(|formatter| {

View File

@ -12,8 +12,8 @@ enum NixShellType {
}
impl NixShellType {
fn detect_shell_type(use_heuristic: bool, context: &Context) -> Option<NixShellType> {
use NixShellType::*;
fn detect_shell_type(use_heuristic: bool, context: &Context) -> Option<Self> {
use NixShellType::{Impure, Pure, Unknown};
let shell_type = context.get_env("IN_NIX_SHELL");
match shell_type.as_deref() {

View File

@ -93,13 +93,11 @@ fn get_engines_version(context: &Context) -> Option<String> {
}
fn check_engines_version(nodejs_version: Option<&str>, engines_version: Option<String>) -> bool {
let (nodejs_version, engines_version) = match (nodejs_version, engines_version) {
(Some(nv), Some(ev)) => (nv, ev),
_ => return true,
let (Some(nodejs_version), Some(engines_version)) = (nodejs_version, engines_version) else {
return true;
};
let r = match VersionReq::parse(&engines_version) {
Ok(r) => r,
Err(_e) => return true,
let Ok(r) = VersionReq::parse(&engines_version) else {
return true;
};
let re = Regex::new(r"\d+\.\d+\.\d+").unwrap();
let version = re

View File

@ -80,9 +80,8 @@ fn create_offset_time_string(
);
if utc_time_offset_in_hours < 24_f32 && utc_time_offset_in_hours > -24_f32 {
let utc_offset_in_seconds: i32 = (utc_time_offset_in_hours * 3600_f32) as i32;
let timezone_offset = match FixedOffset::east_opt(utc_offset_in_seconds) {
Some(offset) => offset,
None => return Err("Invalid offset"),
let Some(timezone_offset) = FixedOffset::east_opt(utc_offset_in_seconds) else {
return Err("Invalid offset")
};
log::trace!("Target timezone offset is {}", timezone_offset);

View File

@ -334,7 +334,7 @@ fn handle_module<'a>(
for (child, config) in context
.config
.get_config(&[module])
.and_then(|config| config.as_table().map(|t| t.iter()))
.and_then(|config| config.as_table().map(toml::map::Map::iter))
.into_iter()
.flatten()
{