Fix a bunch of future clippy warnings (#3586)

* Fix a bunch of future clippy warnings

* Fix a bunch of future clippy warnings
This commit is contained in:
JT
2021-06-10 07:08:12 +12:00
committed by GitHub
parent e8a2250ef8
commit 383e874166
86 changed files with 237 additions and 258 deletions

View File

@ -26,7 +26,7 @@ pub fn evaluate_baseline_expr(
};
let span = expr.span;
match &expr.expr {
Expression::Literal(literal) => Ok(evaluate_literal(&literal, span)),
Expression::Literal(literal) => Ok(evaluate_literal(literal, span)),
Expression::ExternalWord => Err(ShellError::argument_error(
"Invalid external word".spanned(tag.span),
ArgumentError::InvalidExternalWord,
@ -35,7 +35,7 @@ pub fn evaluate_baseline_expr(
Expression::Synthetic(hir::Synthetic::String(s)) => {
Ok(UntaggedValue::string(s).into_untagged_value())
}
Expression::Variable(var, s) => evaluate_reference(&var, ctx, *s),
Expression::Variable(var, s) => evaluate_reference(var, ctx, *s),
Expression::Command => unimplemented!(),
Expression::Subexpression(block) => evaluate_subexpression(block, ctx),
Expression::ExternalCommand(_) => unimplemented!(),
@ -68,13 +68,13 @@ pub fn evaluate_baseline_expr(
}
Expression::Range(range) => {
let left = if let Some(left) = &range.left {
evaluate_baseline_expr(&left, ctx)?
evaluate_baseline_expr(left, ctx)?
} else {
Value::nothing()
};
let right = if let Some(right) = &range.right {
evaluate_baseline_expr(&right, ctx)?
evaluate_baseline_expr(right, ctx)?
} else {
Value::nothing()
};
@ -100,7 +100,7 @@ pub fn evaluate_baseline_expr(
let mut output_headers = vec![];
for expr in headers {
let val = evaluate_baseline_expr(&expr, ctx)?;
let val = evaluate_baseline_expr(expr, ctx)?;
let header = val.as_string()?;
output_headers.push(header);
@ -128,7 +128,7 @@ pub fn evaluate_baseline_expr(
let mut row_output = IndexMap::new();
for cell in output_headers.iter().zip(row.iter()) {
let val = evaluate_baseline_expr(&cell.1, ctx)?;
let val = evaluate_baseline_expr(cell.1, ctx)?;
row_output.insert(cell.0.clone(), val);
}
output_table.push(UntaggedValue::row(row_output).into_value(tag.clone()));
@ -140,7 +140,7 @@ pub fn evaluate_baseline_expr(
let mut exprs = vec![];
for expr in list {
let expr = evaluate_baseline_expr(&expr, ctx)?;
let expr = evaluate_baseline_expr(expr, ctx)?;
exprs.push(expr);
}
@ -228,7 +228,7 @@ fn evaluate_literal(literal: &hir::Literal, span: Span) -> Value {
UntaggedValue::decimal(d.clone()).into_value(span)
}
},
hir::Literal::Size(int, unit) => unit.compute(&int).into_value(span),
hir::Literal::Size(int, unit) => unit.compute(int).into_value(span),
hir::Literal::String(string) => UntaggedValue::string(string).into_value(span),
hir::Literal::GlobPattern(pattern) => UntaggedValue::glob_pattern(pattern).into_value(span),
hir::Literal::Bare(bare) => UntaggedValue::string(bare.clone()).into_value(span),
@ -287,7 +287,7 @@ fn evaluate_subexpression(
None => InputStream::empty(),
};
let result = run_block(&block, ctx, input, hir::ExternalRedirection::Stdout)?;
let result = run_block(block, ctx, input, hir::ExternalRedirection::Stdout)?;
let output = result.into_vec();

View File

@ -84,7 +84,7 @@ fn table_contains(
UntaggedValue::Table(values) => {
Ok(values
.iter()
.any(|x| match compare_values(Operator::Equal, &left, &x.value) {
.any(|x| match compare_values(Operator::Equal, left, &x.value) {
Ok(coerced) => coerced,
_ => false,
}))

View File

@ -292,7 +292,7 @@ impl EvaluationContext {
}
//Unload config
self.configs.lock().remove_cfg(&cfg_path);
self.configs.lock().remove_cfg(cfg_path);
self.scope.exit_scope_with_tag(&tag);
}
@ -301,7 +301,7 @@ impl EvaluationContext {
pub fn run_scripts(&self, scripts: Vec<String>, dir: Option<&Path>) {
if let Some(dir) = dir {
for script in scripts {
match script::run_script_in_dir(script.clone(), dir, &self) {
match script::run_script_in_dir(script.clone(), dir, self) {
Ok(_) => {}
Err(e) => {
let err = ShellError::untagged_runtime_error(format!(

View File

@ -105,9 +105,9 @@ impl DirInfo {
match f {
Ok(i) => match i.file_type() {
Ok(t) if t.is_dir() => {
s = s.add_dir(i.path(), depth, &params, ctrl_c.clone())
s = s.add_dir(i.path(), depth, params, ctrl_c.clone())
}
Ok(_t) => s = s.add_file(i.path(), &params),
Ok(_t) => s = s.add_file(i.path(), params),
Err(e) => s = s.add_error(e.into()),
},
Err(e) => s = s.add_error(e.into()),
@ -134,7 +134,7 @@ impl DirInfo {
}
}
let d = DirInfo::new(path, &params, depth, ctrl_c);
let d = DirInfo::new(path, params, depth, ctrl_c);
self.size += d.size;
self.blocks += d.blocks;
self.dirs.push(d);

View File

@ -931,7 +931,7 @@ fn move_file(from: TaggedPathBuf, to: TaggedPathBuf) -> Result<(), ShellError> {
to.push(from_file_name);
}
move_item(&from, from_tag, &to)
move_item(from, from_tag, &to)
}
fn move_item(from: &Path, from_tag: &Tag, to: &Path) -> Result<(), ShellError> {

View File

@ -185,7 +185,7 @@ mod tests {
let mut res = FileStructure::new();
res.walk_decorate(&dirs.test())
res.walk_decorate(dirs.test())
.expect("Can not decorate files traversal.");
assert_eq!(

View File

@ -40,7 +40,7 @@ impl<R: Read> Iterator for BufCodecReader<R> {
let buffer = self.input.fill_buf();
match buffer {
Ok(s) => {
let result = self.maybe_text_codec.decode(&s).transpose();
let result = self.maybe_text_codec.decode(s).transpose();
let buffer_len = s.len();
self.input.consume(buffer_len);

View File

@ -158,7 +158,7 @@ pub fn scan(
if is_valid_name && is_executable {
trace!(target: "nu::load", "plugin infrastructure -> Trying {:?}", path.display());
build_plugin_command(&path).unwrap_or(None)
build_plugin_command(path).unwrap_or(None)
} else {
None
}

View File

@ -416,7 +416,7 @@ fn run_sink(path: String, args: CommandArgs) -> Result<ActionStream, ShellError>
"Bypass",
"-File",
&real_path.to_string_lossy(),
&tmpfile
tmpfile
.path()
.to_str()
.expect("Failed getting tmpfile path"),

View File

@ -65,7 +65,7 @@ pub fn process_script(
} else {
let line = chomp_newline(script_text);
let (block, err) = nu_parser::parse(&line, span_offset, &ctx.scope);
let (block, err) = nu_parser::parse(line, span_offset, &ctx.scope);
debug!("{:#?}", block);
//println!("{:#?}", pipeline);
@ -111,7 +111,7 @@ pub fn process_script(
&& args
.positional
.as_ref()
.map(|ref v| v.len() == 1)
.map(|v| v.len() == 1)
.unwrap_or(true)
&& args
.named
@ -120,7 +120,7 @@ pub fn process_script(
.unwrap_or(true)
&& canonicalize(ctx.shell_manager.path(), name).is_ok()
&& Path::new(&name).is_dir()
&& !ctx.host.lock().is_external_cmd(&name)
&& !ctx.host.lock().is_external_cmd(name)
{
let tag = Tag {
anchor: Some(AnchorLocation::Source(line.into())),
@ -285,7 +285,7 @@ pub fn run_script_standalone(
}
};
maybe_print_errors(&context, Text::from(line));
maybe_print_errors(context, Text::from(line));
if error_code != 0 && exit_on_error {
std::process::exit(error_code);
}
@ -297,7 +297,7 @@ pub fn run_script_standalone(
.lock()
.print_err(err, &Text::from(line.clone()));
maybe_print_errors(&context, Text::from(line));
maybe_print_errors(context, Text::from(line));
if exit_on_error {
std::process::exit(1);
}

View File

@ -72,10 +72,8 @@ impl Painter {
current_style = self.styles[idx_end];
idx_start = idx_end;
idx_end += 1;
} else {
idx_end += 1;
}
idx_end += 1;
}
let intermediate = String::from_utf8_lossy(&self.original[idx_start..idx_end]);