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

FP equatable_if_let: no longer able to infer type #9888

Open
matthiaskrgr opened this issue Nov 19, 2022 · 0 comments
Open

FP equatable_if_let: no longer able to infer type #9888

matthiaskrgr opened this issue Nov 19, 2022 · 0 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-nursery Lint: Currently in the nursery group

Comments

@matthiaskrgr
Copy link
Member

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

@matthiaskrgr matthiaskrgr added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied labels Nov 19, 2022
@J-ZhengLi J-ZhengLi added the L-nursery Lint: Currently in the nursery group label Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-nursery Lint: Currently in the nursery group
Projects
None yet
Development

No branches or pull requests

2 participants