summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Knaack <davidkna@users.noreply.github.com>2022-12-17 18:01:27 +0100
committerGitHub <noreply@github.com>2022-12-17 18:01:27 +0100
commitaa6c2dd5883d1ac6a48774f39a95ab7ee6f7f7ba (patch)
treeed446453f2eae89de6b369c27325bc319e560b17
parent220844daa014046bedbc9ce703f8b18fbe267e3c (diff)
chore: fix clippy warnings for rust 1.66 (#4715)
chore: fix new clippy lints
-rw-r--r--src/bug_report.rs2
-rw-r--r--src/configs/os.rs2
-rw-r--r--src/init/mod.rs7
-rw-r--r--src/logger.rs2
-rw-r--r--src/main.rs4
-rw-r--r--src/module.rs2
-rw-r--r--src/modules/aws.rs5
-rw-r--r--src/modules/git_branch.rs14
-rw-r--r--src/modules/haxe.rs14
-rw-r--r--src/modules/hg_branch.rs3
-rw-r--r--src/modules/kubernetes.rs10
-rw-r--r--src/modules/mod.rs2
-rw-r--r--src/modules/os.rs2
-rw-r--r--src/modules/rust.rs4
-rw-r--r--src/modules/utils/directory_nix.rs8
-rw-r--r--src/utils.rs8
16 files changed, 42 insertions, 47 deletions
diff --git a/src/bug_report.rs b/src/bug_report.rs
index 9d819e4be..39df1691f 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 73c84aba9..b42d8f96f 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 4289727e7..514398936 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 6a9b80627..ca0c21be1 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::<StarshipLogger>::default()).unwrap();
log::set_max_level(LevelFilter::Trace);
}
diff --git a/src/main.rs b/src/main.rs
index 80830f985..69bff9cfb 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 64518afd6..a2b2f1b28 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 eb9566e1d..014f6b779 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 5d743511a..f57b86572 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 de0a8133c..09d9e5cee 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 0ec4873ab..3aefd4b65 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 e0aee2bce..6fec82d72 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 8e463aa55..e9117054d 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 aa4d9b93f..77d9d83a0 100644
--- a/src/modules/os.rs
+++ b/src/modules/os.rs
@@ -77,7 +77,7 @@ fn get_type(os: &os_info::Info) -> Option<String> {
fn get_version(os: &os_info::Info) -> Option<String> {
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 b494761fb..5e5a97578 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<Str
Ok(formatted) => 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<Str
fn format_toolchain(toolchain: &str, default_host_triple: Option<&str>) -> 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 920d72cb2..110e5f955 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<bool, String> {
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<bool, String> {
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 6994290e8..06a5c2701 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"),
});