From f26151e36d4f7b1d408e527358e51cbad176710a Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Fri, 17 Jul 2020 13:57:15 -0400 Subject: [PATCH] Silence Rust 1.45 Clippy warnings (#2196) * Silence Rust 1.45 Clippy warnings dealing with using `map_err()` * Silence false Clippy warning * Fix last Clippy error for unnecessary conversion * Fix `and_then` clippy warnings --- crates/nu-cli/src/commands/autoenv.rs | 6 +----- crates/nu-cli/src/commands/autoenv_trust.rs | 6 ++---- crates/nu-cli/src/commands/autoenv_untrust.rs | 6 ++---- crates/nu-cli/src/commands/str_/substring.rs | 11 ++--------- .../nu-cli/src/env/directory_specific_environment.rs | 8 ++++---- crates/nu-protocol/src/signature.rs | 12 ++++++------ 6 files changed, 17 insertions(+), 32 deletions(-) diff --git a/crates/nu-cli/src/commands/autoenv.rs b/crates/nu-cli/src/commands/autoenv.rs index a8777e65be..a3775772dd 100644 --- a/crates/nu-cli/src/commands/autoenv.rs +++ b/crates/nu-cli/src/commands/autoenv.rs @@ -36,11 +36,7 @@ pub fn read_trusted() -> Result { .create(true) .write(true) .open(config_path) - .or_else(|_| { - Err(ShellError::untagged_runtime_error( - "Couldn't open nu-env.toml", - )) - })?; + .map_err(|_| ShellError::untagged_runtime_error("Couldn't open nu-env.toml"))?; let mut doc = String::new(); file.read_to_string(&mut doc)?; diff --git a/crates/nu-cli/src/commands/autoenv_trust.rs b/crates/nu-cli/src/commands/autoenv_trust.rs index 82ef7510d8..1a47edb429 100644 --- a/crates/nu-cli/src/commands/autoenv_trust.rs +++ b/crates/nu-cli/src/commands/autoenv_trust.rs @@ -54,10 +54,8 @@ impl WholeStreamCommand for AutoenvTrust { .insert(filename, Sha256::digest(&content).as_slice().to_vec()); let config_path = config::default_path_for(&Some(PathBuf::from("nu-env.toml")))?; - let tomlstr = toml::to_string(&allowed).or_else(|_| { - Err(ShellError::untagged_runtime_error( - "Couldn't serialize allowed dirs to nu-env.toml", - )) + let tomlstr = toml::to_string(&allowed).map_err(|_| { + ShellError::untagged_runtime_error("Couldn't serialize allowed dirs to nu-env.toml") })?; fs::write(config_path, tomlstr).expect("Couldn't write to toml file"); diff --git a/crates/nu-cli/src/commands/autoenv_untrust.rs b/crates/nu-cli/src/commands/autoenv_untrust.rs index 512896893b..fa661de6f9 100644 --- a/crates/nu-cli/src/commands/autoenv_untrust.rs +++ b/crates/nu-cli/src/commands/autoenv_untrust.rs @@ -78,10 +78,8 @@ impl WholeStreamCommand for AutoenvUnTrust { )); } - let tomlstr = toml::to_string(&allowed).or_else(|_| { - Err(ShellError::untagged_runtime_error( - "Couldn't serialize allowed dirs to nu-env.toml", - )) + let tomlstr = toml::to_string(&allowed).map_err(|_| { + ShellError::untagged_runtime_error("Couldn't serialize allowed dirs to nu-env.toml") })?; fs::write(config_path, tomlstr).expect("Couldn't write to toml file"); diff --git a/crates/nu-cli/src/commands/str_/substring.rs b/crates/nu-cli/src/commands/str_/substring.rs index d41b7ece6a..3b2c2f24a0 100644 --- a/crates/nu-cli/src/commands/str_/substring.rs +++ b/crates/nu-cli/src/commands/str_/substring.rs @@ -141,15 +141,8 @@ fn action(input: &Value, options: &Substring, tag: impl Into) -> Result= 0 { match start.cmp(&end) { diff --git a/crates/nu-cli/src/env/directory_specific_environment.rs b/crates/nu-cli/src/env/directory_specific_environment.rs index 08ccd4396d..b6755216cf 100644 --- a/crates/nu-cli/src/env/directory_specific_environment.rs +++ b/crates/nu-cli/src/env/directory_specific_environment.rs @@ -55,7 +55,7 @@ impl DirectorySpecificEnvironment { if autoenv::file_is_trusted(&nu_env_file, &content)? { let mut doc: NuEnvDoc = toml::de::from_slice(&content) - .or_else(|e| Err(ShellError::untagged_runtime_error(format!("{:?}", e))))?; + .map_err(|e| ShellError::untagged_runtime_error(format!("{:?}", e)))?; if let Some(scripts) = doc.scripts.as_ref() { for (k, v) in scripts { @@ -244,11 +244,11 @@ fn value_from_script(cmd: &str) -> Result { cmd ))); } - let response = std::str::from_utf8(&command.stdout[..command.stdout.len()]).or_else(|e| { - Err(ShellError::untagged_runtime_error(format!( + let response = std::str::from_utf8(&command.stdout[..command.stdout.len()]).map_err(|e| { + ShellError::untagged_runtime_error(format!( "Couldn't parse stdout from command {:?}: {:?}", command, e - ))) + )) })?; Ok(response.trim().to_string()) diff --git a/crates/nu-protocol/src/signature.rs b/crates/nu-protocol/src/signature.rs index 12557c85a1..4144323b65 100644 --- a/crates/nu-protocol/src/signature.rs +++ b/crates/nu-protocol/src/signature.rs @@ -233,9 +233,9 @@ impl Signature { desc: impl Into, short: Option, ) -> Signature { - let s = short.and_then(|c| { + let s = short.map(|c| { debug_assert!(!self.get_shorts().contains(&c)); - Some(c) + c }); self.named.insert( name.into(), @@ -253,9 +253,9 @@ impl Signature { desc: impl Into, short: Option, ) -> Signature { - let s = short.and_then(|c| { + let s = short.map(|c| { debug_assert!(!self.get_shorts().contains(&c)); - Some(c) + c }); self.named.insert( @@ -273,12 +273,12 @@ impl Signature { desc: impl Into, short: Option, ) -> Signature { - let s = short.and_then(|c| { + let s = short.map(|c| { debug_assert!( !self.get_shorts().contains(&c), "There may be duplicate short flags, such as -h" ); - Some(c) + c }); self.named