From 15ebf45f46385b5883237a0917d0381961005901 Mon Sep 17 00:00:00 2001 From: nibon7 Date: Sun, 18 Sep 2022 01:10:32 +0800 Subject: [PATCH] Apply clippy fix for rust 1.63.0 (#6576) * Apply clippy fix to avoid extra allocation error: `format!(..)` appended to existing `String` --> crates/nu-engine/src/documentation.rs:82:9 | 82 | long_desc.push_str(&format!("\n{G}Subcommands{RESET}:\n")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::format-push-string` implied by `-D warnings` = help: consider using `write!` to avoid the extra allocation = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string error: `format!(..)` appended to existing `String` --> crates/nu-engine/src/documentation.rs:96:9 | 96 | long_desc.push_str(&format!("\n{G}Parameters{RESET}:\n")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider using `write!` to avoid the extra allocation = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string error: `format!(..)` appended to existing `String` --> crates/nu-engine/src/documentation.rs:128:9 | 128 | long_desc.push_str(&format!("\n{}Examples{}:", G, RESET)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider using `write!` to avoid the extra allocation = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string error: `format!(..)` appended to existing `String` --> crates/nu-engine/src/documentation.rs:202:5 | 202 | long_desc.push_str(&format!("\n{}Flags{}:\n", G, RESET)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider using `write!` to avoid the extra allocation = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string error: could not compile `nu-engine` due to 4 previous errors * Apply clippy fix to avoid deref on an immutable reference error: deref on an immutable reference --> crates/nu-command/src/dataframe/eager/sql_context.rs:188:77 | 188 | SetExpr::Select(select_stmt) => self.execute_select(&*select_stmt)?, | ^^^^^^^^^^^^^ | = note: `-D clippy::borrow-deref-ref` implied by `-D warnings` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrow_deref_ref help: if you would like to reborrow, try removing `&*` | 188 | SetExpr::Select(select_stmt) => self.execute_select(select_stmt)?, | ~~~~~~~~~~~ help: if you would like to deref, try using `&**` | 188 | SetExpr::Select(select_stmt) => self.execute_select(&**select_stmt)?, | ~~~~~~~~~~~~~~ error: deref on an immutable reference --> crates/nu-command/src/database/values/dsl/expression.rs:252:15 | 252 | match &*expr { | ^^^^^^ help: if you would like to reborrow, try removing `&*`: `expr` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrow_deref_ref error: could not compile `nu-command` due to 2 previous errors --- crates/nu-command/src/database/values/dsl/expression.rs | 2 +- crates/nu-command/src/dataframe/eager/sql_context.rs | 2 +- crates/nu-engine/src/documentation.rs | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/nu-command/src/database/values/dsl/expression.rs b/crates/nu-command/src/database/values/dsl/expression.rs index 2bda5a4b9..9489f8c65 100644 --- a/crates/nu-command/src/database/values/dsl/expression.rs +++ b/crates/nu-command/src/database/values/dsl/expression.rs @@ -249,7 +249,7 @@ impl ExtractedExpr { impl ExprDb { pub fn expr_to_value(expr: &Expr, span: Span) -> Value { - match &*expr { + match expr { Expr::Identifier(ident) => { let cols = vec!["value".into(), "quoted_style".into()]; let val = Value::String { diff --git a/crates/nu-command/src/dataframe/eager/sql_context.rs b/crates/nu-command/src/dataframe/eager/sql_context.rs index 5232f8858..c8106dfa3 100644 --- a/crates/nu-command/src/dataframe/eager/sql_context.rs +++ b/crates/nu-command/src/dataframe/eager/sql_context.rs @@ -185,7 +185,7 @@ impl SQLContext { Ok(match ast { Statement::Query(query) => { let rs = match &*query.body { - SetExpr::Select(select_stmt) => self.execute_select(&*select_stmt)?, + SetExpr::Select(select_stmt) => self.execute_select(select_stmt)?, _ => { return Err(PolarsError::ComputeError( "INSERT, UPDATE is not supported for polars".into(), diff --git a/crates/nu-engine/src/documentation.rs b/crates/nu-engine/src/documentation.rs index 8be8974e6..e2639c1fe 100644 --- a/crates/nu-engine/src/documentation.rs +++ b/crates/nu-engine/src/documentation.rs @@ -79,7 +79,7 @@ fn get_documentation( let _ = write!(long_desc, "{}", text); if !subcommands.is_empty() { - long_desc.push_str(&format!("\n{G}Subcommands{RESET}:\n")); + let _ = write!(long_desc, "\n{G}Subcommands{RESET}:\n"); subcommands.sort(); long_desc.push_str(&subcommands.join("\n")); long_desc.push('\n'); @@ -93,7 +93,7 @@ fn get_documentation( || !sig.optional_positional.is_empty() || sig.rest_positional.is_some() { - long_desc.push_str(&format!("\n{G}Parameters{RESET}:\n")); + let _ = write!(long_desc, "\n{G}Parameters{RESET}:\n"); for positional in &sig.required_positional { let text = format!( " {C}{}{RESET} <{BB}{:?}{RESET}>: {}", @@ -125,7 +125,7 @@ fn get_documentation( } if !examples.is_empty() { - long_desc.push_str(&format!("\n{}Examples{}:", G, RESET)); + let _ = write!(long_desc, "\n{}Examples{}:", G, RESET); } for example in examples { @@ -199,7 +199,7 @@ pub fn get_flags_section(signature: &Signature) -> String { const D: &str = "\x1b[39m"; // default let mut long_desc = String::new(); - long_desc.push_str(&format!("\n{}Flags{}:\n", G, RESET)); + let _ = write!(long_desc, "\n{}Flags{}:\n", G, RESET); for flag in &signature.named { let msg = if let Some(arg) = &flag.arg { if let Some(short) = flag.short {