chore: fix clippy warnings for rust 1.66 (#4715)

chore: fix new clippy lints
This commit is contained in:
David Knaack 2022-12-17 18:01:27 +01:00 committed by GitHub
parent 220844daa0
commit aa6c2dd588
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 42 additions and 47 deletions

View File

@ -38,7 +38,7 @@ pub fn create() {
if input.trim().to_lowercase() == "y" { if input.trim().to_lowercase() == "y" {
let link = make_github_issue_link(&issue_body); let link = make_github_issue_link(&issue_body);
if let Err(e) = open::that(&link) { 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}"); println!("Please copy the above report and open an issue manually, or try opening the following link:\n{link}");
} }
} else { } else {

View File

@ -18,7 +18,7 @@ pub struct OSConfig<'a> {
impl<'a> OSConfig<'a> { impl<'a> OSConfig<'a> {
pub fn get_symbol(&self, key: &Type) -> Option<&'a str> { pub fn get_symbol(&self, key: &Type) -> Option<&'a str> {
self.symbols.get(key).cloned() self.symbols.get(key).copied()
} }
} }

View File

@ -183,7 +183,7 @@ pub fn init_stub(shell_name: &str) -> io::Result<()> {
"cmd" => print_script(CMDEXE_INIT, &StarshipPath::init()?.sprint_cmdexe()?), "cmd" => print_script(CMDEXE_INIT, &StarshipPath::init()?.sprint_cmdexe()?),
_ => { _ => {
eprintln!( 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\ For the time being, we support the following shells:\n\
* bash\n\ * bash\n\
* elvish\n\ * elvish\n\
@ -197,9 +197,8 @@ pub fn init_stub(shell_name: &str) -> io::Result<()> {
* cmd\n\ * cmd\n\
\n\ \n\
Please open an issue in the starship repo if you would like to \ Please open an issue in the starship repo if you would like to \
see support for {0}:\n\ see support for {shell_basename}:\n\
https://github.com/starship/starship/issues/new\n", https://github.com/starship/starship/issues/new\n"
shell_basename
) )
} }
}; };

View File

@ -133,6 +133,6 @@ impl log::Log for StarshipLogger {
} }
pub fn init() { pub fn init() {
log::set_boxed_logger(Box::new(StarshipLogger::default())).unwrap(); log::set_boxed_logger(Box::<StarshipLogger>::default()).unwrap();
log::set_max_level(LevelFilter::Trace); log::set_max_level(LevelFilter::Trace);
} }

View File

@ -184,7 +184,7 @@ fn main() {
println!("Supported modules list"); println!("Supported modules list");
println!("----------------------"); println!("----------------------");
for modules in ALL_MODULES { for modules in ALL_MODULES {
println!("{}", modules); println!("{modules}");
} }
} }
if let Some(module_name) = name { if let Some(module_name) = name {
@ -198,7 +198,7 @@ fn main() {
configure::update_configuration(&name, &value) configure::update_configuration(&name, &value)
} }
} else if let Err(reason) = configure::edit_configuration(None) { } 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); std::process::exit(1);
} }
} }

View File

@ -211,7 +211,7 @@ where
} }
} }
if let Segment::LineTerm = segment { if matches!(segment, Segment::LineTerm) {
break; break;
} }
} }

View File

@ -682,9 +682,8 @@ credential_process = /opt/bin/awscreds-retriever
"[astronauts] "[astronauts]
aws_access_key_id=dummy aws_access_key_id=dummy
aws_secret_access_key=dummy aws_secret_access_key=dummy
{}={} {key}={expiration_date}
", "
key, expiration_date
) )
.as_bytes(), .as_bytes(),
) )

View File

@ -491,10 +491,9 @@ mod tests {
toml::from_str(&format!( toml::from_str(&format!(
" "
[git_branch] [git_branch]
truncation_length = {} truncation_length = {truncate_length}
{} {config_options}
", "
truncate_length, config_options
)) ))
.unwrap(), .unwrap(),
) )
@ -530,10 +529,9 @@ mod tests {
toml::from_str(&format!( toml::from_str(&format!(
r#" r#"
[git_branch] [git_branch]
format = "{}" format = "{format}"
{} {config_options}
"#, "#
format, config_options
)) ))
.unwrap(), .unwrap(),
) )

