Skip to content

let_underscore_untyped in the case of unnameable types #10411

@dtolnay

Description

@dtolnay

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

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions