mirror of
https://github.com/nushell/nushell.git
synced 2024-12-23 07:30:13 +01:00
Clippy fixes for new Rust version (#3392)
This commit is contained in:
parent
0f8e31af06
commit
91a929b2a9
@ -377,10 +377,7 @@ impl VarSyntaxShapeDeductor {
|
||||
.iter()
|
||||
.map(|decl| {
|
||||
let usage: VarUsage = decl.into();
|
||||
let deduction = match deducer.inferences.get(&usage) {
|
||||
Some(vec) => Some(vec.clone()),
|
||||
None => None,
|
||||
};
|
||||
let deduction = deducer.inferences.get(&usage).cloned();
|
||||
(decl.clone(), deduction)
|
||||
})
|
||||
.collect())
|
||||
@ -1023,7 +1020,7 @@ impl VarSyntaxShapeDeductor {
|
||||
Some(combination)
|
||||
}
|
||||
})
|
||||
.filter_map(|elem| elem)
|
||||
.flatten()
|
||||
.collect()
|
||||
}
|
||||
//No any's intersection of both is result
|
||||
@ -1044,7 +1041,7 @@ impl VarSyntaxShapeDeductor {
|
||||
Some(combination)
|
||||
}
|
||||
})
|
||||
.filter_map(|elem| elem)
|
||||
.flatten()
|
||||
.collect();
|
||||
if intersection.is_empty() {
|
||||
//TODO pass all labels somehow
|
||||
|
@ -87,7 +87,7 @@ impl WholeStreamCommand for EachWindow {
|
||||
None
|
||||
}
|
||||
})
|
||||
.filter_map(|x| x)
|
||||
.flatten()
|
||||
.flatten()
|
||||
.to_action_stream())
|
||||
}
|
||||
|
@ -228,8 +228,8 @@ pub fn get_column_from_row_error(
|
||||
} => {
|
||||
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()) {
|
||||
Some(ShellError::labeled_error_with_secondary(
|
||||
did_you_mean(&obj_source, column_path_tried.as_string()).map(|suggestions| {
|
||||
ShellError::labeled_error_with_secondary(
|
||||
"Unknown column",
|
||||
primary_label,
|
||||
column_path_tried.span,
|
||||
@ -239,10 +239,8 @@ pub fn get_column_from_row_error(
|
||||
&obj_source.data_descriptors().join(", ")
|
||||
),
|
||||
column_path_tried.span.since(path_members_span),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
PathMember {
|
||||
unspanned: UnspannedPathMember::Int(idx),
|
||||
|
@ -76,10 +76,10 @@ pub fn histogram(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
};
|
||||
|
||||
let column_grouper = if !columns.is_empty() {
|
||||
match columns.remove(0).split_last() {
|
||||
Some((key, _)) => Some(key.as_string().tagged(&name)),
|
||||
None => None,
|
||||
}
|
||||
columns
|
||||
.remove(0)
|
||||
.split_last()
|
||||
.map(|(key, _)| key.as_string().tagged(&name))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
@ -272,10 +272,7 @@ fn move_after(table: &Value, columns: &[String], from: &ColumnPath) -> Result<Va
|
||||
|
||||
Ok(select_fields(
|
||||
table,
|
||||
&reordered_columns
|
||||
.into_iter()
|
||||
.filter_map(|v| v)
|
||||
.collect::<Vec<_>>(),
|
||||
&reordered_columns.into_iter().flatten().collect::<Vec<_>>(),
|
||||
&table.tag,
|
||||
))
|
||||
}
|
||||
@ -321,10 +318,7 @@ fn move_before(table: &Value, columns: &[String], from: &ColumnPath) -> Result<V
|
||||
|
||||
Ok(select_fields(
|
||||
table,
|
||||
&reordered_columns
|
||||
.into_iter()
|
||||
.filter_map(|v| v)
|
||||
.collect::<Vec<_>>(),
|
||||
&reordered_columns.into_iter().flatten().collect::<Vec<_>>(),
|
||||
&table.tag,
|
||||
))
|
||||
}
|
||||
|
@ -95,10 +95,10 @@ fn where_command(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
};
|
||||
|
||||
Ok(WhereIterator {
|
||||
block,
|
||||
condition,
|
||||
context,
|
||||
input,
|
||||
block,
|
||||
}
|
||||
.to_output_stream())
|
||||
}
|
||||
|
@ -68,18 +68,16 @@ pub fn chop() {
|
||||
let stdin = io::stdin();
|
||||
let mut stdout = io::stdout();
|
||||
|
||||
for line in stdin.lock().lines() {
|
||||
if let Ok(given) = line {
|
||||
let chopped = if given.is_empty() {
|
||||
&given
|
||||
} else {
|
||||
let to = given.len() - 1;
|
||||
&given[..to]
|
||||
};
|
||||
for given in stdin.lock().lines().flatten() {
|
||||
let chopped = if given.is_empty() {
|
||||
&given
|
||||
} else {
|
||||
let to = given.len() - 1;
|
||||
&given[..to]
|
||||
};
|
||||
|
||||
if let Err(_e) = writeln!(stdout, "{}", chopped) {
|
||||
break;
|
||||
}
|
||||
if let Err(_e) = writeln!(stdout, "{}", chopped) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,8 +59,8 @@ impl NuConfig {
|
||||
};
|
||||
|
||||
Ok(NuConfig {
|
||||
file_path,
|
||||
vars,
|
||||
file_path,
|
||||
modified_at,
|
||||
})
|
||||
}
|
||||
|
@ -16,19 +16,11 @@ pub struct Labels {
|
||||
|
||||
impl Labels {
|
||||
pub fn at(&self, idx: usize) -> Option<&str> {
|
||||
if let Some(k) = self.x.get(idx) {
|
||||
Some(&k[..])
|
||||
} else {
|
||||
None
|
||||
}
|
||||
self.x.get(idx).map(|k| &k[..])
|
||||
}
|
||||
|
||||
pub fn at_split(&self, idx: usize) -> Option<&str> {
|
||||
if let Some(k) = self.y.get(idx) {
|
||||
Some(&k[..])
|
||||
} else {
|
||||
None
|
||||
}
|
||||
self.y.get(idx).map(|k| &k[..])
|
||||
}
|
||||
|
||||
pub fn grouped(&self) -> impl Iterator<Item = &String> {
|
||||
|
5
crates/nu-engine/src/env/host.rs
vendored
5
crates/nu-engine/src/env/host.rs
vendored
@ -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) {
|
||||
|
@ -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 {
|
||||
|
@ -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())
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -937,7 +937,7 @@ impl<'de> de::Deserializer<'de> for Value {
|
||||
}
|
||||
};
|
||||
|
||||
visitor.visit_enum(EnumDeserializer { value, variant })
|
||||
visitor.visit_enum(EnumDeserializer { variant, value })
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -62,10 +62,9 @@ impl<'a, T: Plugin> PluginTest<'a, T> {
|
||||
self.configure(|flags_configured| {
|
||||
let flags_registered = &call_stub.args.named;
|
||||
|
||||
let flag_passed = match flags_registered {
|
||||
Some(names) => Some(names.keys().map(String::from).collect::<Vec<String>>()),
|
||||
None => None,
|
||||
};
|
||||
let flag_passed = flags_registered
|
||||
.as_ref()
|
||||
.map(|names| names.keys().map(String::from).collect::<Vec<String>>());
|
||||
|
||||
if let Some(flags) = flag_passed {
|
||||
for flag in flags {
|
||||
|
@ -181,14 +181,10 @@ impl Dictionary {
|
||||
|
||||
/// Get a mutable entry that matches a key, if possible
|
||||
pub fn get_mut_data_by_key(&mut self, name: &str) -> Option<&mut Value> {
|
||||
match self
|
||||
.entries
|
||||
self.entries
|
||||
.iter_mut()
|
||||
.find(|(desc_name, _)| *desc_name == name)
|
||||
{
|
||||
Some((_, v)) => Some(v),
|
||||
None => None,
|
||||
}
|
||||
.map(|(_, v)| v)
|
||||
}
|
||||
|
||||
/// Insert a new key/value pair into the dictionary
|
||||
|
@ -794,10 +794,7 @@ where
|
||||
|
||||
impl<T> HasFallibleSpan for Option<Spanned<T>> {
|
||||
fn maybe_span(&self) -> Option<Span> {
|
||||
match self {
|
||||
None => None,
|
||||
Some(value) => Some(value.span),
|
||||
}
|
||||
self.as_ref().map(|value| value.span)
|
||||
}
|
||||
}
|
||||
|
||||
@ -815,10 +812,7 @@ where
|
||||
|
||||
impl<T> HasFallibleSpan for Option<Tagged<T>> {
|
||||
fn maybe_span(&self) -> Option<Span> {
|
||||
match self {
|
||||
None => None,
|
||||
Some(value) => Some(value.tag.span),
|
||||
}
|
||||
self.as_ref().map(|value| value.tag.span)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -213,15 +213,9 @@ pub fn view_contents(
|
||||
skip: Option<&Value>,
|
||||
length: Option<&Value>,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let skip_bytes = match skip {
|
||||
Some(s) => Some(s.as_usize().unwrap_or(0)),
|
||||
None => None,
|
||||
};
|
||||
let skip_bytes = skip.map(|s| s.as_usize().unwrap_or(0));
|
||||
|
||||
let num_bytes = match length {
|
||||
Some(b) => Some(b.as_usize().unwrap_or(0)),
|
||||
None => None,
|
||||
};
|
||||
let num_bytes = length.map(|b| b.as_usize().unwrap_or(0));
|
||||
|
||||
let config = HexConfig {
|
||||
title: true,
|
||||
|
@ -19,6 +19,6 @@ impl Plugin for Start {
|
||||
}
|
||||
fn begin_filter(&mut self, call_info: CallInfo) -> Result<Vec<ReturnValue>, ShellError> {
|
||||
self.parse(call_info)?;
|
||||
self.exec().map(|_| vec![])
|
||||
self.exec().map(|_| Vec::new())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user