mirror of
https://github.com/nushell/nushell.git
synced 2025-02-16 18:41:44 +01:00
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
This commit is contained in:
parent
0f688d7da7
commit
f26151e36d
@ -36,11 +36,7 @@ pub fn read_trusted() -> Result<Trusted, ShellError> {
|
|||||||
.create(true)
|
.create(true)
|
||||||
.write(true)
|
.write(true)
|
||||||
.open(config_path)
|
.open(config_path)
|
||||||
.or_else(|_| {
|
.map_err(|_| ShellError::untagged_runtime_error("Couldn't open nu-env.toml"))?;
|
||||||
Err(ShellError::untagged_runtime_error(
|
|
||||||
"Couldn't open nu-env.toml",
|
|
||||||
))
|
|
||||||
})?;
|
|
||||||
let mut doc = String::new();
|
let mut doc = String::new();
|
||||||
file.read_to_string(&mut doc)?;
|
file.read_to_string(&mut doc)?;
|
||||||
|
|
||||||
|
@ -54,10 +54,8 @@ impl WholeStreamCommand for AutoenvTrust {
|
|||||||
.insert(filename, Sha256::digest(&content).as_slice().to_vec());
|
.insert(filename, Sha256::digest(&content).as_slice().to_vec());
|
||||||
|
|
||||||
let config_path = config::default_path_for(&Some(PathBuf::from("nu-env.toml")))?;
|
let config_path = config::default_path_for(&Some(PathBuf::from("nu-env.toml")))?;
|
||||||
let tomlstr = toml::to_string(&allowed).or_else(|_| {
|
let tomlstr = toml::to_string(&allowed).map_err(|_| {
|
||||||
Err(ShellError::untagged_runtime_error(
|
ShellError::untagged_runtime_error("Couldn't serialize allowed dirs to nu-env.toml")
|
||||||
"Couldn't serialize allowed dirs to nu-env.toml",
|
|
||||||
))
|
|
||||||
})?;
|
})?;
|
||||||
fs::write(config_path, tomlstr).expect("Couldn't write to toml file");
|
fs::write(config_path, tomlstr).expect("Couldn't write to toml file");
|
||||||
|
|
||||||
|
@ -78,10 +78,8 @@ impl WholeStreamCommand for AutoenvUnTrust {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let tomlstr = toml::to_string(&allowed).or_else(|_| {
|
let tomlstr = toml::to_string(&allowed).map_err(|_| {
|
||||||
Err(ShellError::untagged_runtime_error(
|
ShellError::untagged_runtime_error("Couldn't serialize allowed dirs to nu-env.toml")
|
||||||
"Couldn't serialize allowed dirs to nu-env.toml",
|
|
||||||
))
|
|
||||||
})?;
|
})?;
|
||||||
fs::write(config_path, tomlstr).expect("Couldn't write to toml file");
|
fs::write(config_path, tomlstr).expect("Couldn't write to toml file");
|
||||||
|
|
||||||
|
@ -141,15 +141,8 @@ fn action(input: &Value, options: &Substring, tag: impl Into<Tag>) -> Result<Val
|
|||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let start: isize = options.0.try_into().map_err(|_| {
|
let start: isize = options.0;
|
||||||
ShellError::labeled_error(
|
let end: isize = options.1;
|
||||||
"could not perform substring",
|
|
||||||
"could not perform substring",
|
|
||||||
tag.span,
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let end = options.1;
|
|
||||||
|
|
||||||
if start < len && end >= 0 {
|
if start < len && end >= 0 {
|
||||||
match start.cmp(&end) {
|
match start.cmp(&end) {
|
||||||
|
@ -55,7 +55,7 @@ impl DirectorySpecificEnvironment {
|
|||||||
|
|
||||||
if autoenv::file_is_trusted(&nu_env_file, &content)? {
|
if autoenv::file_is_trusted(&nu_env_file, &content)? {
|
||||||
let mut doc: NuEnvDoc = toml::de::from_slice(&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() {
|
if let Some(scripts) = doc.scripts.as_ref() {
|
||||||
for (k, v) in scripts {
|
for (k, v) in scripts {
|
||||||
@ -244,11 +244,11 @@ fn value_from_script(cmd: &str) -> Result<String, ShellError> {
|
|||||||
cmd
|
cmd
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
let response = std::str::from_utf8(&command.stdout[..command.stdout.len()]).or_else(|e| {
|
let response = std::str::from_utf8(&command.stdout[..command.stdout.len()]).map_err(|e| {
|
||||||
Err(ShellError::untagged_runtime_error(format!(
|
ShellError::untagged_runtime_error(format!(
|
||||||
"Couldn't parse stdout from command {:?}: {:?}",
|
"Couldn't parse stdout from command {:?}: {:?}",
|
||||||
command, e
|
command, e
|
||||||
)))
|
))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(response.trim().to_string())
|
Ok(response.trim().to_string())
|
||||||
|
@ -233,9 +233,9 @@ impl Signature {
|
|||||||
desc: impl Into<String>,
|
desc: impl Into<String>,
|
||||||
short: Option<char>,
|
short: Option<char>,
|
||||||
) -> Signature {
|
) -> Signature {
|
||||||
let s = short.and_then(|c| {
|
let s = short.map(|c| {
|
||||||
debug_assert!(!self.get_shorts().contains(&c));
|
debug_assert!(!self.get_shorts().contains(&c));
|
||||||
Some(c)
|
c
|
||||||
});
|
});
|
||||||
self.named.insert(
|
self.named.insert(
|
||||||
name.into(),
|
name.into(),
|
||||||
@ -253,9 +253,9 @@ impl Signature {
|
|||||||
desc: impl Into<String>,
|
desc: impl Into<String>,
|
||||||
short: Option<char>,
|
short: Option<char>,
|
||||||
) -> Signature {
|
) -> Signature {
|
||||||
let s = short.and_then(|c| {
|
let s = short.map(|c| {
|
||||||
debug_assert!(!self.get_shorts().contains(&c));
|
debug_assert!(!self.get_shorts().contains(&c));
|
||||||
Some(c)
|
c
|
||||||
});
|
});
|
||||||
|
|
||||||
self.named.insert(
|
self.named.insert(
|
||||||
@ -273,12 +273,12 @@ impl Signature {
|
|||||||
desc: impl Into<String>,
|
desc: impl Into<String>,
|
||||||
short: Option<char>,
|
short: Option<char>,
|
||||||
) -> Signature {
|
) -> Signature {
|
||||||
let s = short.and_then(|c| {
|
let s = short.map(|c| {
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
!self.get_shorts().contains(&c),
|
!self.get_shorts().contains(&c),
|
||||||
"There may be duplicate short flags, such as -h"
|
"There may be duplicate short flags, such as -h"
|
||||||
);
|
);
|
||||||
Some(c)
|
c
|
||||||
});
|
});
|
||||||
|
|
||||||
self.named
|
self.named
|
||||||
|
Loading…
Reference in New Issue
Block a user