View File

@ -132,7 +132,7 @@ mod tests {
"haxe --version", "haxe --version",
Some(CommandOutput { Some(CommandOutput {
stdout: "4.3.0-rc.1+\n".to_owned(), stdout: "4.3.0-rc.1+\n".to_owned(),
stderr: "".to_owned(), stderr: String::new(),
}), }),
) )
.path(dir.path()) .path(dir.path())
@ -151,7 +151,7 @@ mod tests {
"haxe --version", "haxe --version",
Some(CommandOutput { Some(CommandOutput {
stdout: "4.3.0-rc.1+\n".to_owned(), stdout: "4.3.0-rc.1+\n".to_owned(),
stderr: "".to_owned(), stderr: String::new(),
}), }),
) )
.path(dir.path()) .path(dir.path())
@ -173,7 +173,7 @@ mod tests {
"haxe --version", "haxe --version",
Some(CommandOutput { Some(CommandOutput {
stdout: "4.3.0-rc.1+\n".to_owned(), stdout: "4.3.0-rc.1+\n".to_owned(),
stderr: "".to_owned(), stderr: String::new(),
}), }),
) )
.path(dir.path()) .path(dir.path())
@ -201,7 +201,7 @@ mod tests {
"haxe --version", "haxe --version",
Some(CommandOutput { Some(CommandOutput {
stdout: "4.3.0-rc.1+\n".to_owned(), stdout: "4.3.0-rc.1+\n".to_owned(),
stderr: "".to_owned(), stderr: String::new(),
}), }),
) )
.path(dir.path()) .path(dir.path())
@ -230,7 +230,7 @@ mod tests {
"haxe --version", "haxe --version",
Some(CommandOutput { Some(CommandOutput {
stdout: "4.3.0-rc.1+\n".to_owned(), stdout: "4.3.0-rc.1+\n".to_owned(),
stderr: "".to_owned(), stderr: String::new(),
}), }),
) )
.path(dir.path()) .path(dir.path())
@ -260,7 +260,7 @@ mod tests {
"haxe --version", "haxe --version",
Some(CommandOutput { Some(CommandOutput {
stdout: "4.3.0-rc.1+\n".to_owned(), stdout: "4.3.0-rc.1+\n".to_owned(),
stderr: "".to_owned(), stderr: String::new(),
}), }),
) )
.path(dir.path()) .path(dir.path())
@ -290,7 +290,7 @@ mod tests {
"haxe --version", "haxe --version",
Some(CommandOutput { Some(CommandOutput {
stdout: "4.3.0-rc.1+\n".to_owned(), stdout: "4.3.0-rc.1+\n".to_owned(),
stderr: "".to_owned(), stderr: String::new(),
}), }),
) )
.path(dir.path()) .path(dir.path())

View File

@ -326,8 +326,7 @@ mod tests {
let expected = Some(format!( let expected = Some(format!(
"on {} ", "on {} ",
expect_style.paint(format!( expect_style.paint(format!(
"{} {}{}", "{expect_symbol} {expect_branch_name}{expect_truncation_symbol}"
expect_symbol, expect_branch_name, expect_truncation_symbol
)), )),
)); ));
assert_eq!(expected, actual); assert_eq!(expected, actual);

View File

@ -385,12 +385,11 @@ users: []
apiVersion: v1 apiVersion: v1
clusters: [] clusters: []
contexts: [] contexts: []
current-context: {} current-context: {ctx_name}
kind: Config kind: Config
preferences: {{}} preferences: {{}}
users: [] users: []
", "
ctx_name
) )
.as_bytes(), .as_bytes(),
)?; )?;
@ -695,15 +694,14 @@ clusters: []
contexts: contexts:
- context: - context:
cluster: test_cluster cluster: test_cluster
user: {} user: {user_name}
namespace: test_namespace namespace: test_namespace
name: test_context name: test_context
current-context: test_context current-context: test_context
kind: Config kind: Config
preferences: {{}} preferences: {{}}
users: [] users: []
", "
user_name
) )
.as_bytes(), .as_bytes(),
)?; )?;

