You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fnmain(){let a = [1,2,3];(a.len() > 0).then(|| println!("Hello, world!"));}
running cargo clippy on this produces the following warning:
warning: length comparison to zero
--> src/main.rs:3:5
|
3 | (a.len() > 0).then(|| println!("Hello, world!"));
| ^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!a.is_empty()`
|
= help:for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_zero
= note: `#[warn(clippy::len_zero)]` on by default
which makes sense to me.
I expected to see this happen: running 'cargo clippy --fix' changes the condition to the one suggested
Instead, this happened:
cargo clippy --fix
Checking minimal_example v0.1.0(/home/ingo/minimal_example)
warning: failed to automatically apply fixes suggested by rustc to crate `minimal_example`
after fixes were automatically applied the compiler reported errors within these files:* src/main.rsThis likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed.If you could open an issue at
https://github.com/rust-lang/rust/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag
The following errors were reported:
error[E0600]: cannot apply unary operator `!` to type `std::option::Option<()>`
--> src/main.rs:3:5
|
3 | !a.is_empty().then(|| println!("Hello, world!"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot apply unary operator `!`
error:aborting due to previous error
Reinserting parens around the condition makes it compile.
fnmain(){let a = [1,2,3];(!a.is_empty()).then(|| println!("Hello, world!"));}
ingomancer
changed the title
clippy --fix removes necessary parens when changing 'len > 0' to '.is_empty()'
clippy --fix removes necessary parens when changing 'len > 0' to '!.is_empty()'
Mar 21, 2023
I have the following minimized example:
running cargo clippy on this produces the following warning:
which makes sense to me.
I expected to see this happen: running 'cargo clippy --fix' changes the condition to the one suggested
Instead, this happened:
Reinserting parens around the condition makes it compile.
Meta
rustc --version --verbose
:I get the same result on nightly, which is currently:
'rustc +nightly --version --verbose':
Regards,
ingo
Backtrace
The text was updated successfully, but these errors were encountered: