rust-clippy
rust-clippy copied to clipboard
FP equatable_if_let: no longer able to infer type
Summary
.
Lint Name
equatable_if_let
Reproducer
I tried this code:
#![warn(clippy::redundant_else)]
#![allow(clippy::needless_return, clippy::if_same_then_else, clippy::needless_late_init)]
fn main() {
// inside if let
let _ = if let Some(1) = foo() {
let _ = 1;
if foo() {
return;
} else {
1
}
} else {
1
};
}
fn foo<T>() -> T {
unimplemented!("I'm not Santa Claus")
}
I saw this happen:
cargo clippy --fix -- -Wclippy::equatable_if_let
warning: failed to automatically apply fixes suggested by rustc to crate `a`
after fixes were automatically applied the compiler reported errors within these files:
* src/main.rs
This 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:
warning: redundant else block
--> src/main.rs:11:16
|
11 | } else {
| ________________^
12 | | 1
13 | | }
| |_________^
|
= help: remove the `else` block and move the contents out
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_else
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![warn(clippy::redundant_else)]
| ^^^^^^^^^^^^^^^^^^^^^^
error[E0282]: type annotations needed
--> src/main.rs:7:16
|
7 | let _ = if foo() == Some(1) {
| ^^^ cannot infer type of the type parameter `T` declared on the function `foo`
|
help: consider specifying the generic argument
|
7 | let _ = if foo::<T>() == Some(1) {
| +++++
error: aborting due to previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0282`.
Original diagnostics will follow.
warning: redundant else block
--> src/main.rs:11:16
|
11 | } else {
| ________________^
12 | | 1
13 | | }
| |_________^
|
= help: remove the `else` block and move the contents out
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_else
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![warn(clippy::redundant_else)]
| ^^^^^^^^^^^^^^^^^^^^^^
warning: this pattern matching can be expressed using equality
--> src/main.rs:7:16
|
7 | let _ = if let Some(1) = foo() {
| ^^^^^^^^^^^^^^^^^^^ help: try: `foo() == Some(1)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#equatable_if_let
= note: requested on the command line with `-W clippy::equatable-if-let`
warning: `a` (bin "a") generated 2 warnings (run `cargo fix --bin "a"` to apply 1 suggestion)
Version
rustc 1.67.0-nightly (b833ad56f 2022-11-18)
binary: rustc
commit-hash: b833ad56f46a0bbe0e8729512812a161e7dae28a
commit-date: 2022-11-18
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4
Additional Labels
No response