View File

@ -11,7 +11,7 @@ mod cobol;
mod conda; mod conda;
mod container; mod container;
mod crystal; mod crystal;
pub(crate) mod custom; pub mod custom;
mod daml; mod daml;
mod dart; mod dart;
mod deno; mod deno;

View File

@ -77,7 +77,7 @@ fn get_type(os: &os_info::Info) -> Option<String> {
fn get_version(os: &os_info::Info) -> Option<String> { fn get_version(os: &os_info::Info) -> Option<String> {
Some(os.version()) Some(os.version())
.filter(|&x| x != &os_info::Version::Unknown) .filter(|&x| x != &os_info::Version::Unknown)
.map(|x| x.to_string()) .map(os_info::Version::to_string)
} }
#[cfg(test)] #[cfg(test)]

View File

@ -394,7 +394,7 @@ fn format_rustc_version(rustc_version: &str, version_format: &str) -> Option<Str
Ok(formatted) => Some(formatted), Ok(formatted) => Some(formatted),
Err(error) => { Err(error) => {
log::warn!("Error formatting `rust` version:\n{}", 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<Str
fn format_toolchain(toolchain: &str, default_host_triple: Option<&str>) -> String { fn format_toolchain(toolchain: &str, default_host_triple: Option<&str>) -> String {
default_host_triple default_host_triple
.map_or(toolchain, |triple| { .map_or(toolchain, |triple| {
toolchain.trim_end_matches(&format!("-{}", triple)) toolchain.trim_end_matches(&format!("-{triple}"))
}) })
.to_owned() .to_owned()
} }

View File

@ -13,6 +13,7 @@ use std::path::Path;
/// 2a) (not implemented on macOS) one of the supplementary groups of the current user is the /// 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 /// directory group owner and whether it has write access
/// 3) 'others' part of the access mask has the 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<bool, String> { pub fn is_write_allowed(folder_path: &Path) -> Result<bool, String> {
let meta = let meta =
fs::metadata(folder_path).map_err(|e| format!("Unable to stat() directory: {e:?}"))?; 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<bool, String> {
if euid.is_root() { if euid.is_root() {
return Ok(true); return Ok(true);
} }
if meta.uid() == euid.as_raw() { 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()) } else if (meta.gid() == Gid::effective().as_raw())
|| (get_supplementary_groups().contains(&meta.gid())) || (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 { } else {
Ok(perms & Mode::S_IWOTH.bits() as u32 != 0) Ok(perms & u32::from(Mode::S_IWOTH.bits()) != 0)
} }
} }

View File

@ -668,8 +668,8 @@ mod tests {
fn exec_no_output() { fn exec_no_output() {
let result = internal_exec_cmd("true", &[] as &[&OsStr], Duration::from_millis(500)); let result = internal_exec_cmd("true", &[] as &[&OsStr], Duration::from_millis(500));
let expected = Some(CommandOutput { let expected = Some(CommandOutput {
stdout: String::from(""), stdout: String::new(),
stderr: String::from(""), stderr: String::new(),
}); });
assert_eq!(result, expected) assert_eq!(result, expected)
@ -682,7 +682,7 @@ mod tests {
internal_exec_cmd("/bin/sh", &["-c", "echo hello"], Duration::from_millis(500)); internal_exec_cmd("/bin/sh", &["-c", "echo hello"], Duration::from_millis(500));
let expected = Some(CommandOutput { let expected = Some(CommandOutput {
stdout: String::from("hello\n"), stdout: String::from("hello\n"),
stderr: String::from(""), stderr: String::new(),
}); });
assert_eq!(result, expected) assert_eq!(result, expected)
@ -697,7 +697,7 @@ mod tests {
Duration::from_millis(500), Duration::from_millis(500),
); );
let expected = Some(CommandOutput { let expected = Some(CommandOutput {
stdout: String::from(""), stdout: String::new(),
stderr: String::from("hello\n"), stderr: String::from("hello\n"),
}); });