From 69bf43ef56cbc938bbacd38e565bbad0c5d7f1cf Mon Sep 17 00:00:00 2001 From: nibon7 Date: Tue, 20 Jun 2023 16:17:33 +0800 Subject: [PATCH] Apply nightly clippy fixes (#9482) # Description This PR fixes the following nightly clippy warnings. ``` warning: you should consider adding a `Default` implementation for `HjsonFormatter<'a>` --> crates/nu-json/src/ser.rs:700:5 | 700 | / pub fn new() -> Self { 701 | | HjsonFormatter::with_indent(b" ") 702 | | } | |_____^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default = note: `#[warn(clippy::new_without_default)]` on by default help: try adding this | 698 + impl<'a> Default for HjsonFormatter<'a> { 699 + fn default() -> Self { 700 + Self::new() 701 + } 702 + } | warning: `nu-json` (lib) generated 1 warning warning: private item shadows public glob re-export --> crates/nu-command/src/strings/mod.rs:8:1 | 8 | mod str_; | ^^^^^^^^^ | note: the name `str_` in the type namespace is supposed to be publicly re-exported here --> crates/nu-command/src/strings/mod.rs:17:9 | 17 | pub use str_::*; | ^^^^^^^ note: but the private item here shadows it --> crates/nu-command/src/strings/mod.rs:8:1 | 8 | mod str_; | ^^^^^^^^^ = note: `#[warn(hidden_glob_reexports)]` on by default warning: incorrect NaN comparison, NaN cannot be directly compared to itself --> crates/nu-command/src/formats/to/nuon.rs:186:20 | 186 | && val != &f64::NAN | ^^^^^^^^^^^^^^^^ | = note: `#[warn(invalid_nan_comparisons)]` on by default help: use `f32::is_nan()` or `f64::is_nan()` instead | 186 - && val != &f64::NAN 186 + && !val.is_nan() | warning: `nu-command` (lib) generated 2 warnings (run `cargo clippy --fix --lib -p nu-command` to apply 1 suggestion) Compiling nu v0.81.1 (/data/source/nushell) warning: this expression creates a reference which is immediately dereferenced by the compiler --> crates/nu-command/tests/commands/rm.rs:392:27 | 392 | dir_to_clean: &test_dir, | ^^^^^^^^^ help: change this to: `test_dir` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default warning: `nu-command` (test "main") generated 1 warning (run `cargo clippy --fix --test "main"` to apply 1 suggestion) warning: `nu-command` (lib test) generated 2 warnings (2 duplicates) warning: `nu-json` (lib test) generated 1 warning (1 duplicate) Finished dev [unoptimized + debuginfo] target(s) in 3.89s ``` # User-Facing Changes N/A # Tests + Formatting # After Submitting --- crates/nu-command/src/formats/to/nuon.rs | 6 +----- .../nu-command/src/strings/str_/case/mod.rs | 20 +++++++++---------- crates/nu-command/tests/commands/rm.rs | 2 +- crates/nu-json/src/ser.rs | 6 ++++++ 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/crates/nu-command/src/formats/to/nuon.rs b/crates/nu-command/src/formats/to/nuon.rs index c712fa132..4eaf4dfe3 100644 --- a/crates/nu-command/src/formats/to/nuon.rs +++ b/crates/nu-command/src/formats/to/nuon.rs @@ -182,11 +182,7 @@ pub fn value_to_string( Value::Filesize { val, .. } => Ok(format!("{}b", *val)), Value::Float { val, .. } => { // This serialises these as 'nan', 'inf' and '-inf', respectively. - if &val.round() == val - && val != &f64::NAN - && val != &f64::INFINITY - && val != &f64::NEG_INFINITY - { + if &val.round() == val && val.is_finite() { Ok(format!("{}.0", *val)) } else { Ok(format!("{}", *val)) diff --git a/crates/nu-command/src/strings/str_/case/mod.rs b/crates/nu-command/src/strings/str_/case/mod.rs index 1f76caf03..321ef66e4 100644 --- a/crates/nu-command/src/strings/str_/case/mod.rs +++ b/crates/nu-command/src/strings/str_/case/mod.rs @@ -1,13 +1,13 @@ -pub mod camel_case; -pub mod capitalize; -pub mod downcase; -pub mod kebab_case; -pub mod pascal_case; -pub mod screaming_snake_case; -pub mod snake_case; -pub mod str_; -pub mod title_case; -pub mod upcase; +mod camel_case; +mod capitalize; +mod downcase; +mod kebab_case; +mod pascal_case; +mod screaming_snake_case; +mod snake_case; +mod str_; +mod title_case; +mod upcase; pub use camel_case::SubCommand as StrCamelCase; pub use capitalize::SubCommand as StrCapitalize; diff --git a/crates/nu-command/tests/commands/rm.rs b/crates/nu-command/tests/commands/rm.rs index f02613086..f0aced78c 100644 --- a/crates/nu-command/tests/commands/rm.rs +++ b/crates/nu-command/tests/commands/rm.rs @@ -389,7 +389,7 @@ fn rm_prints_filenames_on_error() { set_dir_read_only(test_dir, true); let _cleanup = Cleanup { - dir_to_clean: &test_dir, + dir_to_clean: test_dir, }; // This rm is expected to fail, and stderr output indicating so is also expected. diff --git a/crates/nu-json/src/ser.rs b/crates/nu-json/src/ser.rs index ba644eb46..246a5db20 100644 --- a/crates/nu-json/src/ser.rs +++ b/crates/nu-json/src/ser.rs @@ -695,6 +695,12 @@ struct HjsonFormatter<'a> { braces_same_line: bool, } +impl<'a> Default for HjsonFormatter<'a> { + fn default() -> Self { + Self::new() + } +} + impl<'a> HjsonFormatter<'a> { /// Construct a formatter that defaults to using two spaces for indentation. pub fn new() -> Self {