Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unnecessary boolean 'not' operation found by clippy pedantic #4534

Closed
sylvestre opened this issue Mar 18, 2023 · 4 comments
Closed

Fix unnecessary boolean 'not' operation found by clippy pedantic #4534

sylvestre opened this issue Mar 18, 2023 · 4 comments
Labels
good first issue For newcomers!

Comments

@sylvestre
Copy link
Contributor

Example:

warning: unnecessary boolean `not` operation
   --> tests/by-util/test_du.rs:306:5
    |
306 | /     if !uucore::os::is_wsl_1() {
307 | |         assert_eq!(s, "8\tsubdir/links/deeper_dir\n24\tsubdir/links\n");
308 | |     } else {
309 | |         assert_eq!(s, "0\tsubdir/links/deeper_dir\n8\tsubdir/links\n");
310 | |     }
    | |_____^
    |
    = help: remove the `!` and swap the blocks of the `if`/`else`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_not_else

Found with:
cargo +nightly clippy --features unix --allow-dirty -- -W clippy::pedantic

@sylvestre sylvestre added the good first issue For newcomers! label Mar 18, 2023
@papparapa
Copy link
Contributor

Maybe cargo +nightly clippy --features unix -- -A clippy::pedantic -W clippy::if_not_else is useful to pick up this specific type of warning.

@sylvestre
Copy link
Contributor Author

Two more occurrences:

warning: unnecessary boolean `not` operation
    --> tests/common/util.rs:2508:5
     |
2508 | /     if !is_ci() {
2509 | |         // check if we can run 'sudo'
2510 | |         log_info("run", "sudo -E --non-interactive whoami");
2511 | |         match Command::new("sudo")
...    |
2539 | |         Err(format!("{UUTILS_INFO}: {}", "cannot run inside CI"))
2540 | |     }
     | |_____^
     |
     = help: remove the `!` and swap the blocks of the `if`/`else`
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_not_else
     = note: `-W clippy::if-not-else` implied by `-W clippy::pedantic`

warning: unnecessary boolean `not` operation
    --> tests/common/util.rs:2993:9
     |
2993 | /         if !is_ci() {
2994 | |             // Skip test if we can't guarantee non-interactive `sudo`, or if we're not "root"
2995 | |             if let Ok(output) = Command::new("sudo")
2996 | |                 .env("LC_ALL", "C")
...    |
3013 | |             println!("TEST SKIPPED (cannot run inside CI)");
3014 | |         }
     | |_________^
     |
     = help: remove the `!` and swap the blocks of the `if`/`else`
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_not_else

@sylvestre
Copy link
Contributor Author

There is way more :)


   --> src/uucore/src/lib/mods/quoting_style.rs:262:13
    |
262 | /             if !show_control {
263 | |                 name.to_string_lossy()
264 | |                     .chars()
265 | |                     .flat_map(|c| EscapedChar::new_literal(c).hide_control())
...   |
268 | |                 name.to_string_lossy().into_owned()
269 | |             }
    | |_____________^

@cakebaker
Copy link
Contributor

Fixed in #4647

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue For newcomers!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants