Skip to content

New lint against let $pat: _ = $expr; #10463

Closed
@dtolnay

Description

@dtolnay

What it does

Generalizing from #10441 -- a new lint for this would supersede that issue, which was originally reported as a false negative against the existing let_underscore_untyped lint.

In this GitHub search (not sure how stable the URL is -- it's a search for /let [a-zA-Z0-9_]+: _ =( |$)/ language:rust) I noticed a surprisingly large amount of code doing:

let pattern: _ = expression;

There are 610 search results. From skimming about a dozen of them, I couldn't identify any reason that the code would need to be written in this way. It is universally equivalent to:

let pattern = expression;

and it would be helpful for Clippy to guide newbies in this preferred direction.

Lint Name

let_with_type_underscore

Category

complexity

Advantage

Reduced line noise. : _ provides zero clarity or utility.

Drawbacks

No response

Example

fn main() {
    let v: _ = 1;
    println!("{v}");
}

Could be written as:

fn main() {
    let v = 1;
    println!("{v}");
}

Metadata

Metadata

Assignees

Labels

A-lintArea: New lints

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions