Clippy fixes for new Rust version (#3392)

This commit is contained in:
JT
2021-05-07 07:58:21 +12:00
committed by GitHub
parent 0f8e31af06
commit 91a929b2a9
19 changed files with 109 additions and 158 deletions

View File

@ -114,10 +114,7 @@ impl Host for FakeHost {
fn env_get(&mut self, key: OsString) -> Option<OsString> {
let key = key.into_string().expect("Couldn't convert to string.");
match self.env_vars.get(&key) {
Some(env) => Some(OsString::from(env)),
None => None,
}
self.env_vars.get(&key).map(OsString::from)
}
fn env_set(&mut self, key: OsString, value: OsString) {

View File

@ -178,10 +178,8 @@ impl EvaluationContext {
Some(env_paths)
} else if let Some(env_paths) = self.scope.get_env("Path") {
Some(env_paths)
} else if let Some(env_paths) = self.scope.get_env("path") {
Some(env_paths)
} else {
None
self.scope.get_env("path")
};
if let Some(env_paths) = env_paths {
@ -249,10 +247,8 @@ impl EvaluationContext {
Some(env_paths)
} else if let Some(env_paths) = self.scope.get_env("Path") {
Some(env_paths)
} else if let Some(env_paths) = self.scope.get_env("path") {
Some(env_paths)
} else {
None
self.scope.get_env("path")
};
if let Some(env_paths) = env_paths {

View File

@ -386,82 +386,80 @@ impl Shell for FilesystemShell {
));
}
for entry in sources {
if let Ok(entry) = entry {
let mut sources = FileStructure::new();
sources.walk_decorate(&entry)?;
for entry in sources.into_iter().flatten() {
let mut sources = FileStructure::new();
sources.walk_decorate(&entry)?;
if entry.is_file() {
let sources = sources.paths_applying_with(|(source_file, _depth_level)| {
if destination.is_dir() {
let mut dest = canonicalize(&path, &dst.item)?;
if let Some(name) = entry.file_name() {
dest.push(name);
}
Ok((source_file, dest))
} else {
Ok((source_file, destination.clone()))
if entry.is_file() {
let sources = sources.paths_applying_with(|(source_file, _depth_level)| {
if destination.is_dir() {
let mut dest = canonicalize(&path, &dst.item)?;
if let Some(name) = entry.file_name() {
dest.push(name);
}
})?;
Ok((source_file, dest))
} else {
Ok((source_file, destination.clone()))
}
})?;
for (src, dst) in sources {
if src.is_file() {
std::fs::copy(src, dst).map_err(|e| {
ShellError::labeled_error(e.to_string(), e.to_string(), &name_tag)
})?;
for (src, dst) in sources {
if src.is_file() {
std::fs::copy(src, dst).map_err(|e| {
ShellError::labeled_error(e.to_string(), e.to_string(), &name_tag)
})?;
}
}
} else if entry.is_dir() {
let destination = if !destination.exists() {
destination.clone()
} else {
match entry.file_name() {
Some(name) => destination.join(name),
None => {
return Err(ShellError::labeled_error(
"Copy aborted. Not a valid path",
"not a valid path",
dst.tag,
))
}
}
} else if entry.is_dir() {
let destination = if !destination.exists() {
destination.clone()
} else {
match entry.file_name() {
Some(name) => destination.join(name),
None => {
return Err(ShellError::labeled_error(
"Copy aborted. Not a valid path",
"not a valid path",
dst.tag,
))
}
}
};
};
std::fs::create_dir_all(&destination).map_err(|e| {
ShellError::labeled_error(e.to_string(), e.to_string(), &dst.tag)
})?;
std::fs::create_dir_all(&destination).map_err(|e| {
ShellError::labeled_error(e.to_string(), e.to_string(), &dst.tag)
})?;
let sources = sources.paths_applying_with(|(source_file, depth_level)| {
let mut dest = destination.clone();
let path = canonicalize(&path, &source_file)?;
let sources = sources.paths_applying_with(|(source_file, depth_level)| {
let mut dest = destination.clone();
let path = canonicalize(&path, &source_file)?;
let comps: Vec<_> = path
.components()
.map(|fragment| fragment.as_os_str())
.rev()
.take(1 + depth_level)
.collect();
let comps: Vec<_> = path
.components()
.map(|fragment| fragment.as_os_str())
.rev()
.take(1 + depth_level)
.collect();
for fragment in comps.into_iter().rev() {
dest.push(fragment);
}
for fragment in comps.into_iter().rev() {
dest.push(fragment);
}
Ok((PathBuf::from(&source_file), dest))
})?;
Ok((PathBuf::from(&source_file), dest))
})?;
let dst_tag = &dst.tag;
for (src, dst) in sources {
if src.is_dir() && !dst.exists() {
std::fs::create_dir_all(&dst).map_err(|e| {
ShellError::labeled_error(e.to_string(), e.to_string(), dst_tag)
})?;
}
let dst_tag = &dst.tag;
for (src, dst) in sources {
if src.is_dir() && !dst.exists() {
std::fs::create_dir_all(&dst).map_err(|e| {
ShellError::labeled_error(e.to_string(), e.to_string(), dst_tag)
})?;
}
if src.is_file() {
std::fs::copy(&src, &dst).map_err(|e| {
ShellError::labeled_error(e.to_string(), e.to_string(), &name_tag)
})?;
}
if src.is_file() {
std::fs::copy(&src, &dst).map_err(|e| {
ShellError::labeled_error(e.to_string(), e.to_string(), &name_tag)
})?;
}
}
}
@ -574,13 +572,11 @@ impl Shell for FilesystemShell {
.collect();
}
for entry in sources {
if let Ok(entry) = entry {
move_file(
TaggedPathBuf(&entry, &src.tag),
TaggedPathBuf(&destination, &dst.tag),
)?
}
for entry in sources.into_iter().flatten() {
move_file(
TaggedPathBuf(&entry, &src.tag),
TaggedPathBuf(&destination, &dst.tag),
)?
}
Ok(ActionStream::empty())

View File

@ -27,8 +27,8 @@ pub struct BufCodecReader<R: Read> {
impl<R: Read> BufCodecReader<R> {
pub fn new(input: BufReader<R>, maybe_text_codec: MaybeTextCodec) -> Self {
BufCodecReader {
input,
maybe_text_codec,
input,
}
}
}