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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 109 additions and 158 deletions

View File

@ -377,10 +377,7 @@ impl VarSyntaxShapeDeductor {
.iter() .iter()
.map(|decl| { .map(|decl| {
let usage: VarUsage = decl.into(); let usage: VarUsage = decl.into();
let deduction = match deducer.inferences.get(&usage) { let deduction = deducer.inferences.get(&usage).cloned();
Some(vec) => Some(vec.clone()),
None => None,
};
(decl.clone(), deduction) (decl.clone(), deduction)
}) })
.collect()) .collect())
@ -1023,7 +1020,7 @@ impl VarSyntaxShapeDeductor {
Some(combination) Some(combination)
} }
}) })
.filter_map(|elem| elem) .flatten()
.collect() .collect()
} }
//No any's intersection of both is result //No any's intersection of both is result
@ -1044,7 +1041,7 @@ impl VarSyntaxShapeDeductor {
Some(combination) Some(combination)
} }
}) })
.filter_map(|elem| elem) .flatten()
.collect(); .collect();
if intersection.is_empty() { if intersection.is_empty() {
//TODO pass all labels somehow //TODO pass all labels somehow

View File

@ -87,7 +87,7 @@ impl WholeStreamCommand for EachWindow {
None None
} }
}) })
.filter_map(|x| x) .flatten()
.flatten() .flatten()
.to_action_stream()) .to_action_stream())
} }

View File

@ -228,8 +228,8 @@ pub fn get_column_from_row_error(
} => { } => {
let primary_label = format!("There isn't a column named '{}'", &column); let primary_label = format!("There isn't a column named '{}'", &column);
if let Some(suggestions) = did_you_mean(&obj_source, column_path_tried.as_string()) { did_you_mean(&obj_source, column_path_tried.as_string()).map(|suggestions| {
Some(ShellError::labeled_error_with_secondary( ShellError::labeled_error_with_secondary(
"Unknown column", "Unknown column",
primary_label, primary_label,
column_path_tried.span, column_path_tried.span,
@ -239,10 +239,8 @@ pub fn get_column_from_row_error(
&obj_source.data_descriptors().join(", ") &obj_source.data_descriptors().join(", ")
), ),
column_path_tried.span.since(path_members_span), column_path_tried.span.since(path_members_span),
)) )
} else { })
None
}
} }
PathMember { PathMember {
unspanned: UnspannedPathMember::Int(idx), unspanned: UnspannedPathMember::Int(idx),

View File

@ -76,10 +76,10 @@ pub fn histogram(args: CommandArgs) -> Result<ActionStream, ShellError> {
}; };
let column_grouper = if !columns.is_empty() { let column_grouper = if !columns.is_empty() {
match columns.remove(0).split_last() { columns
Some((key, _)) => Some(key.as_string().tagged(&name)), .remove(0)
None => None, .split_last()
} .map(|(key, _)| key.as_string().tagged(&name))
} else { } else {
None None
}; };

View File

@ -272,10 +272,7 @@ fn move_after(table: &Value, columns: &[String], from: &ColumnPath) -> Result<Va
Ok(select_fields( Ok(select_fields(
table, table,
&reordered_columns &reordered_columns.into_iter().flatten().collect::<Vec<_>>(),
.into_iter()
.filter_map(|v| v)
.collect::<Vec<_>>(),
&table.tag, &table.tag,
)) ))
} }
@ -321,10 +318,7 @@ fn move_before(table: &Value, columns: &[String], from: &ColumnPath) -> Result<V
Ok(select_fields( Ok(select_fields(
table, table,
&reordered_columns &reordered_columns.into_iter().flatten().collect::<Vec<_>>(),
.into_iter()
.filter_map(|v| v)
.collect::<Vec<_>>(),
&table.tag, &table.tag,
)) ))
} }

View File

@ -95,10 +95,10 @@ fn where_command(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
}; };
Ok(WhereIterator { Ok(WhereIterator {
block,
condition, condition,
context, context,
input, input,
block,
} }
.to_output_stream()) .to_output_stream())
} }

View File

@ -68,8 +68,7 @@ pub fn chop() {
let stdin = io::stdin(); let stdin = io::stdin();
let mut stdout = io::stdout(); let mut stdout = io::stdout();
for line in stdin.lock().lines() { for given in stdin.lock().lines().flatten() {
if let Ok(given) = line {
let chopped = if given.is_empty() { let chopped = if given.is_empty() {
&given &given
} else { } else {
@ -81,7 +80,6 @@ pub fn chop() {
break; break;
} }
} }
}
std::process::exit(0); std::process::exit(0);
} }

View File

@ -59,8 +59,8 @@ impl NuConfig {
}; };
Ok(NuConfig { Ok(NuConfig {
file_path,
vars, vars,
file_path,
modified_at, modified_at,
}) })
} }

View File

