From 9da0f41ebb882895a7f79e0e32f76ccf9c75963b Mon Sep 17 00:00:00 2001 From: Stefan Holderbach Date: Sun, 29 Jun 2025 17:37:17 +0200 Subject: [PATCH] Fix easy clippy lints from latest stable (#16053) 1.88.0 was released today, clippy now lints (machine-applicable) against: - format strings with empty braces that could be inlined - easy win - `manual_abs_diff` - returning of a stored result of the last expression. - this can be somewhat contentious but touched only a few places --- benches/benchmarks.rs | 12 ++--- .../src/completions/cell_path_completions.rs | 2 +- .../src/completions/command_completions.rs | 2 +- crates/nu-cli/src/completions/completer.rs | 7 ++- .../src/completions/completion_common.rs | 2 +- .../src/completions/dotnu_completions.rs | 4 +- crates/nu-cli/src/repl.rs | 12 ++--- crates/nu-cli/tests/completions/mod.rs | 2 +- .../nu-cmd-extra/src/extra/formats/to/html.rs | 11 ++-- .../src/extra/strings/format/bits.rs | 12 ++--- .../nu-cmd-lang/src/core_commands/describe.rs | 2 +- .../src/core_commands/error_make.rs | 2 +- crates/nu-cmd-lang/src/example_support.rs | 22 ++++---- crates/nu-command/src/charting/histogram.rs | 2 +- .../src/conversions/into/datetime.rs | 2 +- .../src/conversions/into/duration.rs | 3 +- .../src/database/commands/into_sqlite.rs | 8 +-- .../nu-command/src/database/values/sqlite.rs | 2 +- crates/nu-command/src/debug/view_source.rs | 6 +-- crates/nu-command/src/filesystem/mktemp.rs | 4 +- crates/nu-command/src/filesystem/open.rs | 4 +- crates/nu-command/src/filesystem/ucp.rs | 6 +-- crates/nu-command/src/filesystem/umkdir.rs | 4 +- crates/nu-command/src/filesystem/umv.rs | 4 +- crates/nu-command/src/filesystem/utouch.rs | 2 +- crates/nu-command/src/filters/default.rs | 2 +- crates/nu-command/src/filters/join.rs | 5 +- crates/nu-command/src/formats/from/msgpack.rs | 2 +- crates/nu-command/src/formats/from/ssv.rs | 2 +- crates/nu-command/src/formats/from/xml.rs | 2 +- crates/nu-command/src/formats/from/yaml.rs | 15 +++--- crates/nu-command/src/formats/to/delimited.rs | 2 +- crates/nu-command/src/formats/to/md.rs | 6 +-- crates/nu-command/src/formats/to/xml.rs | 8 ++- crates/nu-command/src/generators/generate.rs | 2 +- crates/nu-command/src/help/help_commands.rs | 2 +- crates/nu-command/src/network/http/client.rs | 48 ++++++++--------- .../nu-command/src/network/version_check.rs | 6 +-- .../src/platform/input/input_listen.rs | 2 +- crates/nu-command/src/random/uuid.rs | 12 ++--- crates/nu-command/src/stor/create.rs | 15 +++--- crates/nu-command/src/stor/delete.rs | 6 +-- crates/nu-command/src/stor/insert.rs | 2 +- crates/nu-command/src/stor/update.rs | 2 +- crates/nu-command/src/strings/ansi/ansi_.rs | 6 +-- .../nu-command/src/strings/format/duration.rs | 4 +- crates/nu-command/src/strings/str_/join.rs | 2 +- .../nu-command/src/strings/str_/substring.rs | 2 +- crates/nu-command/src/system/nu_check.rs | 6 +-- crates/nu-command/src/system/uname.rs | 4 +- crates/nu-command/src/viewers/table.rs | 6 +-- crates/nu-command/tests/commands/glob.rs | 2 +- crates/nu-command/tests/commands/into_int.rs | 2 +- crates/nu-command/tests/commands/join.rs | 26 ++++----- crates/nu-command/tests/commands/mktemp.rs | 2 +- crates/nu-command/tests/commands/table.rs | 5 +- crates/nu-command/tests/commands/transpose.rs | 2 +- crates/nu-command/tests/commands/utouch.rs | 5 +- .../tests/format_conversions/msgpack.rs | 2 +- crates/nu-derive-value/src/tests.rs | 54 +++++++------------ crates/nu-engine/src/compile/builder.rs | 2 +- crates/nu-engine/src/documentation.rs | 2 +- crates/nu-engine/src/exit.rs | 2 +- crates/nu-explore/src/nu_common/lscolor.rs | 2 +- .../src/views/binary/binary_widget.rs | 4 +- crates/nu-glob/src/lib.rs | 4 +- crates/nu-lsp/src/completion.rs | 4 +- crates/nu-lsp/src/hints.rs | 4 +- crates/nu-lsp/src/hover.rs | 6 +-- crates/nu-lsp/src/signature.rs | 4 +- crates/nu-parser/src/parse_keywords.rs | 8 ++- crates/nu-parser/src/parse_shape_specs.rs | 12 ++--- crates/nu-parser/src/parser.rs | 9 ++-- crates/nu-parser/tests/test_parser.rs | 11 ++-- .../communication_mode/local_socket/tests.rs | 4 +- .../src/interface/stream/tests.rs | 2 +- crates/nu-plugin-core/src/serializers/json.rs | 3 +- crates/nu-plugin-engine/src/interface/mod.rs | 5 +- .../nu-plugin-test-support/src/plugin_test.rs | 6 +-- crates/nu-plugin/src/plugin/mod.rs | 4 +- crates/nu-protocol/src/engine/engine_state.rs | 5 +- crates/nu-protocol/src/errors/parse_error.rs | 2 +- .../nu-protocol/src/errors/shell_error/mod.rs | 6 +-- crates/nu-protocol/src/ir/display.rs | 4 +- crates/nu-protocol/src/lev_distance.rs | 4 +- .../nu-protocol/src/pipeline/byte_stream.rs | 2 +- .../nu-protocol/src/pipeline/pipeline_data.rs | 2 +- crates/nu-protocol/src/signature.rs | 6 +-- crates/nu-protocol/src/value/mod.rs | 4 +- crates/nu-system/src/util.rs | 2 +- crates/nu-test-support/src/macros.rs | 6 +-- crates/nu-utils/src/utils.rs | 7 ++- crates/nu_plugin_formats/src/from/plist.rs | 6 +-- crates/nu_plugin_formats/src/to/plist.rs | 8 +-- crates/nu_plugin_polars/src/cloud/aws.rs | 4 +- .../src/dataframe/command/core/to_repr.rs | 2 +- .../src/dataframe/command/datetime/mod.rs | 4 +- crates/nu_plugin_polars/src/main.rs | 2 +- src/ide.rs | 2 +- src/test_bins.rs | 2 +- tests/eval/mod.rs | 3 +- tests/repl/test_config_path.rs | 6 +-- 102 files changed, 258 insertions(+), 339 deletions(-) diff --git a/benches/benchmarks.rs b/benches/benchmarks.rs index a6fd2cf7f4..1ffb4ccc92 100644 --- a/benches/benchmarks.rs +++ b/benches/benchmarks.rs @@ -199,7 +199,7 @@ fn bench_record_nested_access(n: usize) -> impl IntoBenchmarks { let nested_access = ".col".repeat(n); bench_command( format!("record_nested_access_{n}"), - format!("$record{} | ignore", nested_access), + format!("$record{nested_access} | ignore"), stack, engine, ) @@ -319,7 +319,7 @@ fn bench_eval_par_each(n: usize) -> impl IntoBenchmarks { let stack = Stack::new(); bench_command( format!("eval_par_each_{n}"), - format!("(1..{}) | par-each -t 2 {{|_| 1 }} | ignore", n), + format!("(1..{n}) | par-each -t 2 {{|_| 1 }} | ignore"), stack, engine, ) @@ -357,7 +357,7 @@ fn encode_json(row_cnt: usize, col_cnt: usize) -> impl IntoBenchmarks { let encoder = Rc::new(EncodingType::try_from_bytes(b"json").unwrap()); [benchmark_fn( - format!("encode_json_{}_{}", row_cnt, col_cnt), + format!("encode_json_{row_cnt}_{col_cnt}"), move |b| { let encoder = encoder.clone(); let test_data = test_data.clone(); @@ -377,7 +377,7 @@ fn encode_msgpack(row_cnt: usize, col_cnt: usize) -> impl IntoBenchmarks { let encoder = Rc::new(EncodingType::try_from_bytes(b"msgpack").unwrap()); [benchmark_fn( - format!("encode_msgpack_{}_{}", row_cnt, col_cnt), + format!("encode_msgpack_{row_cnt}_{col_cnt}"), move |b| { let encoder = encoder.clone(); let test_data = test_data.clone(); @@ -399,7 +399,7 @@ fn decode_json(row_cnt: usize, col_cnt: usize) -> impl IntoBenchmarks { encoder.encode(&test_data, &mut res).unwrap(); [benchmark_fn( - format!("decode_json_{}_{}", row_cnt, col_cnt), + format!("decode_json_{row_cnt}_{col_cnt}"), move |b| { let res = res.clone(); b.iter(move || { @@ -422,7 +422,7 @@ fn decode_msgpack(row_cnt: usize, col_cnt: usize) -> impl IntoBenchmarks { encoder.encode(&test_data, &mut res).unwrap(); [benchmark_fn( - format!("decode_msgpack_{}_{}", row_cnt, col_cnt), + format!("decode_msgpack_{row_cnt}_{col_cnt}"), move |b| { let res = res.clone(); b.iter(move || { diff --git a/crates/nu-cli/src/completions/cell_path_completions.rs b/crates/nu-cli/src/completions/cell_path_completions.rs index 51ca0b5409..9837a6708b 100644 --- a/crates/nu-cli/src/completions/cell_path_completions.rs +++ b/crates/nu-cli/src/completions/cell_path_completions.rs @@ -118,7 +118,7 @@ fn get_suggestions_by_value( || s.chars() .any(|c: char| !(c.is_ascii_alphabetic() || ['_', '-'].contains(&c))) { - format!("{:?}", s) + format!("{s:?}") } else { s }; diff --git a/crates/nu-cli/src/completions/command_completions.rs b/crates/nu-cli/src/completions/command_completions.rs index ce745362de..113a431cbb 100644 --- a/crates/nu-cli/src/completions/command_completions.rs +++ b/crates/nu-cli/src/completions/command_completions.rs @@ -52,7 +52,7 @@ impl CommandCompletion { continue; }; let value = if matched_internal(&name) { - format!("^{}", name) + format!("^{name}") } else { name.clone() }; diff --git a/crates/nu-cli/src/completions/completer.rs b/crates/nu-cli/src/completions/completer.rs index 3de89fbee1..f6b1cdfdac 100644 --- a/crates/nu-cli/src/completions/completer.rs +++ b/crates/nu-cli/src/completions/completer.rs @@ -176,7 +176,7 @@ impl NuCompleter { &mut working_set, Some("completer"), // Add a placeholder `a` to the end - format!("{}a", line).as_bytes(), + format!("{line}a").as_bytes(), false, ); self.fetch_completions_by_block(block, &working_set, pos, offset, line, true) @@ -850,7 +850,7 @@ mod completer_tests { for (line, has_result, begins_with, expected_values) in dataset { let result = completer.fetch_completions_at(line, line.len()); // Test whether the result is empty or not - assert_eq!(!result.is_empty(), has_result, "line: {}", line); + assert_eq!(!result.is_empty(), has_result, "line: {line}"); // Test whether the result begins with the expected value result @@ -865,8 +865,7 @@ mod completer_tests { .filter(|x| *x) .count(), expected_values.len(), - "line: {}", - line + "line: {line}" ); } } diff --git a/crates/nu-cli/src/completions/completion_common.rs b/crates/nu-cli/src/completions/completion_common.rs index 41f6c0c7db..b86418b36e 100644 --- a/crates/nu-cli/src/completions/completion_common.rs +++ b/crates/nu-cli/src/completions/completion_common.rs @@ -314,7 +314,7 @@ pub fn escape_path(path: String) -> String { if path.contains('\'') { // decide to use double quotes // Path as Debug will do the escaping for `"`, `\` - format!("{:?}", path) + format!("{path:?}") } else { format!("'{path}'") } diff --git a/crates/nu-cli/src/completions/dotnu_completions.rs b/crates/nu-cli/src/completions/dotnu_completions.rs index 299fb995be..fecdb576bc 100644 --- a/crates/nu-cli/src/completions/dotnu_completions.rs +++ b/crates/nu-cli/src/completions/dotnu_completions.rs @@ -129,7 +129,7 @@ impl Completer for DotNuCompletion { .take_while(|c| "`'\"".contains(*c)) .collect::(); for path in ["std", "std-rfc"] { - let path = format!("{}{}", surround_prefix, path); + let path = format!("{surround_prefix}{path}"); matcher.add( path.clone(), FileSuggestion { @@ -146,7 +146,7 @@ impl Completer for DotNuCompletion { for sub_vp_id in sub_paths { let (path, sub_vp) = working_set.get_virtual_path(*sub_vp_id); let path = path - .strip_prefix(&format!("{}/", base_dir)) + .strip_prefix(&format!("{base_dir}/")) .unwrap_or(path) .to_string(); matcher.add( diff --git a/crates/nu-cli/src/repl.rs b/crates/nu-cli/src/repl.rs index f003f15b0e..64a1734513 100644 --- a/crates/nu-cli/src/repl.rs +++ b/crates/nu-cli/src/repl.rs @@ -239,7 +239,7 @@ fn escape_special_vscode_bytes(input: &str) -> Result { match byte { // Escape bytes below 0x20 - b if b < 0x20 => format!("\\x{:02X}", byte).into_bytes(), + b if b < 0x20 => format!("\\x{byte:02X}").into_bytes(), // Escape semicolon as \x3B b';' => "\\x3B".to_string().into_bytes(), // Escape backslash as \\ @@ -1097,8 +1097,7 @@ fn run_shell_integration_osc633( // If we're in vscode, run their specific ansi escape sequence. // This is helpful for ctrl+g to change directories in the terminal. run_ansi_sequence(&format!( - "{}{}{}", - VSCODE_CWD_PROPERTY_MARKER_PREFIX, path, VSCODE_CWD_PROPERTY_MARKER_SUFFIX + "{VSCODE_CWD_PROPERTY_MARKER_PREFIX}{path}{VSCODE_CWD_PROPERTY_MARKER_SUFFIX}" )); perf!( @@ -1114,10 +1113,7 @@ fn run_shell_integration_osc633( //OSC 633 ; E ; [; >() .join(", "), completer_opts, diff --git a/crates/nu-cmd-extra/src/extra/formats/to/html.rs b/crates/nu-cmd-extra/src/extra/formats/to/html.rs index a95867a2c9..566b593747 100644 --- a/crates/nu-cmd-extra/src/extra/formats/to/html.rs +++ b/crates/nu-cmd-extra/src/extra/formats/to/html.rs @@ -188,7 +188,7 @@ fn get_theme_from_asset_file( Some(t) => t, None => { return Err(ShellError::TypeMismatch { - err_message: format!("Unknown HTML theme '{}'", theme_name), + err_message: format!("Unknown HTML theme '{theme_name}'"), span: theme_span, }); } @@ -774,8 +774,7 @@ mod tests { for key in required_keys { assert!( theme_map.contains_key(key), - "Expected theme to contain key '{}'", - key + "Expected theme to contain key '{key}'" ); } } @@ -792,15 +791,13 @@ mod tests { if let Err(err) = result { assert!( matches!(err, ShellError::TypeMismatch { .. }), - "Expected TypeMismatch error, got: {:?}", - err + "Expected TypeMismatch error, got: {err:?}" ); if let ShellError::TypeMismatch { err_message, span } = err { assert!( err_message.contains("doesnt-exist"), - "Error message should mention theme name, got: {}", - err_message + "Error message should mention theme name, got: {err_message}" ); assert_eq!(span.start, 0); assert_eq!(span.end, 13); diff --git a/crates/nu-cmd-extra/src/extra/strings/format/bits.rs b/crates/nu-cmd-extra/src/extra/strings/format/bits.rs index f8d930914c..584109a5b4 100644 --- a/crates/nu-cmd-extra/src/extra/strings/format/bits.rs +++ b/crates/nu-cmd-extra/src/extra/strings/format/bits.rs @@ -161,28 +161,28 @@ fn convert_to_smallest_number_type(num: i64, span: Span) -> Value { let bytes = v.to_ne_bytes(); let mut raw_string = "".to_string(); for ch in bytes { - raw_string.push_str(&format!("{:08b} ", ch)); + raw_string.push_str(&format!("{ch:08b} ")); } Value::string(raw_string.trim(), span) } else if let Some(v) = num.to_i16() { let bytes = v.to_ne_bytes(); let mut raw_string = "".to_string(); for ch in bytes { - raw_string.push_str(&format!("{:08b} ", ch)); + raw_string.push_str(&format!("{ch:08b} ")); } Value::string(raw_string.trim(), span) } else if let Some(v) = num.to_i32() { let bytes = v.to_ne_bytes(); let mut raw_string = "".to_string(); for ch in bytes { - raw_string.push_str(&format!("{:08b} ", ch)); + raw_string.push_str(&format!("{ch:08b} ")); } Value::string(raw_string.trim(), span) } else { let bytes = num.to_ne_bytes(); let mut raw_string = "".to_string(); for ch in bytes { - raw_string.push_str(&format!("{:08b} ", ch)); + raw_string.push_str(&format!("{ch:08b} ")); } Value::string(raw_string.trim(), span) } @@ -193,7 +193,7 @@ fn action(input: &Value, _args: &Arguments, span: Span) -> Value { Value::Binary { val, .. } => { let mut raw_string = "".to_string(); for ch in val { - raw_string.push_str(&format!("{:08b} ", ch)); + raw_string.push_str(&format!("{ch:08b} ")); } Value::string(raw_string.trim(), span) } @@ -204,7 +204,7 @@ fn action(input: &Value, _args: &Arguments, span: Span) -> Value { let raw_bytes = val.as_bytes(); let mut raw_string = "".to_string(); for ch in raw_bytes { - raw_string.push_str(&format!("{:08b} ", ch)); + raw_string.push_str(&format!("{ch:08b} ")); } Value::string(raw_string.trim(), span) } diff --git a/crates/nu-cmd-lang/src/core_commands/describe.rs b/crates/nu-cmd-lang/src/core_commands/describe.rs index d473b2b8df..9430f5047e 100644 --- a/crates/nu-cmd-lang/src/core_commands/describe.rs +++ b/crates/nu-cmd-lang/src/core_commands/describe.rs @@ -296,7 +296,7 @@ fn run( } else { let value = stream.into_value(); let base_description = value.get_type().to_string(); - Value::string(format!("{} (stream)", base_description), head) + Value::string(format!("{base_description} (stream)"), head) } } PipelineData::Value(value, ..) => { diff --git a/crates/nu-cmd-lang/src/core_commands/error_make.rs b/crates/nu-cmd-lang/src/core_commands/error_make.rs index a43d36feab..b620dd9318 100644 --- a/crates/nu-cmd-lang/src/core_commands/error_make.rs +++ b/crates/nu-cmd-lang/src/core_commands/error_make.rs @@ -229,7 +229,7 @@ fn make_other_error(value: &Value, throw_span: Option) -> ShellError { error: "invalid error format.".into(), msg: "`$.label.start` should be smaller than `$.label.end`".into(), span: Some(label_span), - help: Some(format!("{} > {}", span_start, span_end)), + help: Some(format!("{span_start} > {span_end}")), inner: vec![], }; } diff --git a/crates/nu-cmd-lang/src/example_support.rs b/crates/nu-cmd-lang/src/example_support.rs index d78e606a46..e8afb65528 100644 --- a/crates/nu-cmd-lang/src/example_support.rs +++ b/crates/nu-cmd-lang/src/example_support.rs @@ -221,23 +221,23 @@ impl std::fmt::Debug for DebuggableValue<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self.0 { Value::Bool { val, .. } => { - write!(f, "{:?}", val) + write!(f, "{val:?}") } Value::Int { val, .. } => { - write!(f, "{:?}", val) + write!(f, "{val:?}") } Value::Float { val, .. } => { - write!(f, "{:?}f", val) + write!(f, "{val:?}f") } Value::Filesize { val, .. } => { - write!(f, "Filesize({:?})", val) + write!(f, "Filesize({val:?})") } Value::Duration { val, .. } => { let duration = std::time::Duration::from_nanos(*val as u64); - write!(f, "Duration({:?})", duration) + write!(f, "Duration({duration:?})") } Value::Date { val, .. } => { - write!(f, "Date({:?})", val) + write!(f, "Date({val:?})") } Value::Range { val, .. } => match **val { Range::IntRange(range) => match range.end() { @@ -280,7 +280,7 @@ impl std::fmt::Debug for DebuggableValue<'_> { }, }, Value::String { val, .. } | Value::Glob { val, .. } => { - write!(f, "{:?}", val) + write!(f, "{val:?}") } Value::Record { val, .. } => { write!(f, "{{")?; @@ -305,22 +305,22 @@ impl std::fmt::Debug for DebuggableValue<'_> { write!(f, "]") } Value::Closure { val, .. } => { - write!(f, "Closure({:?})", val) + write!(f, "Closure({val:?})") } Value::Nothing { .. } => { write!(f, "Nothing") } Value::Error { error, .. } => { - write!(f, "Error({:?})", error) + write!(f, "Error({error:?})") } Value::Binary { val, .. } => { - write!(f, "Binary({:?})", val) + write!(f, "Binary({val:?})") } Value::CellPath { val, .. } => { write!(f, "CellPath({:?})", val.to_string()) } Value::Custom { val, .. } => { - write!(f, "CustomValue({:?})", val) + write!(f, "CustomValue({val:?})") } } } diff --git a/crates/nu-command/src/charting/histogram.rs b/crates/nu-command/src/charting/histogram.rs index 7587484638..a76d79b30d 100755 --- a/crates/nu-command/src/charting/histogram.rs +++ b/crates/nu-command/src/charting/histogram.rs @@ -89,7 +89,7 @@ impl Command for Histogram { "frequency-column-name can't be {}", forbidden_column_names .iter() - .map(|val| format!("'{}'", val)) + .map(|val| format!("'{val}'")) .collect::>() .join(", ") ), diff --git a/crates/nu-command/src/conversions/into/datetime.rs b/crates/nu-command/src/conversions/into/datetime.rs index a93769cf1a..862dbeaef2 100644 --- a/crates/nu-command/src/conversions/into/datetime.rs +++ b/crates/nu-command/src/conversions/into/datetime.rs @@ -678,7 +678,7 @@ fn parse_value_from_record_as_u32( Value::Int { val, .. } => { if *val < 0 || *val > u32::MAX as i64 { return Err(ShellError::IncorrectValue { - msg: format!("incorrect value for {}", col), + msg: format!("incorrect value for {col}"), val_span: *head, call_span: *span, }); diff --git a/crates/nu-command/src/conversions/into/duration.rs b/crates/nu-command/src/conversions/into/duration.rs index 3af0134868..12e16b8644 100644 --- a/crates/nu-command/src/conversions/into/duration.rs +++ b/crates/nu-command/src/conversions/into/duration.rs @@ -368,8 +368,7 @@ fn merge_record(record: &Record, head: Span, span: Span) -> Result(), Itertools::intersperse(itertools::repeat_n("?", val.len()), ", ").collect::(), ); @@ -381,7 +381,7 @@ fn get_columns_with_sqlite_types( .map(|name| (format!("`{}`", name.0), name.1)) .any(|(name, _)| name == *c) { - columns.push((format!("`{}`", c), nu_value_to_sqlite_type(v)?)); + columns.push((format!("`{c}`"), nu_value_to_sqlite_type(v)?)); } } diff --git a/crates/nu-command/src/database/values/sqlite.rs b/crates/nu-command/src/database/values/sqlite.rs index 7fee136269..23f744fa9f 100644 --- a/crates/nu-command/src/database/values/sqlite.rs +++ b/crates/nu-command/src/database/values/sqlite.rs @@ -173,7 +173,7 @@ impl SQLiteDatabase { filename: String, ) -> Result<(), SqliteError> { //vacuum main into 'c:\\temp\\foo.db' - conn.execute(&format!("vacuum main into '{}'", filename), [])?; + conn.execute(&format!("vacuum main into '{filename}'"), [])?; Ok(()) } diff --git a/crates/nu-command/src/debug/view_source.rs b/crates/nu-command/src/debug/view_source.rs index ddacd64c78..51efa00757 100644 --- a/crates/nu-command/src/debug/view_source.rs +++ b/crates/nu-command/src/debug/view_source.rs @@ -126,10 +126,10 @@ impl Command for ViewSource { } let _ = write!(&mut final_contents, "--{}", n.long); if let Some(short) = n.short { - let _ = write!(&mut final_contents, "(-{})", short); + let _ = write!(&mut final_contents, "(-{short})"); } if let Some(arg) = &n.arg { - let _ = write!(&mut final_contents, ": {}", arg); + let _ = write!(&mut final_contents, ": {arg}"); } final_contents.push(' '); } @@ -146,7 +146,7 @@ impl Command for ViewSource { let mut c = 0; for (insig, outsig) in type_signatures { c += 1; - let s = format!("{} -> {}", insig, outsig); + let s = format!("{insig} -> {outsig}"); final_contents.push_str(&s); if c != len { final_contents.push_str(", ") diff --git a/crates/nu-command/src/filesystem/mktemp.rs b/crates/nu-command/src/filesystem/mktemp.rs index 5ebd054acb..4449a09b58 100644 --- a/crates/nu-command/src/filesystem/mktemp.rs +++ b/crates/nu-command/src/filesystem/mktemp.rs @@ -112,8 +112,8 @@ impl Command for Mktemp { .map_err(|_| ShellError::NonUtf8 { span })?, Err(e) => { return Err(ShellError::GenericError { - error: format!("{}", e), - msg: format!("{}", e), + error: format!("{e}"), + msg: format!("{e}"), span: None, help: None, inner: vec![], diff --git a/crates/nu-command/src/filesystem/open.rs b/crates/nu-command/src/filesystem/open.rs index 521301b530..74e8800b27 100644 --- a/crates/nu-command/src/filesystem/open.rs +++ b/crates/nu-command/src/filesystem/open.rs @@ -198,7 +198,7 @@ impl Command for Open { let converter = exts_opt.and_then(|exts| { exts.iter().find_map(|ext| { engine_state - .find_decl(format!("from {}", ext).as_bytes(), &[]) + .find_decl(format!("from {ext}").as_bytes(), &[]) .map(|id| (id, ext.to_string())) }) }); @@ -314,7 +314,7 @@ fn extract_extensions(filename: &str) -> Vec { if current_extension.is_empty() { current_extension.push_str(part); } else { - current_extension = format!("{}.{}", part, current_extension); + current_extension = format!("{part}.{current_extension}"); } extensions.push(current_extension.clone()); } diff --git a/crates/nu-command/src/filesystem/ucp.rs b/crates/nu-command/src/filesystem/ucp.rs index 673f4e34d9..122d389785 100644 --- a/crates/nu-command/src/filesystem/ucp.rs +++ b/crates/nu-command/src/filesystem/ucp.rs @@ -272,8 +272,8 @@ impl Command for UCp { uu_cp::Error::NotAllFilesCopied => {} _ => { return Err(ShellError::GenericError { - error: format!("{}", error), - msg: format!("{}", error), + error: format!("{error}"), + msg: format!("{error}"), span: None, help: None, inner: vec![], @@ -373,7 +373,7 @@ fn parse_and_set_attribute( "xattr" => &mut attribute.xattr, _ => { return Err(ShellError::IncompatibleParametersSingle { - msg: format!("--preserve flag got an unexpected attribute \"{}\"", val), + msg: format!("--preserve flag got an unexpected attribute \"{val}\""), span: value.span(), }); } diff --git a/crates/nu-command/src/filesystem/umkdir.rs b/crates/nu-command/src/filesystem/umkdir.rs index 589fd6f76d..9df09a22f2 100644 --- a/crates/nu-command/src/filesystem/umkdir.rs +++ b/crates/nu-command/src/filesystem/umkdir.rs @@ -77,8 +77,8 @@ impl Command for UMkdir { for dir in directories { if let Err(error) = mkdir(&dir, IS_RECURSIVE, get_mode(), is_verbose) { return Err(ShellError::GenericError { - error: format!("{}", error), - msg: format!("{}", error), + error: format!("{error}"), + msg: format!("{error}"), span: None, help: None, inner: vec![], diff --git a/crates/nu-command/src/filesystem/umv.rs b/crates/nu-command/src/filesystem/umv.rs index edee8e3b84..ce7f5d6e3c 100644 --- a/crates/nu-command/src/filesystem/umv.rs +++ b/crates/nu-command/src/filesystem/umv.rs @@ -195,8 +195,8 @@ impl Command for UMv { }; if let Err(error) = uu_mv::mv(&files, &options) { return Err(ShellError::GenericError { - error: format!("{}", error), - msg: format!("{}", error), + error: format!("{error}"), + msg: format!("{error}"), span: None, help: None, inner: Vec::new(), diff --git a/crates/nu-command/src/filesystem/utouch.rs b/crates/nu-command/src/filesystem/utouch.rs index fa261d5377..2e59718a74 100644 --- a/crates/nu-command/src/filesystem/utouch.rs +++ b/crates/nu-command/src/filesystem/utouch.rs @@ -220,7 +220,7 @@ impl Command for UTouch { inner: Vec::new(), }, TouchError::InvalidDateFormat(date) => ShellError::IncorrectValue { - msg: format!("Invalid date: {}", date), + msg: format!("Invalid date: {date}"), val_span: date_span.expect("touch should've been given a date"), call_span: call.head, }, diff --git a/crates/nu-command/src/filters/default.rs b/crates/nu-command/src/filters/default.rs index 5d0d3580ab..9d9799df23 100644 --- a/crates/nu-command/src/filters/default.rs +++ b/crates/nu-command/src/filters/default.rs @@ -334,7 +334,7 @@ fn closure_variable_warning( Cow::Owned(s) if s.deref() == "$carapace_completer" => { carapace_suggestion.to_string() } - _ => format!("change this to {{ {} }}", span_contents).to_string(), + _ => format!("change this to {{ {span_contents} }}").to_string(), }; report_shell_warning( diff --git a/crates/nu-command/src/filters/join.rs b/crates/nu-command/src/filters/join.rs index 1dea038347..d435a971c3 100644 --- a/crates/nu-command/src/filters/join.rs +++ b/crates/nu-command/src/filters/join.rs @@ -379,10 +379,7 @@ fn merge_records(left: &Record, right: &Record, shared_key: Option<&str>) -> Rec let k_shared = shared_key == Some(k.as_str()); // Do not output shared join key twice if !(k_seen && k_shared) { - record.push( - if k_seen { format!("{}_", k) } else { k.clone() }, - v.clone(), - ); + record.push(if k_seen { format!("{k}_") } else { k.clone() }, v.clone()); } } record diff --git a/crates/nu-command/src/formats/from/msgpack.rs b/crates/nu-command/src/formats/from/msgpack.rs index 4fe849b8fe..89f3981ebd 100644 --- a/crates/nu-command/src/formats/from/msgpack.rs +++ b/crates/nu-command/src/formats/from/msgpack.rs @@ -212,7 +212,7 @@ impl From for ShellError { }, ReadError::TypeMismatch(marker, span) => ShellError::GenericError { error: "Invalid marker while reading MessagePack data".into(), - msg: format!("unexpected {:?} in data", marker), + msg: format!("unexpected {marker:?} in data"), span: Some(span), help: None, inner: vec![], diff --git a/crates/nu-command/src/formats/from/ssv.rs b/crates/nu-command/src/formats/from/ssv.rs index fb2d55c19e..734d8b5a3c 100644 --- a/crates/nu-command/src/formats/from/ssv.rs +++ b/crates/nu-command/src/formats/from/ssv.rs @@ -167,7 +167,7 @@ fn parse_aligned_columns<'a>( let headers: Vec<(String, usize)> = indices .iter() .enumerate() - .map(|(i, position)| (format!("column{}", i), *position)) + .map(|(i, position)| (format!("column{i}"), *position)) .collect(); construct(ls.iter().map(|s| s.to_owned()), headers) diff --git a/crates/nu-command/src/formats/from/xml.rs b/crates/nu-command/src/formats/from/xml.rs index 8ad2887f4a..47f200a9aa 100644 --- a/crates/nu-command/src/formats/from/xml.rs +++ b/crates/nu-command/src/formats/from/xml.rs @@ -252,7 +252,7 @@ fn process_xml_parse_error(source: String, err: roxmltree::Error, span: Span) -> pos, ), roxmltree::Error::UnknownNamespace(prefix, pos) => { - make_xml_error_spanned(format!("Unknown prefix {}", prefix), source, pos) + make_xml_error_spanned(format!("Unknown prefix {prefix}"), source, pos) } roxmltree::Error::UnexpectedCloseTag(expected, actual, pos) => make_xml_error_spanned( format!("Unexpected close tag {actual}, expected {expected}"), diff --git a/crates/nu-command/src/formats/from/yaml.rs b/crates/nu-command/src/formats/from/yaml.rs index 649f7e83ac..1fad95a52a 100644 --- a/crates/nu-command/src/formats/from/yaml.rs +++ b/crates/nu-command/src/formats/from/yaml.rs @@ -158,27 +158,26 @@ fn convert_yaml_value_to_nu_value( } serde_yaml::Value::Tagged(t) => { let tag = &t.tag; - let value = match &t.value { + + match &t.value { serde_yaml::Value::String(s) => { - let val = format!("{} {}", tag, s).trim().to_string(); + let val = format!("{tag} {s}").trim().to_string(); Value::string(val, span) } serde_yaml::Value::Number(n) => { - let val = format!("{} {}", tag, n).trim().to_string(); + let val = format!("{tag} {n}").trim().to_string(); Value::string(val, span) } serde_yaml::Value::Bool(b) => { - let val = format!("{} {}", tag, b).trim().to_string(); + let val = format!("{tag} {b}").trim().to_string(); Value::string(val, span) } serde_yaml::Value::Null => { - let val = format!("{}", tag).trim().to_string(); + let val = format!("{tag}").trim().to_string(); Value::string(val, span) } v => convert_yaml_value_to_nu_value(v, span, val_span)?, - }; - - value + } } serde_yaml::Value::Null => Value::nothing(span), x => unimplemented!("Unsupported YAML case: {:?}", x), diff --git a/crates/nu-command/src/formats/to/delimited.rs b/crates/nu-command/src/formats/to/delimited.rs index 1062b7e6ca..f3278bc123 100644 --- a/crates/nu-command/src/formats/to/delimited.rs +++ b/crates/nu-command/src/formats/to/delimited.rs @@ -50,7 +50,7 @@ fn make_unsupported_input_error( ) -> ShellError { ShellError::UnsupportedInput { msg: "expected table or record".to_string(), - input: format!("input type: {}", r#type), + input: format!("input type: {type}"), msg_span: head, input_span: span, } diff --git a/crates/nu-command/src/formats/to/md.rs b/crates/nu-command/src/formats/to/md.rs index 487eded072..0d12b38732 100644 --- a/crates/nu-command/src/formats/to/md.rs +++ b/crates/nu-command/src/formats/to/md.rs @@ -246,7 +246,7 @@ fn table( escaped_rows.push(escaped_row); } - let output_string = if (column_widths.is_empty() || column_widths.iter().all(|x| *x == 0)) + if (column_widths.is_empty() || column_widths.iter().all(|x| *x == 0)) && escaped_rows.is_empty() { String::from("") @@ -260,9 +260,7 @@ fn table( ) .trim() .to_string() - }; - - output_string + } } pub fn group_by(values: PipelineData, head: Span, config: &Config) -> (PipelineData, bool) { diff --git a/crates/nu-command/src/formats/to/xml.rs b/crates/nu-command/src/formats/to/xml.rs index f64da04314..7a6e718e40 100644 --- a/crates/nu-command/src/formats/to/xml.rs +++ b/crates/nu-command/src/formats/to/xml.rs @@ -210,8 +210,7 @@ impl Job { from_type: "record".into(), span: entry_span, help: Some(format!( - "Invalid column \"{}\" in xml entry. Only \"{}\", \"{}\" and \"{}\" are permitted", - bad_column, COLUMN_TAG_NAME, COLUMN_ATTRS_NAME, COLUMN_CONTENT_NAME + "Invalid column \"{bad_column}\" in xml entry. Only \"{COLUMN_TAG_NAME}\", \"{COLUMN_ATTRS_NAME}\" and \"{COLUMN_CONTENT_NAME}\" are permitted" )), }); } @@ -399,7 +398,7 @@ impl Job { }); } - let content_text = format!("{} {}", tag, content); + let content_text = format!("{tag} {content}"); // PI content must NOT be escaped // https://www.w3.org/TR/xml/#sec-pi let pi_content = BytesPI::new(content_text.as_str()); @@ -428,8 +427,7 @@ impl Job { from_type: Type::record().to_string(), span: tag_span, help: Some(format!( - "Incorrect tag name {}, tag name can not start with ! or ?", - tag + "Incorrect tag name {tag}, tag name can not start with ! or ?" )), }); } diff --git a/crates/nu-command/src/generators/generate.rs b/crates/nu-command/src/generators/generate.rs index f81f78acfd..9a59e064f7 100644 --- a/crates/nu-command/src/generators/generate.rs +++ b/crates/nu-command/src/generators/generate.rs @@ -211,7 +211,7 @@ fn parse_closure_result( } else { let error = ShellError::GenericError { error: "Invalid block return".into(), - msg: format!("Unexpected record key '{}'", k), + msg: format!("Unexpected record key '{k}'"), span: Some(span), help: None, inner: vec![], diff --git a/crates/nu-command/src/help/help_commands.rs b/crates/nu-command/src/help/help_commands.rs index 7ea035fd6b..5687aa99d2 100644 --- a/crates/nu-command/src/help/help_commands.rs +++ b/crates/nu-command/src/help/help_commands.rs @@ -144,7 +144,7 @@ fn build_help_commands(engine_state: &EngineState, span: Span) -> PipelineData { for named_param in &sig.named { let name = if let Some(short) = named_param.short { if named_param.long.is_empty() { - format!("-{}", short) + format!("-{short}") } else { format!("--{}(-{})", named_param.long, short) } diff --git a/crates/nu-command/src/network/http/client.rs b/crates/nu-command/src/network/http/client.rs index b932f734bd..0d6097988a 100644 --- a/crates/nu-command/src/network/http/client.rs +++ b/crates/nu-command/src/network/http/client.rs @@ -80,9 +80,9 @@ pub fn http_parse_url( ) -> Result<(String, Url), ShellError> { let mut requested_url = raw_url.coerce_into_string()?; if requested_url.starts_with(':') { - requested_url = format!("http://localhost{}", requested_url); + requested_url = format!("http://localhost{requested_url}"); } else if !requested_url.contains("://") { - requested_url = format!("http://{}", requested_url); + requested_url = format!("http://{requested_url}"); } let url = match url::Url::parse(&requested_url) { @@ -382,8 +382,7 @@ fn send_multipart_request( "Content-Type: application/octet-stream".to_string(), "Content-Transfer-Encoding: binary".to_string(), format!( - "Content-Disposition: form-data; name=\"{}\"; filename=\"{}\"", - col, col + "Content-Disposition: form-data; name=\"{col}\"; filename=\"{col}\"" ), format!("Content-Length: {}", val.len()), ]; @@ -391,7 +390,7 @@ fn send_multipart_request( .add(&mut Cursor::new(val), &headers.join("\r\n")) .map_err(err)?; } else { - let headers = format!(r#"Content-Disposition: form-data; name="{}""#, col); + let headers = format!(r#"Content-Disposition: form-data; name="{col}""#); builder .add(val.coerce_into_string()?.as_bytes(), &headers) .map_err(err)?; @@ -400,7 +399,7 @@ fn send_multipart_request( builder.finish(); let (boundary, data) = (builder.boundary, builder.data); - let content_type = format!("multipart/form-data; boundary={}", boundary); + let content_type = format!("multipart/form-data; boundary={boundary}"); move || req.set("Content-Type", &content_type).send_bytes(&data) } @@ -703,26 +702,23 @@ fn transform_response_using_content_type( .expect("Failed to parse content type, and failed to default to text/plain"); let ext = match (content_type.type_(), content_type.subtype()) { - (mime::TEXT, mime::PLAIN) => { - let path_extension = url::Url::parse(requested_url) - .map_err(|err| { - LabeledError::new(err.to_string()) - .with_help("cannot parse") - .with_label( - format!("Cannot parse URL: {requested_url}"), - Span::unknown(), - ) - })? - .path_segments() - .and_then(|mut segments| segments.next_back()) - .and_then(|name| if name.is_empty() { None } else { Some(name) }) - .and_then(|name| { - PathBuf::from(name) - .extension() - .map(|name| name.to_string_lossy().to_string()) - }); - path_extension - } + (mime::TEXT, mime::PLAIN) => url::Url::parse(requested_url) + .map_err(|err| { + LabeledError::new(err.to_string()) + .with_help("cannot parse") + .with_label( + format!("Cannot parse URL: {requested_url}"), + Span::unknown(), + ) + })? + .path_segments() + .and_then(|mut segments| segments.next_back()) + .and_then(|name| if name.is_empty() { None } else { Some(name) }) + .and_then(|name| { + PathBuf::from(name) + .extension() + .map(|name| name.to_string_lossy().to_string()) + }), _ => Some(content_type.subtype().to_string()), }; diff --git a/crates/nu-command/src/network/version_check.rs b/crates/nu-command/src/network/version_check.rs index 7d230d3bf9..9c3613169d 100644 --- a/crates/nu-command/src/network/version_check.rs +++ b/crates/nu-command/src/network/version_check.rs @@ -64,7 +64,7 @@ impl Registry for NuShellNightly { tag_name: String, } - let url = format!("https://api.github.com/repos/{}/releases", pkg); + let url = format!("https://api.github.com/repos/{pkg}/releases"); let versions = http_client .add_header("Accept", "application/vnd.github.v3+json") .add_header("User-Agent", "update-informer") @@ -128,7 +128,7 @@ pub fn check_for_latest_nushell_version() -> Value { if let Ok(Some(new_version)) = informer.check_version() { rec.push("current", Value::test_bool(false)); - rec.push("latest", Value::test_string(format!("{}", new_version))); + rec.push("latest", Value::test_string(format!("{new_version}"))); Value::test_record(rec) } else { rec.push("current", Value::test_bool(true)); @@ -148,7 +148,7 @@ pub fn check_for_latest_nushell_version() -> Value { if let Ok(Some(new_version)) = informer.check_version() { rec.push("current", Value::test_bool(false)); - rec.push("latest", Value::test_string(format!("{}", new_version))); + rec.push("latest", Value::test_string(format!("{new_version}"))); Value::test_record(rec) } else { rec.push("current", Value::test_bool(true)); diff --git a/crates/nu-command/src/platform/input/input_listen.rs b/crates/nu-command/src/platform/input/input_listen.rs index 2fccaeb7c3..8c4c0e610a 100644 --- a/crates/nu-command/src/platform/input/input_listen.rs +++ b/crates/nu-command/src/platform/input/input_listen.rs @@ -208,7 +208,7 @@ impl EventTypeFilter { fn wrong_type_error(head: Span, val: &str, val_span: Span) -> ShellError { ShellError::UnsupportedInput { - msg: format!("{} is not a valid event type", val), + msg: format!("{val} is not a valid event type"), input: "value originates from here".into(), msg_span: head, input_span: val_span, diff --git a/crates/nu-command/src/random/uuid.rs b/crates/nu-command/src/random/uuid.rs index 48b2df8ee4..4299429c55 100644 --- a/crates/nu-command/src/random/uuid.rs +++ b/crates/nu-command/src/random/uuid.rs @@ -135,8 +135,7 @@ fn uuid( _ => { return Err(ShellError::IncorrectValue { msg: format!( - "Unsupported UUID version: {}. Supported versions are 1, 3, 4, 5, and 7.", - version + "Unsupported UUID version: {version}. Supported versions are 1, 3, 4, 5, and 7." ), val_span: span, call_span: span, @@ -190,8 +189,7 @@ fn validate_flags( if v != 4 && v != 7 { return Err(ShellError::IncorrectValue { msg: format!( - "Unsupported UUID version: {}. Supported versions are 1, 3, 4, 5, and 7.", - v + "Unsupported UUID version: {v}. Supported versions are 1, 3, 4, 5, and 7." ), val_span: span, call_span: span, @@ -202,7 +200,7 @@ fn validate_flags( .is_some() { return Err(ShellError::IncompatibleParametersSingle { - msg: format!("version {} uuid does not take mac as a parameter", v), + msg: format!("version {v} uuid does not take mac as a parameter"), span, }); } @@ -211,7 +209,7 @@ fn validate_flags( .is_some() { return Err(ShellError::IncompatibleParametersSingle { - msg: format!("version {} uuid does not take namespace as a parameter", v), + msg: format!("version {v} uuid does not take namespace as a parameter"), span, }); } @@ -220,7 +218,7 @@ fn validate_flags( .is_some() { return Err(ShellError::IncompatibleParametersSingle { - msg: format!("version {} uuid does not take name as a parameter", v), + msg: format!("version {v} uuid does not take name as a parameter"), span, }); } diff --git a/crates/nu-command/src/stor/create.rs b/crates/nu-command/src/stor/create.rs index b95020a8d2..6c8adceda5 100644 --- a/crates/nu-command/src/stor/create.rs +++ b/crates/nu-command/src/stor/create.rs @@ -81,33 +81,32 @@ fn process( if let Ok(conn) = db.open_connection() { match columns { Some(record) => { - let mut create_stmt = format!("CREATE TABLE {} ( ", new_table_name); + let mut create_stmt = format!("CREATE TABLE {new_table_name} ( "); for (column_name, column_datatype) in record { match column_datatype.coerce_str()?.as_ref() { "int" => { - create_stmt.push_str(&format!("{} INTEGER, ", column_name)); + create_stmt.push_str(&format!("{column_name} INTEGER, ")); } "float" => { - create_stmt.push_str(&format!("{} REAL, ", column_name)); + create_stmt.push_str(&format!("{column_name} REAL, ")); } "str" => { - create_stmt.push_str(&format!("{} VARCHAR(255), ", column_name)); + create_stmt.push_str(&format!("{column_name} VARCHAR(255), ")); } "bool" => { - create_stmt.push_str(&format!("{} BOOLEAN, ", column_name)); + create_stmt.push_str(&format!("{column_name} BOOLEAN, ")); } "datetime" => { create_stmt.push_str(&format!( - "{} DATETIME DEFAULT(STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), ", - column_name + "{column_name} DATETIME DEFAULT(STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), " )); } _ => { return Err(ShellError::UnsupportedInput { msg: "unsupported column data type".into(), - input: format!("{:?}", column_datatype), + input: format!("{column_datatype:?}"), msg_span: column_datatype.span(), input_span: column_datatype.span(), }); diff --git a/crates/nu-command/src/stor/delete.rs b/crates/nu-command/src/stor/delete.rs index eb0170e2ef..7ba1ebd82a 100644 --- a/crates/nu-command/src/stor/delete.rs +++ b/crates/nu-command/src/stor/delete.rs @@ -92,16 +92,16 @@ impl Command for StorDelete { let sql_stmt = match where_clause_opt { None => { // We're deleting an entire table - format!("DROP TABLE {}", new_table_name) + format!("DROP TABLE {new_table_name}") } Some(where_clause) => { // We're just deleting some rows - let mut delete_stmt = format!("DELETE FROM {} ", new_table_name); + let mut delete_stmt = format!("DELETE FROM {new_table_name} "); // Yup, this is a bit janky, but I'm not sure a better way to do this without having // --and and --or flags as well as supporting ==, !=, <>, is null, is not null, etc. // and other sql syntax. So, for now, just type a sql where clause as a string. - delete_stmt.push_str(&format!("WHERE {}", where_clause)); + delete_stmt.push_str(&format!("WHERE {where_clause}")); delete_stmt } }; diff --git a/crates/nu-command/src/stor/insert.rs b/crates/nu-command/src/stor/insert.rs index b1fbe3afea..8f5e01d31a 100644 --- a/crates/nu-command/src/stor/insert.rs +++ b/crates/nu-command/src/stor/insert.rs @@ -164,7 +164,7 @@ fn process( } let new_table_name = table_name.unwrap_or("table".into()); - let mut create_stmt = format!("INSERT INTO {} (", new_table_name); + let mut create_stmt = format!("INSERT INTO {new_table_name} ("); let mut column_placeholders: Vec = Vec::new(); let cols = record.columns(); diff --git a/crates/nu-command/src/stor/update.rs b/crates/nu-command/src/stor/update.rs index 13797a7993..23d988016e 100644 --- a/crates/nu-command/src/stor/update.rs +++ b/crates/nu-command/src/stor/update.rs @@ -164,7 +164,7 @@ fn process( } let new_table_name = table_name.unwrap_or("table".into()); if let Ok(conn) = db.open_connection() { - let mut update_stmt = format!("UPDATE {} ", new_table_name); + let mut update_stmt = format!("UPDATE {new_table_name} "); update_stmt.push_str("SET "); let mut placeholders: Vec = Vec::new(); diff --git a/crates/nu-command/src/strings/ansi/ansi_.rs b/crates/nu-command/src/strings/ansi/ansi_.rs index 7588de545a..be2415aa9d 100644 --- a/crates/nu-command/src/strings/ansi/ansi_.rs +++ b/crates/nu-command/src/strings/ansi/ansi_.rs @@ -936,8 +936,7 @@ mod tests { assert!( duplicates.is_empty(), - "Duplicate short_names found: {:?}", - duplicates + "Duplicate short_names found: {duplicates:?}" ); } @@ -958,8 +957,7 @@ mod tests { assert!( duplicates.is_empty(), - "Duplicate long_names found: {:?}", - duplicates + "Duplicate long_names found: {duplicates:?}" ); } } diff --git a/crates/nu-command/src/strings/format/duration.rs b/crates/nu-command/src/strings/format/duration.rs index 5d313a5025..7cacde934c 100644 --- a/crates/nu-command/src/strings/format/duration.rs +++ b/crates/nu-command/src/strings/format/duration.rs @@ -155,9 +155,9 @@ fn format_value_impl(val: &Value, arg: &Arguments, span: Span) -> Value { &arg.format_value.item }; if d.fract() == 0.0 { - Value::string(format!("{} {}", d, unit), inner_span) + Value::string(format!("{d} {unit}"), inner_span) } else { - Value::string(format!("{:.float_precision$} {}", d, unit), inner_span) + Value::string(format!("{d:.float_precision$} {unit}"), inner_span) } } Err(e) => Value::error(e, inner_span), diff --git a/crates/nu-command/src/strings/str_/join.rs b/crates/nu-command/src/strings/str_/join.rs index 0583d0ab0d..42948537c0 100644 --- a/crates/nu-command/src/strings/str_/join.rs +++ b/crates/nu-command/src/strings/str_/join.rs @@ -103,7 +103,7 @@ fn run( if first { first = false; } else if let Some(separator) = &separator { - write!(buffer, "{}", separator).map_err(&from_io_error)?; + write!(buffer, "{separator}").map_err(&from_io_error)?; } match value { diff --git a/crates/nu-command/src/strings/str_/substring.rs b/crates/nu-command/src/strings/str_/substring.rs index d2467d6900..29195346fb 100644 --- a/crates/nu-command/src/strings/str_/substring.rs +++ b/crates/nu-command/src/strings/str_/substring.rs @@ -292,7 +292,7 @@ mod tests { ]; for expectation in &cases { - println!("{:?}", expectation); + println!("{expectation:?}"); let expected = expectation.expected; let actual = action( &word, diff --git a/crates/nu-command/src/system/nu_check.rs b/crates/nu-command/src/system/nu_check.rs index cf9e6cf121..c380d21b3f 100644 --- a/crates/nu-command/src/system/nu_check.rs +++ b/crates/nu-command/src/system/nu_check.rs @@ -106,7 +106,7 @@ impl Command for NuCheck { Err(err) => return Err(err), }; - let result = if as_module || path.is_dir() { + if as_module || path.is_dir() { parse_file_or_dir_module( path.to_string_lossy().as_bytes(), &mut working_set, @@ -120,9 +120,7 @@ impl Command for NuCheck { working_set.files = FileStack::with_file(path.clone()); parse_file_script(&path, &mut working_set, is_debug, path_span, call.head) // The working set is not merged, so no need to pop the file from the stack. - }; - - result + } } else { Err(ShellError::GenericError { error: "Failed to execute command".into(), diff --git a/crates/nu-command/src/system/uname.rs b/crates/nu-command/src/system/uname.rs index 30d36cc12e..7e74e81925 100644 --- a/crates/nu-command/src/system/uname.rs +++ b/crates/nu-command/src/system/uname.rs @@ -45,8 +45,8 @@ impl Command for UName { os: false, }; let output = uu_uname::UNameOutput::new(&opts).map_err(|e| ShellError::GenericError { - error: format!("{}", e), - msg: format!("{}", e), + error: format!("{e}"), + msg: format!("{e}"), span: None, help: None, inner: Vec::new(), diff --git a/crates/nu-command/src/viewers/table.rs b/crates/nu-command/src/viewers/table.rs index 003cc986ae..4cd0bbfda6 100644 --- a/crates/nu-command/src/viewers/table.rs +++ b/crates/nu-command/src/viewers/table.rs @@ -379,7 +379,7 @@ fn get_theme_flag( to_type: String::from("theme"), from_type: String::from("string"), span: call.span(), - help: Some(format!("{}, but found '{}'.", err, theme)), + help: Some(format!("{err}, but found '{theme}'.")), }) }) .transpose() @@ -1117,7 +1117,7 @@ fn create_empty_placeholder( return String::new(); } - let cell = format!("empty {}", value_type_name); + let cell = format!("empty {value_type_name}"); let mut table = NuTable::new(1, 1); table.insert((0, 0), cell); table.set_data_style(TextStyle::default().dimmed()); @@ -1156,7 +1156,7 @@ fn convert_table_to_output( } else { // assume this failed because the table was too wide // TODO: more robust error classification - format!("Couldn't fit table into {} columns!", term_width) + format!("Couldn't fit table into {term_width} columns!") }; Some(Ok(msg.as_bytes().to_vec())) diff --git a/crates/nu-command/tests/commands/glob.rs b/crates/nu-command/tests/commands/glob.rs index bded39d09f..2ba4471c41 100644 --- a/crates/nu-command/tests/commands/glob.rs +++ b/crates/nu-command/tests/commands/glob.rs @@ -170,7 +170,7 @@ fn glob_files_in_parent( let expected = expected .join(" ") .replace('/', std::path::MAIN_SEPARATOR_STR); - assert_eq!(actual.out, expected, "\n test: {}", tag); + assert_eq!(actual.out, expected, "\n test: {tag}"); }); } diff --git a/crates/nu-command/tests/commands/into_int.rs b/crates/nu-command/tests/commands/into_int.rs index 4ad8750242..361660d714 100644 --- a/crates/nu-command/tests/commands/into_int.rs +++ b/crates/nu-command/tests/commands/into_int.rs @@ -70,7 +70,7 @@ fn into_int_binary_signed_empty() { #[ignore] fn into_int_datetime1() { let dt = DateTime::parse_from_rfc3339("1983-04-13T12:09:14.123456789+00:00"); - eprintln!("dt debug {:?}", dt); + eprintln!("dt debug {dt:?}"); assert_eq!( dt, Ok(FixedOffset::east_opt(0) diff --git a/crates/nu-command/tests/commands/join.rs b/crates/nu-command/tests/commands/join.rs index 5b1ce8b0fd..8e281dcea0 100644 --- a/crates/nu-command/tests/commands/join.rs +++ b/crates/nu-command/tests/commands/join.rs @@ -83,16 +83,13 @@ fn do_cases_where_result_is_same_between_join_types(join_type: &str) { ), (("[{a: 1}]", "[{a: 1 b: 1}]", "a"), "[[a, b]; [1, 1]]"), ] { - let expr = format!("{} | join {} {} {} | to nuon", left, right, join_type, on); + let expr = format!("{left} | join {right} {join_type} {on} | to nuon"); let actual = nu!(expr).out; assert_eq!(actual, expected); // Test again with streaming input (using `each` to convert the input into a ListStream) let to_list_stream = "each { |i| $i } | "; - let expr = format!( - "{} | {} join {} {} {} | to nuon", - left, to_list_stream, right, join_type, on - ); + let expr = format!("{left} | {to_list_stream} join {right} {join_type} {on} | to nuon"); let actual = nu!(expr).out; assert_eq!(actual, expected); } @@ -244,16 +241,14 @@ fn do_cases_where_result_differs_between_join_types(join_type: &str) { ] { for (join_type_, expected) in join_types { if join_type_ == join_type { - let expr = format!("{} | join {} {} {} | to nuon", left, right, join_type, on); + let expr = format!("{left} | join {right} {join_type} {on} | to nuon"); let actual = nu!(expr).out; assert_eq!(actual, expected); // Test again with streaming input (using `each` to convert the input into a ListStream) let to_list_stream = "each { |i| $i } | "; - let expr = format!( - "{} | {} join {} {} {} | to nuon", - left, to_list_stream, right, join_type, on - ); + let expr = + format!("{left} | {to_list_stream} join {right} {join_type} {on} | to nuon"); let actual = nu!(expr).out; assert_eq!(actual, expected); } @@ -384,18 +379,15 @@ fn do_cases_where_result_differs_between_join_types_with_different_join_keys(joi ] { for (join_type_, expected) in join_types { if join_type_ == join_type { - let expr = format!( - "{} | join {} {} {} {} | to nuon", - left, right, join_type, left_on, right_on - ); + let expr = + format!("{left} | join {right} {join_type} {left_on} {right_on} | to nuon"); let actual = nu!(expr).out; assert_eq!(actual, expected); // Test again with streaming input (using `each` to convert the input into a ListStream) let to_list_stream = "each { |i| $i } | "; let expr = format!( - "{} | {} join {} {} {} {} | to nuon", - left, to_list_stream, right, join_type, left_on, right_on + "{left} | {to_list_stream} join {right} {join_type} {left_on} {right_on} | to nuon" ); let actual = nu!(expr).out; assert_eq!(actual, expected); @@ -413,7 +405,7 @@ fn test_alternative_table_syntax() { (("[[a]; [1]]", "[{a: 1}]", "a"), "[[a]; [1]]"), (("[[a]; [1]]", "[[a]; [1]]", "a"), "[[a]; [1]]"), ] { - let expr = format!("{} | join {} {} {} | to nuon", left, right, join_type, on); + let expr = format!("{left} | join {right} {join_type} {on} | to nuon"); let actual = nu!(&expr).out; assert_eq!(actual, expected, "Expression was {}", &expr); } diff --git a/crates/nu-command/tests/commands/mktemp.rs b/crates/nu-command/tests/commands/mktemp.rs index 30de3beb33..026b5ec64b 100644 --- a/crates/nu-command/tests/commands/mktemp.rs +++ b/crates/nu-command/tests/commands/mktemp.rs @@ -10,7 +10,7 @@ fn creates_temp_file() { "mktemp" ); let loc = AbsolutePath::try_new(&output.out).unwrap(); - println!("{:?}", loc); + println!("{loc:?}"); assert!(loc.exists()); }) } diff --git a/crates/nu-command/tests/commands/table.rs b/crates/nu-command/tests/commands/table.rs index 120829e511..a39500bf88 100644 --- a/crates/nu-command/tests/commands/table.rs +++ b/crates/nu-command/tests/commands/table.rs @@ -3698,11 +3698,10 @@ fn table_footer_inheritance() { field0: [ [ y1, y2, y3 ]; [ 1 2 3 ] [ 79 79 79 ] [ {{ f1: 'a string', f2: 1000 }}, 1, 2 ] ],\ field1: [ a, b, c ],\ field2: [ 123, 234, 345 ],\ - field3: {},\ + field3: {table1},\ field4: {{ f1: 1, f2: 3, f3: {{ f1: f1, f2: f2, f3: f3 }} }},\ field5: [ [ x1, x2, x3 ]; [ 1 2 3 ] [ 79 79 79 ] [ {{ f1: 'a string', f2: 1000 }}, 1, 2 ] ],\ - }}", - table1 + }}" ); let actual = nu!(format!( "$env.config.table.footer_inheritance = true; {structure} | table --width=80 --expand" diff --git a/crates/nu-command/tests/commands/transpose.rs b/crates/nu-command/tests/commands/transpose.rs index c4448fdaf6..ffeb1c7ded 100644 --- a/crates/nu-command/tests/commands/transpose.rs +++ b/crates/nu-command/tests/commands/transpose.rs @@ -24,7 +24,7 @@ fn row_but_all() { #[test] fn throw_inner_error() { let error_msg = "This message should show up"; - let error = format!("(error make {{ msg: \"{}\" }})", error_msg); + let error = format!("(error make {{ msg: \"{error_msg}\" }})"); let actual = nu!(format!( "[[key value]; [foo 1] [foo 2] [{} 3]] | transpose", error diff --git a/crates/nu-command/tests/commands/utouch.rs b/crates/nu-command/tests/commands/utouch.rs index 9bbe7b796c..3835c4ef7d 100644 --- a/crates/nu-command/tests/commands/utouch.rs +++ b/crates/nu-command/tests/commands/utouch.rs @@ -540,10 +540,7 @@ fn change_file_times_to_date() { assert!( got_atime.signed_duration_since(expected).lt(&threshold) && got_mtime.signed_duration_since(expected).lt(&threshold), - "Expected: {}. Got: atime={}, mtime={}", - expected, - got_atime, - got_mtime + "Expected: {expected}. Got: atime={got_atime}, mtime={got_mtime}" ); assert!(got_mtime.signed_duration_since(expected).lt(&threshold)); }) diff --git a/crates/nu-command/tests/format_conversions/msgpack.rs b/crates/nu-command/tests/format_conversions/msgpack.rs index 578e96efd5..a18d1f382d 100644 --- a/crates/nu-command/tests/format_conversions/msgpack.rs +++ b/crates/nu-command/tests/format_conversions/msgpack.rs @@ -8,7 +8,7 @@ fn msgpack_test(fixture_name: &str, commands: Option<&str>) -> nu_test_support:: .join("generate.nu"); let mut outcome = None; - Playground::setup(&format!("msgpack test {}", fixture_name), |dirs, _| { + Playground::setup(&format!("msgpack test {fixture_name}"), |dirs, _| { assert!( nu!( cwd: dirs.test(), diff --git a/crates/nu-derive-value/src/tests.rs b/crates/nu-derive-value/src/tests.rs index 87a4b7c24b..e6197d1e4c 100644 --- a/crates/nu-derive-value/src/tests.rs +++ b/crates/nu-derive-value/src/tests.rs @@ -19,15 +19,13 @@ fn unsupported_unions() { let from_res = derive_from_value(input.clone()); assert!( matches!(from_res, Err(DeriveError::UnsupportedUnions)), - "expected `DeriveError::UnsupportedUnions`, got {:?}", - from_res + "expected `DeriveError::UnsupportedUnions`, got {from_res:?}" ); let into_res = derive_into_value(input); assert!( matches!(into_res, Err(DeriveError::UnsupportedUnions)), - "expected `DeriveError::UnsupportedUnions`, got {:?}", - into_res + "expected `DeriveError::UnsupportedUnions`, got {into_res:?}" ); } @@ -48,15 +46,13 @@ fn unsupported_enums() { let from_res = derive_from_value(input.clone()); assert!( matches!(from_res, Err(DeriveError::UnsupportedEnums { .. })), - "expected `DeriveError::UnsupportedEnums`, got {:?}", - from_res + "expected `DeriveError::UnsupportedEnums`, got {from_res:?}" ); let into_res = derive_into_value(input); assert!( matches!(into_res, Err(DeriveError::UnsupportedEnums { .. })), - "expected `DeriveError::UnsupportedEnums`, got {:?}", - into_res + "expected `DeriveError::UnsupportedEnums`, got {into_res:?}" ); } @@ -73,15 +69,13 @@ fn unexpected_attribute() { let from_res = derive_from_value(input.clone()); assert!( matches!(from_res, Err(DeriveError::UnexpectedAttribute { .. })), - "expected `DeriveError::UnexpectedAttribute`, got {:?}", - from_res + "expected `DeriveError::UnexpectedAttribute`, got {from_res:?}" ); let into_res = derive_into_value(input); assert!( matches!(into_res, Err(DeriveError::UnexpectedAttribute { .. })), - "expected `DeriveError::UnexpectedAttribute`, got {:?}", - into_res + "expected `DeriveError::UnexpectedAttribute`, got {into_res:?}" ); } @@ -98,15 +92,13 @@ fn unexpected_attribute_on_struct_field() { let from_res = derive_from_value(input.clone()); assert!( matches!(from_res, Err(DeriveError::UnexpectedAttribute { .. })), - "expected `DeriveError::UnexpectedAttribute`, got {:?}", - from_res + "expected `DeriveError::UnexpectedAttribute`, got {from_res:?}" ); let into_res = derive_into_value(input); assert!( matches!(into_res, Err(DeriveError::UnexpectedAttribute { .. })), - "expected `DeriveError::UnexpectedAttribute`, got {:?}", - into_res + "expected `DeriveError::UnexpectedAttribute`, got {into_res:?}" ); } @@ -123,15 +115,13 @@ fn unexpected_attribute_on_enum_variant() { let from_res = derive_from_value(input.clone()); assert!( matches!(from_res, Err(DeriveError::UnexpectedAttribute { .. })), - "expected `DeriveError::UnexpectedAttribute`, got {:?}", - from_res + "expected `DeriveError::UnexpectedAttribute`, got {from_res:?}" ); let into_res = derive_into_value(input); assert!( matches!(into_res, Err(DeriveError::UnexpectedAttribute { .. })), - "expected `DeriveError::UnexpectedAttribute`, got {:?}", - into_res + "expected `DeriveError::UnexpectedAttribute`, got {into_res:?}" ); } @@ -151,8 +141,7 @@ fn invalid_attribute_position_in_tuple_struct() { from_res, Err(DeriveError::InvalidAttributePosition { attribute_span: _ }) ), - "expected `DeriveError::InvalidAttributePosition`, got {:?}", - from_res + "expected `DeriveError::InvalidAttributePosition`, got {from_res:?}" ); let into_res = derive_into_value(input); @@ -161,8 +150,7 @@ fn invalid_attribute_position_in_tuple_struct() { into_res, Err(DeriveError::InvalidAttributePosition { attribute_span: _ }) ), - "expected `DeriveError::InvalidAttributePosition`, got {:?}", - into_res + "expected `DeriveError::InvalidAttributePosition`, got {into_res:?}" ); } @@ -179,15 +167,13 @@ fn invalid_attribute_value() { let from_res = derive_from_value(input.clone()); assert!( matches!(from_res, Err(DeriveError::InvalidAttributeValue { .. })), - "expected `DeriveError::InvalidAttributeValue`, got {:?}", - from_res + "expected `DeriveError::InvalidAttributeValue`, got {from_res:?}" ); let into_res = derive_into_value(input); assert!( matches!(into_res, Err(DeriveError::InvalidAttributeValue { .. })), - "expected `DeriveError::InvalidAttributeValue`, got {:?}", - into_res + "expected `DeriveError::InvalidAttributeValue`, got {into_res:?}" ); } @@ -204,15 +190,13 @@ fn non_unique_struct_keys() { let from_res = derive_from_value(input.clone()); assert!( matches!(from_res, Err(DeriveError::NonUniqueName { .. })), - "expected `DeriveError::NonUniqueName`, got {:?}", - from_res + "expected `DeriveError::NonUniqueName`, got {from_res:?}" ); let into_res = derive_into_value(input); assert!( matches!(into_res, Err(DeriveError::NonUniqueName { .. })), - "expected `DeriveError::NonUniqueName`, got {:?}", - into_res + "expected `DeriveError::NonUniqueName`, got {into_res:?}" ); } @@ -229,14 +213,12 @@ fn non_unique_enum_variants() { let from_res = derive_from_value(input.clone()); assert!( matches!(from_res, Err(DeriveError::NonUniqueName { .. })), - "expected `DeriveError::NonUniqueName`, got {:?}", - from_res + "expected `DeriveError::NonUniqueName`, got {from_res:?}" ); let into_res = derive_into_value(input); assert!( matches!(into_res, Err(DeriveError::NonUniqueName { .. })), - "expected `DeriveError::NonUniqueName`, got {:?}", - into_res + "expected `DeriveError::NonUniqueName`, got {into_res:?}" ); } diff --git a/crates/nu-engine/src/compile/builder.rs b/crates/nu-engine/src/compile/builder.rs index 4d9117f4da..0526954ed2 100644 --- a/crates/nu-engine/src/compile/builder.rs +++ b/crates/nu-engine/src/compile/builder.rs @@ -556,7 +556,7 @@ impl BlockBuilder { ); instruction.set_branch_target(target_index).map_err(|_| { CompileError::SetBranchTargetOfNonBranchInstruction { - instruction: format!("{:?}", instruction), + instruction: format!("{instruction:?}"), span: *span, } })?; diff --git a/crates/nu-engine/src/documentation.rs b/crates/nu-engine/src/documentation.rs index 0198df210e..a1cd3942b9 100644 --- a/crates/nu-engine/src/documentation.rs +++ b/crates/nu-engine/src/documentation.rs @@ -754,7 +754,7 @@ where long_desc.push_str(" "); // Short flag shown before long flag if let Some(short) = flag.short { - let _ = write!(long_desc, "{help_subcolor_one}-{}{RESET}", short); + let _ = write!(long_desc, "{help_subcolor_one}-{short}{RESET}"); if !flag.long.is_empty() { let _ = write!(long_desc, "{DEFAULT_COLOR},{RESET} "); } diff --git a/crates/nu-engine/src/exit.rs b/crates/nu-engine/src/exit.rs index 396b3eff4b..1a6036f95e 100644 --- a/crates/nu-engine/src/exit.rs +++ b/crates/nu-engine/src/exit.rs @@ -18,7 +18,7 @@ pub fn cleanup_exit(tag: T, engine_state: &EngineState, exit_code: i32) -> T { let job_count = jobs.iter().count(); - println!("There are still background jobs running ({}).", job_count); + println!("There are still background jobs running ({job_count})."); println!("Running `exit` a second time will kill all of them."); diff --git a/crates/nu-explore/src/nu_common/lscolor.rs b/crates/nu-explore/src/nu_common/lscolor.rs index 7a3400dae0..95a9aab8c4 100644 --- a/crates/nu-explore/src/nu_common/lscolor.rs +++ b/crates/nu-explore/src/nu_common/lscolor.rs @@ -46,7 +46,7 @@ fn get_path_style(path: &str, cwd: &str, ls_colors: &LsColors) -> Option