From aa6c2dd5883d1ac6a48774f39a95ab7ee6f7f7ba Mon Sep 17 00:00:00 2001 From: David Knaack Date: Sat, 17 Dec 2022 18:01:27 +0100 Subject: [PATCH] chore: fix clippy warnings for rust 1.66 (#4715) chore: fix new clippy lints --- src/bug_report.rs | 2 +- src/configs/os.rs | 2 +- src/init/mod.rs | 7 +++---- src/logger.rs | 2 +- src/main.rs | 4 ++-- src/module.rs | 2 +- src/modules/aws.rs | 5 ++--- src/modules/git_branch.rs | 14 ++++++-------- src/modules/haxe.rs | 14 +++++++------- src/modules/hg_branch.rs | 3 +-- src/modules/kubernetes.rs | 10 ++++------ src/modules/mod.rs | 2 +- src/modules/os.rs | 2 +- src/modules/rust.rs | 4 ++-- src/modules/utils/directory_nix.rs | 8 +++++--- src/utils.rs | 8 ++++---- 16 files changed, 42 insertions(+), 47 deletions(-) diff --git a/src/bug_report.rs b/src/bug_report.rs index 9d819e4b..39df1691 100644 --- a/src/bug_report.rs +++ b/src/bug_report.rs @@ -38,7 +38,7 @@ pub fn create() { if input.trim().to_lowercase() == "y" { let link = make_github_issue_link(&issue_body); if let Err(e) = open::that(&link) { - println!("Failed to open issue report in your browser: {}", e); + println!("Failed to open issue report in your browser: {e}"); println!("Please copy the above report and open an issue manually, or try opening the following link:\n{link}"); } } else { diff --git a/src/configs/os.rs b/src/configs/os.rs index 73c84aba..b42d8f96 100644 --- a/src/configs/os.rs +++ b/src/configs/os.rs @@ -18,7 +18,7 @@ pub struct OSConfig<'a> { impl<'a> OSConfig<'a> { pub fn get_symbol(&self, key: &Type) -> Option<&'a str> { - self.symbols.get(key).cloned() + self.symbols.get(key).copied() } } diff --git a/src/init/mod.rs b/src/init/mod.rs index 4289727e..51439893 100644 --- a/src/init/mod.rs +++ b/src/init/mod.rs @@ -183,7 +183,7 @@ pub fn init_stub(shell_name: &str) -> io::Result<()> { "cmd" => print_script(CMDEXE_INIT, &StarshipPath::init()?.sprint_cmdexe()?), _ => { eprintln!( - "{0} is not yet supported by starship.\n\ + "{shell_basename} is not yet supported by starship.\n\ For the time being, we support the following shells:\n\ * bash\n\ * elvish\n\ @@ -197,9 +197,8 @@ pub fn init_stub(shell_name: &str) -> io::Result<()> { * cmd\n\ \n\ Please open an issue in the starship repo if you would like to \ - see support for {0}:\n\ - https://github.com/starship/starship/issues/new\n", - shell_basename + see support for {shell_basename}:\n\ + https://github.com/starship/starship/issues/new\n" ) } }; diff --git a/src/logger.rs b/src/logger.rs index 6a9b8062..ca0c21be 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -133,6 +133,6 @@ impl log::Log for StarshipLogger { } pub fn init() { - log::set_boxed_logger(Box::new(StarshipLogger::default())).unwrap(); + log::set_boxed_logger(Box::::default()).unwrap(); log::set_max_level(LevelFilter::Trace); } diff --git a/src/main.rs b/src/main.rs index 80830f98..69bff9cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -184,7 +184,7 @@ fn main() { println!("Supported modules list"); println!("----------------------"); for modules in ALL_MODULES { - println!("{}", modules); + println!("{modules}"); } } if let Some(module_name) = name { @@ -198,7 +198,7 @@ fn main() { configure::update_configuration(&name, &value) } } else if let Err(reason) = configure::edit_configuration(None) { - eprintln!("Could not edit configuration: {}", reason); + eprintln!("Could not edit configuration: {reason}"); std::process::exit(1); } } diff --git a/src/module.rs b/src/module.rs index 64518afd..a2b2f1b2 100644 --- a/src/module.rs +++ b/src/module.rs @@ -211,7 +211,7 @@ where } } - if let Segment::LineTerm = segment { + if matches!(segment, Segment::LineTerm) { break; } } diff --git a/src/modules/aws.rs b/src/modules/aws.rs index eb9566e1..014f6b77 100644 --- a/src/modules/aws.rs +++ b/src/modules/aws.rs @@ -682,9 +682,8 @@ credential_process = /opt/bin/awscreds-retriever "[astronauts] aws_access_key_id=dummy aws_secret_access_key=dummy -{}={} -", - key, expiration_date +{key}={expiration_date} +" ) .as_bytes(), ) diff --git a/src/modules/git_branch.rs b/src/modules/git_branch.rs index 5d743511..f57b8657 100644 --- a/src/modules/git_branch.rs +++ b/src/modules/git_branch.rs @@ -491,10 +491,9 @@ mod tests { toml::from_str(&format!( " [git_branch] - truncation_length = {} - {} - ", - truncate_length, config_options + truncation_length = {truncate_length} + {config_options} + " )) .unwrap(), ) @@ -530,10 +529,9 @@ mod tests { toml::from_str(&format!( r#" [git_branch] - format = "{}" - {} - "#, - format, config_options + format = "{format}" + {config_options} + "# )) .unwrap(), ) diff --git a/src/modules/haxe.rs b/src/modules/haxe.rs index de0a8133..09d9e5ce 100644 --- a/src/modules/haxe.rs +++ b/src/modules/haxe.rs @@ -132,7 +132,7 @@ mod tests { "haxe --version", Some(CommandOutput { stdout: "4.3.0-rc.1+\n".to_owned(), - stderr: "".to_owned(), + stderr: String::new(), }), ) .path(dir.path()) @@ -151,7 +151,7 @@ mod tests { "haxe --version", Some(CommandOutput { stdout: "4.3.0-rc.1+\n".to_owned(), - stderr: "".to_owned(), + stderr: String::new(), }), ) .path(dir.path()) @@ -173,7 +173,7 @@ mod tests { "haxe --version", Some(CommandOutput { stdout: "4.3.0-rc.1+\n".to_owned(), - stderr: "".to_owned(), + stderr: String::new(), }), ) .path(dir.path()) @@ -201,7 +201,7 @@ mod tests { "haxe --version", Some(CommandOutput { stdout: "4.3.0-rc.1+\n".to_owned(), - stderr: "".to_owned(), + stderr: String::new(), }), ) .path(dir.path()) @@ -230,7 +230,7 @@ mod tests { "haxe --version", Some(CommandOutput { stdout: "4.3.0-rc.1+\n".to_owned(), - stderr: "".to_owned(), + stderr: String::new(), }), ) .path(dir.path()) @@ -260,7 +260,7 @@ mod tests { "haxe --version", Some(CommandOutput { stdout: "4.3.0-rc.1+\n".to_owned(), - stderr: "".to_owned(), + stderr: String::new(), }), ) .path(dir.path()) @@ -290,7 +290,7 @@ mod tests { "haxe --version", Some(CommandOutput { stdout: "4.3.0-rc.1+\n".to_owned(), - stderr: "".to_owned(), + stderr: String::new(), }), ) .path(dir.path()) diff --git a/src/modules/hg_branch.rs b/src/modules/hg_branch.rs index 0ec4873a..3aefd4b6 100644 --- a/src/modules/hg_branch.rs +++ b/src/modules/hg_branch.rs @@ -326,8 +326,7 @@ mod tests { let expected = Some(format!( "on {} ", expect_style.paint(format!( - "{} {}{}", - expect_symbol, expect_branch_name, expect_truncation_symbol + "{expect_symbol} {expect_branch_name}{expect_truncation_symbol}" )), )); assert_eq!(expected, actual); diff --git a/src/modules/kubernetes.rs b/src/modules/kubernetes.rs index e0aee2bc..6fec82d7 100644 --- a/src/modules/kubernetes.rs +++ b/src/modules/kubernetes.rs @@ -385,12 +385,11 @@ users: [] apiVersion: v1 clusters: [] contexts: [] -current-context: {} +current-context: {ctx_name} kind: Config preferences: {{}} users: [] -", - ctx_name +" ) .as_bytes(), )?; @@ -695,15 +694,14 @@ clusters: [] contexts: - context: cluster: test_cluster - user: {} + user: {user_name} namespace: test_namespace name: test_context current-context: test_context kind: Config preferences: {{}} users: [] -", - user_name +" ) .as_bytes(), )?; diff --git a/src/modules/mod.rs b/src/modules/mod.rs index 8e463aa5..e9117054 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -11,7 +11,7 @@ mod cobol; mod conda; mod container; mod crystal; -pub(crate) mod custom; +pub mod custom; mod daml; mod dart; mod deno; diff --git a/src/modules/os.rs b/src/modules/os.rs index aa4d9b93..77d9d83a 100644 --- a/src/modules/os.rs +++ b/src/modules/os.rs @@ -77,7 +77,7 @@ fn get_type(os: &os_info::Info) -> Option { fn get_version(os: &os_info::Info) -> Option { Some(os.version()) .filter(|&x| x != &os_info::Version::Unknown) - .map(|x| x.to_string()) + .map(os_info::Version::to_string) } #[cfg(test)] diff --git a/src/modules/rust.rs b/src/modules/rust.rs index b494761f..5e5a9757 100644 --- a/src/modules/rust.rs +++ b/src/modules/rust.rs @@ -394,7 +394,7 @@ fn format_rustc_version(rustc_version: &str, version_format: &str) -> Option Some(formatted), Err(error) => { log::warn!("Error formatting `rust` version:\n{}", error); - Some(format!("v{}", version)) + Some(format!("v{version}")) } } } @@ -402,7 +402,7 @@ fn format_rustc_version(rustc_version: &str, version_format: &str) -> Option) -> String { default_host_triple .map_or(toolchain, |triple| { - toolchain.trim_end_matches(&format!("-{}", triple)) + toolchain.trim_end_matches(&format!("-{triple}")) }) .to_owned() } diff --git a/src/modules/utils/directory_nix.rs b/src/modules/utils/directory_nix.rs index 920d72cb..110e5f95 100644 --- a/src/modules/utils/directory_nix.rs +++ b/src/modules/utils/directory_nix.rs @@ -13,6 +13,7 @@ use std::path::Path; /// 2a) (not implemented on macOS) one of the supplementary groups of the current user is the /// directory group owner and whether it has write access /// 3) 'others' part of the access mask has the write access +#[allow(clippy::useless_conversion)] // On some platforms it is not u32 pub fn is_write_allowed(folder_path: &Path) -> Result { let meta = fs::metadata(folder_path).map_err(|e| format!("Unable to stat() directory: {e:?}"))?; @@ -22,14 +23,15 @@ pub fn is_write_allowed(folder_path: &Path) -> Result { if euid.is_root() { return Ok(true); } + if meta.uid() == euid.as_raw() { - Ok(perms & Mode::S_IWUSR.bits() as u32 != 0) + Ok(perms & u32::from(Mode::S_IWUSR.bits()) != 0) } else if (meta.gid() == Gid::effective().as_raw()) || (get_supplementary_groups().contains(&meta.gid())) { - Ok(perms & Mode::S_IWGRP.bits() as u32 != 0) + Ok(perms & u32::from(Mode::S_IWGRP.bits()) != 0) } else { - Ok(perms & Mode::S_IWOTH.bits() as u32 != 0) + Ok(perms & u32::from(Mode::S_IWOTH.bits()) != 0) } } diff --git a/src/utils.rs b/src/utils.rs index 6994290e..06a5c270 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -668,8 +668,8 @@ mod tests { fn exec_no_output() { let result = internal_exec_cmd("true", &[] as &[&OsStr], Duration::from_millis(500)); let expected = Some(CommandOutput { - stdout: String::from(""), - stderr: String::from(""), + stdout: String::new(), + stderr: String::new(), }); assert_eq!(result, expected) @@ -682,7 +682,7 @@ mod tests { internal_exec_cmd("/bin/sh", &["-c", "echo hello"], Duration::from_millis(500)); let expected = Some(CommandOutput { stdout: String::from("hello\n"), - stderr: String::from(""), + stderr: String::new(), }); assert_eq!(result, expected) @@ -697,7 +697,7 @@ mod tests { Duration::from_millis(500), ); let expected = Some(CommandOutput { - stdout: String::from(""), + stdout: String::new(), stderr: String::from("hello\n"), });