Apply clippy fix (#7193)

# Description

rust 1.65.0 has been released for a while, this pr applies lint
suggestions from rust 1.65.0.

# User-Facing Changes

N/A

# Tests + Formatting

Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace --features=extra -- -D warnings -D
clippy::unwrap_used -A clippy::needless_collect` to check that you're
using the standard code style
- `cargo test --workspace --features=extra` to check that all tests pass

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
This commit is contained in:
nibon7 2022-11-23 11:57:27 +08:00 committed by GitHub
parent a0b3a48e8b
commit 0c38729735
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 24 deletions

View File

@ -4,8 +4,8 @@ use nu_engine::CallExt;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Config, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Spanned,
Spanned, SyntaxShape, Type, Value, SyntaxShape, Type, Value,
}; };
use std::iter; use std::iter;
use std::path::Path; use std::path::Path;
@ -83,14 +83,13 @@ fn operate(
input: PipelineData, input: PipelineData,
) -> Result<PipelineData, ShellError> { ) -> Result<PipelineData, ShellError> {
let span = call.head; let span = call.head;
let config = engine_state.get_config();
let file_name: Spanned<String> = call.req(engine_state, stack, 0)?; let file_name: Spanned<String> = call.req(engine_state, stack, 0)?;
let table_name: Option<Spanned<String>> = call.get_flag(engine_state, stack, "table_name")?; let table_name: Option<Spanned<String>> = call.get_flag(engine_state, stack, "table_name")?;
// collect the input into a value // collect the input into a value
let table_entries = input.into_value(span); let table_entries = input.into_value(span);
match action(&table_entries, table_name, file_name, config, span) { match action(&table_entries, table_name, file_name, span) {
Ok(val) => Ok(val.into_pipeline_data()), Ok(val) => Ok(val.into_pipeline_data()),
Err(e) => Err(e), Err(e) => Err(e),
} }
@ -100,7 +99,6 @@ fn action(
input: &Value, input: &Value,
table: Option<Spanned<String>>, table: Option<Spanned<String>>,
file: Spanned<String>, file: Spanned<String>,
config: &Config,
span: Span, span: Span,
) -> Result<Value, ShellError> { ) -> Result<Value, ShellError> {
let table_name = if let Some(table_name) = table { let table_name = if let Some(table_name) = table {
@ -133,10 +131,7 @@ fn action(
} => { } => {
vals.iter() vals.iter()
.map(|rec_val| { .map(|rec_val| {
format!( format!("'{}'", nu_value_to_string(rec_val.clone(), ""))
"'{}'",
nu_value_to_string(rec_val.clone(), "", config)
)
}) })
.join(",") .join(",")
} }
@ -145,10 +140,10 @@ fn action(
| Value::Float { val: _, span: _ } | Value::Float { val: _, span: _ }
| Value::Filesize { val: _, span: _ } | Value::Filesize { val: _, span: _ }
| Value::Duration { val: _, span: _ } => | Value::Duration { val: _, span: _ } =>
nu_value_to_string(list_value.clone(), "", config), nu_value_to_string(list_value.clone(), ""),
_ => _ =>
// String formats so add quotes around them // String formats so add quotes around them
format!("'{}'", nu_value_to_string(list_value.clone(), "", config)), format!("'{}'", nu_value_to_string(list_value.clone(), "")),
} }
) )
}) })
@ -231,7 +226,7 @@ fn action(
} }
// This is taken from to text local_into_string but tweaks it a bit so that certain formatting does not happen // This is taken from to text local_into_string but tweaks it a bit so that certain formatting does not happen
fn nu_value_to_string(value: Value, separator: &str, config: &Config) -> String { fn nu_value_to_string(value: Value, separator: &str) -> String {
match value { match value {
Value::Bool { val, .. } => val.to_string(), Value::Bool { val, .. } => val.to_string(),
Value::Int { val, .. } => val.to_string(), Value::Int { val, .. } => val.to_string(),
@ -242,8 +237,8 @@ fn nu_value_to_string(value: Value, separator: &str, config: &Config) -> String
Value::Range { val, .. } => { Value::Range { val, .. } => {
format!( format!(
"{}..{}", "{}..{}",
nu_value_to_string(val.from, ", ", config), nu_value_to_string(val.from, ", "),
nu_value_to_string(val.to, ", ", config) nu_value_to_string(val.to, ", ")
) )
} }
Value::String { val, .. } => { Value::String { val, .. } => {
@ -253,13 +248,13 @@ fn nu_value_to_string(value: Value, separator: &str, config: &Config) -> String
} }
Value::List { vals: val, .. } => val Value::List { vals: val, .. } => val
.iter() .iter()
.map(|x| nu_value_to_string(x.clone(), ", ", config)) .map(|x| nu_value_to_string(x.clone(), ", "))
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(separator), .join(separator),
Value::Record { cols, vals, .. } => cols Value::Record { cols, vals, .. } => cols
.iter() .iter()
.zip(vals.iter()) .zip(vals.iter())
.map(|(x, y)| format!("{}: {}", x, nu_value_to_string(y.clone(), ", ", config))) .map(|(x, y)| format!("{}: {}", x, nu_value_to_string(y.clone(), ", ")))
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(separator), .join(separator),
Value::Block { val, .. } => format!("<Block {}>", val), Value::Block { val, .. } => format!("<Block {}>", val),

View File

@ -1,3 +1,4 @@
use indexmap::IndexMap;
use nu_engine::CallExt; use nu_engine::CallExt;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
@ -213,9 +214,8 @@ pub fn data_split(
} = grouped } = grouped
{ {
for (inner_idx, subset) in li.iter().enumerate() { for (inner_idx, subset) in li.iter().enumerate() {
let s = splits let s: &mut IndexMap<String, Value> =
.entry(sub_cols[inner_idx].clone()) splits.entry(sub_cols[inner_idx].clone()).or_default();
.or_insert(indexmap::IndexMap::new());
s.insert(cols[idx].clone(), subset.clone()); s.insert(cols[idx].clone(), subset.clone());
} }

View File

@ -100,7 +100,7 @@ fn action(
match input { match input {
Value::Binary { val, .. } => match base64_config.action_type { Value::Binary { val, .. } => match base64_config.action_type {
ActionType::Encode => { ActionType::Encode => {
Value::string(encode_config(&val, base64_config_enum), command_span) Value::string(encode_config(val, base64_config_enum), command_span)
} }
ActionType::Decode => Value::Error { ActionType::Decode => Value::Error {
error: ShellError::UnsupportedInput( error: ShellError::UnsupportedInput(

View File

@ -593,8 +593,8 @@ impl ExternalCommand {
for m in matches { for m in matches {
if let Ok(arg) = m { if let Ok(arg) = m {
let arg = if let Some(prefix) = &prefix { let arg = if let Some(prefix) = &prefix {
if let Ok(remainder) = arg.strip_prefix(&prefix) { if let Ok(remainder) = arg.strip_prefix(prefix) {
let new_prefix = if let Some(pfx) = diff_paths(&prefix, &cwd) { let new_prefix = if let Some(pfx) = diff_paths(prefix, &cwd) {
pfx pfx
} else { } else {
prefix.to_path_buf() prefix.to_path_buf()

View File

@ -973,7 +973,7 @@ fn convert_to_table2<'a>(
data[row].push(value); data[row].push(value);
} }
let count_columns = with_index.then(|| 2).unwrap_or(1); let count_columns = if with_index { 2 } else { 1 };
let size = (data.len(), count_columns); let size = (data.len(), count_columns);
let table = NuTable::new(data, size, usize::MAX, with_header, with_index); let table = NuTable::new(data, size, usize::MAX, with_header, with_index);

View File

@ -1424,7 +1424,7 @@ pub fn parse_module_block(
} }
LiteElement::Or(_, command) LiteElement::Or(_, command)
| LiteElement::And(_, command) | LiteElement::And(_, command)
| LiteElement::Redirection(_, _, command) => (garbage_pipeline(&command.parts)), | LiteElement::Redirection(_, _, command) => garbage_pipeline(&command.parts),
} }
} else { } else {
error = Some(ParseError::Expected("not a pipeline".into(), span)); error = Some(ParseError::Expected("not a pipeline".into(), span));