diff options
author | David Knaack <davidkna@users.noreply.github.com> | 2023-12-30 17:29:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-30 17:29:37 +0100 |
commit | cd0fdb7ce0501cd101c7bb33352efcf609f72c80 (patch) | |
tree | 3b8a513b385b50ff167b74253ee687e28eed5e5f /src/modules | |
parent | 89dc19214bb671fe50a8f1be79a4594e7998ddea (diff) |
chore: apply new rust 1.75 & nightly clippy fixes (#5646)
chore: apply clippy fixes
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/direnv.rs | 26 | ||||
-rw-r--r-- | src/modules/dotnet.rs | 4 | ||||
-rw-r--r-- | src/modules/fossil_metrics.rs | 4 | ||||
-rw-r--r-- | src/modules/kubernetes.rs | 21 | ||||
-rw-r--r-- | src/modules/nix_shell.rs | 2 | ||||
-rw-r--r-- | src/modules/openstack.rs | 2 | ||||
-rw-r--r-- | src/modules/python.rs | 8 | ||||
-rw-r--r-- | src/modules/rust.rs | 12 | ||||
-rw-r--r-- | src/modules/shlvl.rs | 2 |
9 files changed, 42 insertions, 39 deletions
diff --git a/src/modules/direnv.rs b/src/modules/direnv.rs index 4f67800ea..6378cb96e 100644 --- a/src/modules/direnv.rs +++ b/src/modules/direnv.rs @@ -117,8 +117,8 @@ impl FromStr for AllowStatus { fn from_str(s: &str) -> Result<Self, Self::Err> { match s { - "true" => Ok(AllowStatus::Allowed), - "false" => Ok(AllowStatus::Denied), + "true" => Ok(Self::Allowed), + "false" => Ok(Self::Denied), _ => Err(Cow::from("invalid allow status")), } } @@ -152,7 +152,7 @@ mod tests { let dir = tempfile::tempdir()?; let rc_path = dir.path().join(".envrc"); - std::fs::File::create(&rc_path)?.sync_all()?; + std::fs::File::create(rc_path)?.sync_all()?; let renderer = ModuleRenderer::new("direnv") .config(toml::toml! { @@ -169,7 +169,7 @@ mod tests { ); assert_eq!( - Some(format!("direnv not loaded/allowed ")), + Some("direnv not loaded/allowed ".to_string()), renderer.collect() ); @@ -180,7 +180,7 @@ mod tests { let dir = tempfile::tempdir()?; let rc_path = dir.path().join(".envrc"); - std::fs::File::create(&rc_path)?.sync_all()?; + std::fs::File::create(rc_path)?.sync_all()?; let renderer = ModuleRenderer::new("direnv") .config(toml::toml! { @@ -196,7 +196,10 @@ mod tests { }), ); - assert_eq!(Some(format!("direnv loaded/allowed ")), renderer.collect()); + assert_eq!( + Some("direnv loaded/allowed ".to_string()), + renderer.collect() + ); dir.close() } @@ -205,7 +208,7 @@ mod tests { let dir = tempfile::tempdir()?; let rc_path = dir.path().join(".envrc"); - std::fs::File::create(&rc_path)?.sync_all()?; + std::fs::File::create(rc_path)?.sync_all()?; let renderer = ModuleRenderer::new("direnv") .config(toml::toml! { @@ -221,13 +224,16 @@ mod tests { }), ); - assert_eq!(Some(format!("direnv loaded/denied ")), renderer.collect()); + assert_eq!( + Some("direnv loaded/denied ".to_string()), + renderer.collect() + ); dir.close() } fn status_cmd_output_without_rc() -> String { String::from( - r#"\ + r"\ direnv exec path /usr/bin/direnv DIRENV_CONFIG /home/test/.config/direnv bash_path /usr/bin/bash @@ -236,7 +242,7 @@ warn_timeout 5s whitelist.prefix [] whitelist.exact map[] No .envrc or .env loaded -No .envrc or .env found"#, +No .envrc or .env found", ) } fn status_cmd_output_with_rc(dir: impl AsRef<Path>, loaded: bool, allowed: bool) -> String { diff --git a/src/modules/dotnet.rs b/src/modules/dotnet.rs index e3c59008a..4539b4d58 100644 --- a/src/modules/dotnet.rs +++ b/src/modules/dotnet.rs @@ -599,13 +599,13 @@ mod tests { } fn make_csproj_with_tfm(tfm_element: &str, tfm: &str) -> String { - let json_text = r#" + let json_text = r" <Project> <PropertyGroup> <TFM_ELEMENT>TFM_VALUE</TFM_ELEMENT> </PropertyGroup> </Project> - "#; + "; json_text .replace("TFM_ELEMENT", tfm_element) .replace("TFM_VALUE", tfm) diff --git a/src/modules/fossil_metrics.rs b/src/modules/fossil_metrics.rs index 5ec97b6c1..45ceb2b40 100644 --- a/src/modules/fossil_metrics.rs +++ b/src/modules/fossil_metrics.rs @@ -287,10 +287,10 @@ mod tests { "{}{}", expect_added .map(|added| format!("{} ", expect_added_style.paint(format!("+{added}")))) - .unwrap_or(String::from("")), + .unwrap_or_default(), expect_deleted .map(|deleted| format!("{} ", expect_deleted_style.paint(format!("-{deleted}")))) - .unwrap_or(String::from("")), + .unwrap_or_default(), )); assert_eq!(expected, actual); } diff --git a/src/modules/kubernetes.rs b/src/modules/kubernetes.rs index c56514ba8..042f47734 100644 --- a/src/modules/kubernetes.rs +++ b/src/modules/kubernetes.rs @@ -21,7 +21,7 @@ fn get_current_kube_context_name(filename: path::PathBuf) -> Option<String> { let contents = utils::read_file(filename).ok()?; let yaml_docs = YamlLoader::load_from_str(&contents).ok()?; - let conf = yaml_docs.get(0)?; + let conf = yaml_docs.first()?; conf["current-context"] .as_str() .filter(|s| !s.is_empty()) @@ -35,7 +35,7 @@ fn get_kube_ctx_components( let contents = utils::read_file(filename).ok()?; let yaml_docs = YamlLoader::load_from_str(&contents).ok()?; - let conf = yaml_docs.get(0)?; + let conf = yaml_docs.first()?; let contexts = conf["contexts"].as_vec()?; // Find the context with the name we're looking for @@ -118,16 +118,13 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { .any(|v| !v.is_empty()); let is_kube_project = have_scan_config.then(|| { - context - .try_begin_scan() - .map(|scanner| { - scanner - .set_files(&config.detect_files) - .set_folders(&config.detect_folders) - .set_extensions(&config.detect_extensions) - .is_match() - }) - .unwrap_or(false) + context.try_begin_scan().map_or(false, |scanner| { + scanner + .set_files(&config.detect_files) + .set_folders(&config.detect_folders) + .set_extensions(&config.detect_extensions) + .is_match() + }) }); if !is_kube_project.unwrap_or(true) { diff --git a/src/modules/nix_shell.rs b/src/modules/nix_shell.rs index d8666ee84..4d5cc9a11 100644 --- a/src/modules/nix_shell.rs +++ b/src/modules/nix_shell.rs @@ -23,7 +23,7 @@ impl NixShellType { }; if use_heuristic { - Self::in_new_nix_shell(context).map(|_| Unknown) + Self::in_new_nix_shell(context).map(|()| Unknown) } else { None } diff --git a/src/modules/openstack.rs b/src/modules/openstack.rs index 35c488bab..d5e59f63d 100644 --- a/src/modules/openstack.rs +++ b/src/modules/openstack.rs @@ -27,7 +27,7 @@ fn get_osp_project_from_config(context: &Context, osp_cloud: &str) -> Option<Pro .filter_map(|file| { let config = utils::read_file(file.as_ref()?).ok()?; let clouds = YamlLoader::load_from_str(config.as_str()).ok()?; - clouds.get(0)?["clouds"][osp_cloud]["auth"]["project_name"] + clouds.first()?["clouds"][osp_cloud]["auth"]["project_name"] .as_str() .map(ToOwned::to_owned) }) diff --git a/src/modules/python.rs b/src/modules/python.rs index d2b3cdec6..df4cfab5f 100644 --- a/src/modules/python.rs +++ b/src/modules/python.rs @@ -376,10 +376,10 @@ Python 3.7.9 (7e6e2bb30ac5fbdbd443619cae28c51d5c162a02, Nov 24 2020, 10:03:59) create_dir_all(dir.path().join("my_venv"))?; let mut venv_cfg = File::create(dir.path().join("my_venv").join("pyvenv.cfg"))?; venv_cfg.write_all( - br#" + br" home = something prompt = 'foo' - "#, + ", )?; venv_cfg.sync_all()?; @@ -403,10 +403,10 @@ prompt = 'foo' create_dir_all(dir.path().join("my_venv"))?; let mut venv_cfg = File::create(dir.path().join("my_venv").join("pyvenv.cfg"))?; venv_cfg.write_all( - br#" + br" home = something prompt = '(foo)' - "#, + ", )?; venv_cfg.sync_all()?; diff --git a/src/modules/rust.rs b/src/modules/rust.rs index 221111ea1..6544eba77 100644 --- a/src/modules/rust.rs +++ b/src/modules/rust.rs @@ -914,32 +914,32 @@ version = "12" };
}
- static STABLE: &str = r#"rustc 1.40.0 (73528e339 2019-12-16)
+ static STABLE: &str = r"rustc 1.40.0 (73528e339 2019-12-16)
binary: rustc
commit-hash: 73528e339aae0f17a15ffa49a8ac608f50c6cf14
commit-date: 2019-12-16
host: x86_64-unknown-linux-gnu
release: 1.40.0
LLVM version: 9.0
-"#;
+";
- static BETA: &str = r#"rustc 1.41.0-beta.1 (eb3f7c2d3 2019-12-17)
+ static BETA: &str = r"rustc 1.41.0-beta.1 (eb3f7c2d3 2019-12-17)
binary: rustc
commit-hash: eb3f7c2d3aec576f47eba854cfbd3c1187b8a2a0
commit-date: 2019-12-17
host: x86_64-unknown-linux-gnu
release: 1.41.0-beta.1
LLVM version: 9.0
-"#;
+";
- static NIGHTLY: &str = r#"rustc 1.42.0-nightly (da3629b05 2019-12-29)
+ static NIGHTLY: &str = r"rustc 1.42.0-nightly (da3629b05 2019-12-29)
binary: rustc
commit-hash: da3629b05f8f1b425a738bfe9fe9aedd47c5417a
commit-date: 2019-12-29
host: x86_64-unknown-linux-gnu
release: 1.42.0-nightly
LLVM version: 9.0
-"#;
+";
test!(
(STABLE, None) => Some(("v1.40.0", "x86_64-unknown-linux-gnu")),
diff --git a/src/modules/shlvl.rs b/src/modules/shlvl.rs index 48d22ec89..03e32728e 100644 --- a/src/modules/shlvl.rs +++ b/src/modules/shlvl.rs @@ -242,7 +242,7 @@ mod tests { disabled = false threshold = threshold }) - .env(SHLVL_ENV_VAR, format!("{}", shlvl)) + .env(SHLVL_ENV_VAR, format!("{shlvl}")) .collect() } |