Skip to content

Fix let underscore place expr - #164994

Closed
yashaggarwal85d wants to merge 5 commits into
rust-lang:mainfrom
yashaggarwal85d:fix-let-underscore-place-expr
Closed

yashaggarwal85d wants to merge 5 commits into
rust-lang:mainfrom
yashaggarwal85d:fix-let-underscore-place-expr

Conversation

@yashaggarwal85d

@yashaggarwal85d yashaggarwal85d commented Oct 26, 2026 •

Copy link
Copy Markdown

let _ = y; where y is a local guard doesn't move or drop y, but
let_underscore_lock (deny by default) says the lock is released immediately and suggests
drop(y), which would change behaviour. Same for let_underscore_drop.

This skips the lint when the let initializer is a place expression. Temporaries still lint,
including fields of temporaries like (m.lock(), 1).0.

Fixes #164746
cc @theemathas @traviscross

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 26, 2026
@rustbot

rustbot commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

r? @mu001999

rustbot has assigned @mu001999.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 77 candidates
  • Random selection from 19 candidates

@mu001999 mu001999 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread compiler/rustc_lint/src/let_underscore.rs Outdated
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 27, 2026
@rustbot

rustbot commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@yashaggarwal85d

This comment was marked as low quality.

@yashaggarwal85d

This comment was marked as low quality.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 27, 2026
Comment thread compiler/rustc_lint/src/let_underscore.rs
@yashaggarwal85d

This comment was marked as low quality.

@mu001999 mu001999 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

/// Whether `expr` is a place based on a local or a static, so no temporary is involved.
fn is_local_or_static_place(expr: &hir::Expr<'_>) -> bool {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking about cases like:

let &_ = &m.lock().unwrap(); // Shouldn't lint

and

fn identity<T>(x: &T) -> &T { x }

let _ = *identity(&NontrivialDrop); // Should lint

let d = NontrivialDrop;
let _ = *identity(&d); // Shouldn't lint

I suspect we may not be able to cover the above cases at the HIR level by further modifying is_local_or_static_place. If so, I think that's fine. Our goal can be to reduce false positives as much as possible without introducing any new false negatives.

Could you investigate further whether we can eliminate more false positives? If not, I'd like to see some FIXME comments on is_local_or_static_place explaining its current limitations.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 28, 2026
@oli-obk oli-obk closed this Oct 28, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

let_underscore_* lints usage in place expression contexts

4 participants