@ -16,19 +16,11 @@ pub struct Labels {
impl Labels { impl Labels {
pub fn at(&self, idx: usize) -> Option<&str> { pub fn at(&self, idx: usize) -> Option<&str> {
if let Some(k) = self.x.get(idx) { self.x.get(idx).map(|k| &k[..])
Some(&k[..])
} else {
None
}
} }
pub fn at_split(&self, idx: usize) -> Option<&str> { pub fn at_split(&self, idx: usize) -> Option<&str> {
if let Some(k) = self.y.get(idx) { self.y.get(idx).map(|k| &k[..])
Some(&k[..])
} else {
None
}
} }
pub fn grouped(&self) -> impl Iterator<Item = &String> { pub fn grouped(&self) -> impl Iterator<Item = &String> {

View File

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

View File

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

View File

@ -386,8 +386,7 @@ impl Shell for FilesystemShell {
)); ));
} }
for entry in sources { for entry in sources.into_iter().flatten() {
if let Ok(entry) = entry {
let mut sources = FileStructure::new(); let mut sources = FileStructure::new();
sources.walk_decorate(&entry)?; sources.walk_decorate(&entry)?;
@ -465,7 +464,6 @@ impl Shell for FilesystemShell {
} }
} }
} }
}
Ok(ActionStream::empty()) Ok(ActionStream::empty())
} }
@ -574,14 +572,12 @@ impl Shell for FilesystemShell {
.collect(); .collect();
} }
for entry in sources { for entry in sources.into_iter().flatten() {
if let Ok(entry) = entry {
move_file( move_file(
TaggedPathBuf(&entry, &src.tag), TaggedPathBuf(&entry, &src.tag),
TaggedPathBuf(&destination, &dst.tag), TaggedPathBuf(&destination, &dst.tag),
)? )?
} }
}
Ok(ActionStream::empty()) Ok(ActionStream::empty())
} }

View File

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

View File

@ -937,7 +937,7 @@ impl<'de> de::Deserializer<'de> for Value {
} }
}; };
visitor.visit_enum(EnumDeserializer { value, variant }) visitor.visit_enum(EnumDeserializer { variant, value })
} }
#[inline] #[inline]

View File

@ -62,10 +62,9 @@ impl<'a, T: Plugin> PluginTest<'a, T> {
self.configure(|flags_configured| { self.configure(|flags_configured| {
let flags_registered = &call_stub.args.named; let flags_registered = &call_stub.args.named;
let flag_passed = match flags_registered { let flag_passed = flags_registered
Some(names) => Some(names.keys().map(String::from).collect::<Vec<String>>()), .as_ref()
None => None, .map(|names| names.keys().map(String::from).collect::<Vec<String>>());
};
if let Some(flags) = flag_passed { if let Some(flags) = flag_passed {
for flag in flags { for flag in flags {

View File

@ -181,14 +181,10 @@ impl Dictionary {
/// Get a mutable entry that matches a key, if possible /// Get a mutable entry that matches a key, if possible
pub fn get_mut_data_by_key(&mut self, name: &str) -> Option<&mut Value> { pub fn get_mut_data_by_key(&mut self, name: &str) -> Option<&mut Value> {
match self self.entries
.entries
.iter_mut() .iter_mut()
.find(|(desc_name, _)| *desc_name == name) .find(|(desc_name, _)| *desc_name == name)
{ .map(|(_, v)| v)
Some((_, v)) => Some(v),
None => None,
}
} }
/// Insert a new key/value pair into the dictionary /// Insert a new key/value pair into the dictionary

View File

@ -794,10 +794,7 @@ where
impl<T> HasFallibleSpan for Option<Spanned<T>> { impl<T> HasFallibleSpan for Option<Spanned<T>> {
fn maybe_span(&self) -> Option<Span> { fn maybe_span(&self) -> Option<Span> {
match self { self.as_ref().map(|value| value.span)
None => None,
Some(value) => Some(value.span),
}
} }
} }
@ -815,10 +812,7 @@ where
impl<T> HasFallibleSpan for Option<Tagged<T>> { impl<T> HasFallibleSpan for Option<Tagged<T>> {
fn maybe_span(&self) -> Option<Span> { fn maybe_span(&self) -> Option<Span> {
match self { self.as_ref().map(|value| value.tag.span)
None => None,
Some(value) => Some(value.tag.span),
}
} }
} }

View File

@ -213,15 +213,9 @@ pub fn view_contents(
skip: Option<&Value>, skip: Option<&Value>,
length: Option<&Value>, length: Option<&Value>,
) -> Result<(), Box<dyn std::error::Error>> { ) -> Result<(), Box<dyn std::error::Error>> {
let skip_bytes = match skip { let skip_bytes = skip.map(|s| s.as_usize().unwrap_or(0));
Some(s) => Some(s.as_usize().unwrap_or(0)),
None => None,
};
let num_bytes = match length { let num_bytes = length.map(|b| b.as_usize().unwrap_or(0));
Some(b) => Some(b.as_usize().unwrap_or(0)),
None => None,
};
let config = HexConfig { let config = HexConfig {
title: true, title: true,

View File

@ -19,6 +19,6 @@ impl Plugin for Start {
} }
fn begin_filter(&mut self, call_info: CallInfo) -> Result<Vec<ReturnValue>, ShellError> { fn begin_filter(&mut self, call_info: CallInfo) -> Result<Vec<ReturnValue>, ShellError> {
self.parse(call_info)?; self.parse(call_info)?;
self.exec().map(|_| vec![]) self.exec().map(|_| Vec::new())
} }
} }