mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 16:33:37 +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)
|
||||
.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)?;
|
||||
|
||||
|
@ -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");
|
||||
|
||||
|
@ -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");
|
||||
|
||||
|
@ -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(|_| {
|
||||
ShellError::labeled_error(
|
||||
"could not perform substring",
|
||||
"could not perform substring",
|
||||
tag.span,
|
||||
)
|
||||
})?;
|
||||
|
||||
let end = options.1;
|
||||
let start: isize = options.0;
|
||||
let end: isize = options.1;
|
||||
|
||||
if start < len && end >= 0 {
|
||||
match start.cmp(&end) {
|
||||
|
@ -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<String, ShellError> {
|
||||
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())
|
||||
|
@ -233,9 +233,9 @@ impl Signature {
|
||||
desc: impl Into<String>,
|
||||
short: Option<char>,
|
||||
) -> 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<String>,
|
||||
short: Option<char>,
|
||||
) -> 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<String>,
|
||||
short: Option<char>,
|
||||
) -> 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
|
||||
|
Loading…
Reference in New Issue
Block a user