Skip to content

let_underscore_untyped in the case of unnameable types #10411

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

Closed
dtolnay opened this issue Feb 27, 2023 · 3 comments · Fixed by #10701
Closed

let_underscore_untyped in the case of unnameable types #10411

dtolnay opened this issue Feb 27, 2023 · 3 comments · Fixed by #10701
Assignees
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

Comments

@dtolnay
Copy link
Member

dtolnay commented Feb 27, 2023

Summary

Clippy recommends that the programmer fill in a type annotation even when there isn't a type annotation that the programmer could fill in.

Lint Name

let_underscore_untyped

Reproducer

#![deny(clippy::pedantic)]

fn f() -> impl Fn() {
    || {}
}

fn main() {
    let _ = f();
}
error: non-binding `let` without a type annotation
 --> src/main.rs:8:5
  |
8 |     let _ = f();
  |     ^^^^^^^^^^^^
  |
  = help: consider adding a type annotation or removing the `let` keyword
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_untyped

Clippy wants this written as let _: ??? = f(). However, there isn't really anything better the programmer could write here. (If there is, clippy should provide that guidance.)

let _: impl Fn() = ... does not work.

error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in variable bindings
 --> src/main.rs:8:12
  |
8 |     let _: impl Fn() = f();
  |            ^^^^^^^^^

Version

rustc 1.69.0-nightly (d962ea578 2023-02-26)
binary: rustc
commit-hash: d962ea57899d64dc8a57040142c6b498a57c8064
commit-date: 2023-02-26
host: aarch64-unknown-linux-gnu
release: 1.69.0-nightly
LLVM version: 15.0.7

Additional Labels

No response

@dtolnay dtolnay 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 labels Feb 27, 2023
@dtolnay
Copy link
Member Author

dtolnay commented Feb 27, 2023

Mentioning @JirkaVebr @llogiq since this lint is from #10356.

@blyxyas
Copy link
Member

blyxyas commented Apr 23, 2023

@rustbot claim

@blyxyas
Copy link
Member

blyxyas commented Apr 23, 2023

Turns out this happens for any impl Trait, not only impl Fn()

fn a() -> impl Trait {
    // [...]
}

fn main() {
    let _ = a();
}

Would have the same problem.

@bors bors closed this as completed in 4195522 Apr 23, 2023
nyurik added a commit to nyurik/cxx that referenced this issue May 27, 2023
Clippy keeps complaining about
  https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_untyped

Seems like a noop, esp considering that @dtolnay has filed a bug in
  rust-lang/rust-clippy#10411

One issue though is that MSRV in .clippy.toml is not matching the one in Cargo.toml:
* .clippy.toml:  msrv = "1.48.0"
* Cargo.toml: rust-version = "1.60"

Which one is the accurate one?  I would assume its the Cargo.toml, in
which case it might be better to apply this change?
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants