chore: apply new rust 1.75 & nightly clippy fixes (#5646)

chore: apply clippy fixes
This commit is contained in:
David Knaack 2023-12-30 17:29:37 +01:00 committed by GitHub
parent 89dc19214b
commit cd0fdb7ce0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 49 additions and 46 deletions

View File

@ -244,7 +244,7 @@ impl<'a> Context<'a> {
.any(|env_var| self.get_env(env_var).is_some()) .any(|env_var| self.get_env(env_var).is_some())
} }
/// Returns true if 'detect_env_vars' is empty, /// Returns true if `detect_env_vars` is empty,
/// or if at least one environment variable is set and no negated environment variable is set /// or if at least one environment variable is set and no negated environment variable is set
pub fn detect_env_vars(&'a self, env_vars: &'a [&'a str]) -> bool { pub fn detect_env_vars(&'a self, env_vars: &'a [&'a str]) -> bool {
if env_vars.is_empty() { if env_vars.is_empty() {

View File

@ -188,7 +188,7 @@ fn main() {
(_, _, true) => Target::Continuation, (_, _, true) => Target::Continuation,
(_, _, _) => Target::Main, (_, _, _) => Target::Main,
}; };
print::prompt(properties, target) print::prompt(properties, target);
} }
Commands::Module { Commands::Module {
name, name,
@ -211,7 +211,7 @@ fn main() {
let context = Context::default(); let context = Context::default();
if let Some(name) = name { if let Some(name) = name {
if let Some(value) = value { if let Some(value) = value {
configure::update_configuration(&context, &name, &value) configure::update_configuration(&context, &name, &value);
} }
} else if let Err(reason) = configure::edit_configuration(&context, None) { } else if let Err(reason) = configure::edit_configuration(&context, None) {
eprintln!("Could not edit configuration: {reason}"); eprintln!("Could not edit configuration: {reason}");
@ -222,7 +222,7 @@ fn main() {
configure::print_configuration(&Context::default(), default, &name); configure::print_configuration(&Context::default(), default, &name);
} }
Commands::Toggle { name, value } => { Commands::Toggle { name, value } => {
configure::toggle_configuration(&Context::default(), &name, &value) configure::toggle_configuration(&Context::default(), &name, &value);
} }
Commands::BugReport => bug_report::create(), Commands::BugReport => bug_report::create(),
Commands::Time => { Commands::Time => {

View File

@ -117,8 +117,8 @@ impl FromStr for AllowStatus {
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
match s { match s {
"true" => Ok(AllowStatus::Allowed), "true" => Ok(Self::Allowed),
"false" => Ok(AllowStatus::Denied), "false" => Ok(Self::Denied),
_ => Err(Cow::from("invalid allow status")), _ => Err(Cow::from("invalid allow status")),
} }
} }
@ -152,7 +152,7 @@ mod tests {
let dir = tempfile::tempdir()?; let dir = tempfile::tempdir()?;
let rc_path = dir.path().join(".envrc"); 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") let renderer = ModuleRenderer::new("direnv")
.config(toml::toml! { .config(toml::toml! {
@ -169,7 +169,7 @@ mod tests {
); );
assert_eq!( assert_eq!(
Some(format!("direnv not loaded/allowed ")), Some("direnv not loaded/allowed ".to_string()),
renderer.collect() renderer.collect()
); );
@ -180,7 +180,7 @@ mod tests {
let dir = tempfile::tempdir()?; let dir = tempfile::tempdir()?;
let rc_path = dir.path().join(".envrc"); 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") let renderer = ModuleRenderer::new("direnv")
.config(toml::toml! { .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() dir.close()
} }
@ -205,7 +208,7 @@ mod tests {
let dir = tempfile::tempdir()?; let dir = tempfile::tempdir()?;
let rc_path = dir.path().join(".envrc"); 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") let renderer = ModuleRenderer::new("direnv")
.config(toml::toml! { .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() dir.close()
} }
fn status_cmd_output_without_rc() -> String { fn status_cmd_output_without_rc() -> String {
String::from( String::from(
r#"\ r"\
direnv exec path /usr/bin/direnv direnv exec path /usr/bin/direnv
DIRENV_CONFIG /home/test/.config/direnv DIRENV_CONFIG /home/test/.config/direnv
bash_path /usr/bin/bash bash_path /usr/bin/bash
@ -236,7 +242,7 @@ warn_timeout 5s
whitelist.prefix [] whitelist.prefix []
whitelist.exact map[] whitelist.exact map[]
No .envrc or .env loaded 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 { fn status_cmd_output_with_rc(dir: impl AsRef<Path>, loaded: bool, allowed: bool) -> String {

View File

@ -599,13 +599,13 @@ mod tests {
} }
fn make_csproj_with_tfm(tfm_element: &str, tfm: &str) -> String { fn make_csproj_with_tfm(tfm_element: &str, tfm: &str) -> String {
let json_text = r#" let json_text = r"
<Project> <Project>
<PropertyGroup> <PropertyGroup>
<TFM_ELEMENT>TFM_VALUE</TFM_ELEMENT> <TFM_ELEMENT>TFM_VALUE</TFM_ELEMENT>
</PropertyGroup> </PropertyGroup>
</Project> </Project>
"#; ";
json_text json_text
.replace("TFM_ELEMENT", tfm_element) .replace("TFM_ELEMENT", tfm_element)
.replace("TFM_VALUE", tfm) .replace("TFM_VALUE", tfm)

View File

@ -287,10 +287,10 @@ mod tests {
"{}{}", "{}{}",
expect_added expect_added
.map(|added| format!("{} ", expect_added_style.paint(format!("+{added}")))) .map(|added| format!("{} ", expect_added_style.paint(format!("+{added}"))))
.unwrap_or(String::from("")), .unwrap_or_default(),
expect_deleted expect_deleted
.map(|deleted| format!("{} ", expect_deleted_style.paint(format!("-{deleted}")))) .map(|deleted| format!("{} ", expect_deleted_style.paint(format!("-{deleted}"))))
.unwrap_or(String::from("")), .unwrap_or_default(),
)); ));
assert_eq!(expected, actual); assert_eq!(expected, actual);
} }

View File

@ -21,7 +21,7 @@ fn get_current_kube_context_name(filename: path::PathBuf) -> Option<String> {
let contents = utils::read_file(filename).ok()?; let contents = utils::read_file(filename).ok()?;
let yaml_docs = YamlLoader::load_from_str(&contents).ok()?; let yaml_docs = YamlLoader::load_from_str(&contents).ok()?;
let conf = yaml_docs.get(0)?; let conf = yaml_docs.first()?;
conf["current-context"] conf["current-context"]
.as_str() .as_str()
.filter(|s| !s.is_empty()) .filter(|s| !s.is_empty())
@ -35,7 +35,7 @@ fn get_kube_ctx_components(
let contents = utils::read_file(filename).ok()?; let contents = utils::read_file(filename).ok()?;
let yaml_docs = YamlLoader::load_from_str(&contents).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()?; let contexts = conf["contexts"].as_vec()?;
// Find the context with the name we're looking for // 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()); .any(|v| !v.is_empty());
let is_kube_project = have_scan_config.then(|| { let is_kube_project = have_scan_config.then(|| {
context context.try_begin_scan().map_or(false, |scanner| {
.try_begin_scan()
.map(|scanner| {
scanner scanner
.set_files(&config.detect_files) .set_files(&config.detect_files)
.set_folders(&config.detect_folders) .set_folders(&config.detect_folders)
.set_extensions(&config.detect_extensions) .set_extensions(&config.detect_extensions)
.is_match() .is_match()
}) })
.unwrap_or(false)
}); });
if !is_kube_project.unwrap_or(true) { if !is_kube_project.unwrap_or(true) {

View File

@ -23,7 +23,7 @@ impl NixShellType {
}; };
if use_heuristic { if use_heuristic {
Self::in_new_nix_shell(context).map(|_| Unknown) Self::in_new_nix_shell(context).map(|()| Unknown)
} else { } else {
None None
} }

View File

@ -27,7 +27,7 @@ fn get_osp_project_from_config(context: &Context, osp_cloud: &str) -> Option<Pro
.filter_map(|file| { .filter_map(|file| {
let config = utils::read_file(file.as_ref()?).ok()?; let config = utils::read_file(file.as_ref()?).ok()?;
let clouds = YamlLoader::load_from_str(config.as_str()).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() .as_str()
.map(ToOwned::to_owned) .map(ToOwned::to_owned)
}) })

View File

@ -376,10 +376,10 @@ Python 3.7.9 (7e6e2bb30ac5fbdbd443619cae28c51d5c162a02, Nov 24 2020, 10:03:59)
create_dir_all(dir.path().join("my_venv"))?; create_dir_all(dir.path().join("my_venv"))?;
let mut venv_cfg = File::create(dir.path().join("my_venv").join("pyvenv.cfg"))?; let mut venv_cfg = File::create(dir.path().join("my_venv").join("pyvenv.cfg"))?;
venv_cfg.write_all( venv_cfg.write_all(
br#" br"
home = something home = something
prompt = 'foo' prompt = 'foo'
"#, ",
)?; )?;
venv_cfg.sync_all()?; venv_cfg.sync_all()?;
@ -403,10 +403,10 @@ prompt = 'foo'
create_dir_all(dir.path().join("my_venv"))?; create_dir_all(dir.path().join("my_venv"))?;
let mut venv_cfg = File::create(dir.path().join("my_venv").join("pyvenv.cfg"))?; let mut venv_cfg = File::create(dir.path().join("my_venv").join("pyvenv.cfg"))?;
venv_cfg.write_all( venv_cfg.write_all(
br#" br"
home = something home = something
prompt = '(foo)' prompt = '(foo)'
"#, ",
)?; )?;
venv_cfg.sync_all()?; venv_cfg.sync_all()?;

View File

@ -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 binary: rustc
commit-hash: 73528e339aae0f17a15ffa49a8ac608f50c6cf14 commit-hash: 73528e339aae0f17a15ffa49a8ac608f50c6cf14
commit-date: 2019-12-16 commit-date: 2019-12-16
host: x86_64-unknown-linux-gnu host: x86_64-unknown-linux-gnu
release: 1.40.0 release: 1.40.0
LLVM version: 9.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 binary: rustc
commit-hash: eb3f7c2d3aec576f47eba854cfbd3c1187b8a2a0 commit-hash: eb3f7c2d3aec576f47eba854cfbd3c1187b8a2a0
commit-date: 2019-12-17 commit-date: 2019-12-17
host: x86_64-unknown-linux-gnu host: x86_64-unknown-linux-gnu
release: 1.41.0-beta.1 release: 1.41.0-beta.1
LLVM version: 9.0 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 binary: rustc
commit-hash: da3629b05f8f1b425a738bfe9fe9aedd47c5417a commit-hash: da3629b05f8f1b425a738bfe9fe9aedd47c5417a
commit-date: 2019-12-29 commit-date: 2019-12-29
host: x86_64-unknown-linux-gnu host: x86_64-unknown-linux-gnu
release: 1.42.0-nightly release: 1.42.0-nightly
LLVM version: 9.0 LLVM version: 9.0
"#; ";
test!( test!(
(STABLE, None) => Some(("v1.40.0", "x86_64-unknown-linux-gnu")), (STABLE, None) => Some(("v1.40.0", "x86_64-unknown-linux-gnu")),

View File

@ -242,7 +242,7 @@ mod tests {
disabled = false disabled = false
threshold = threshold threshold = threshold
}) })
.env(SHLVL_ENV_VAR, format!("{}", shlvl)) .env(SHLVL_ENV_VAR, format!("{shlvl}"))
.collect() .collect()
} }

View File

@ -391,7 +391,7 @@ pub fn format_duration(duration: &Duration) -> String {
/// Return the modules from $all that are not already in the list /// Return the modules from $all that are not already in the list
fn all_modules_uniq(module_list: &BTreeSet<String>) -> Vec<String> { fn all_modules_uniq(module_list: &BTreeSet<String>) -> Vec<String> {
let mut prompt_order: Vec<String> = Vec::new(); let mut prompt_order: Vec<String> = Vec::new();
for module in PROMPT_ORDER.iter() { for module in PROMPT_ORDER {
if !module_list.contains(*module) { if !module_list.contains(*module) {
prompt_order.push(String::from(*module)) prompt_order.push(String::from(*module))
} }
@ -452,7 +452,7 @@ fn load_formatter_and_modules<'a>(context: &'a Context) -> (StringFormatter<'a>,
let modules = [&lf, &rf] let modules = [&lf, &rf]
.into_iter() .into_iter()
.flatten() .flatten()
.flat_map(|f| f.get_variables()) .flat_map(VariableHolder::get_variables)
.collect(); .collect();
let main_formatter = match context.target { let main_formatter = match context.target {

View File

@ -71,7 +71,7 @@ pub fn write_file<P: AsRef<Path>, S: AsRef<str>>(file_name: P, text: S) -> Resul
}; };
match file.write_all(text.as_bytes()) { match file.write_all(text.as_bytes()) {
Ok(_) => { Ok(()) => {
log::trace!("File {file_name:?} written successfully"); log::trace!("File {file_name:?} written successfully");
} }
Err(err) => { Err(err) => {