Skip to content

Add let_underscore_drop_guard lint. - #164414

Open
theemathas wants to merge 1 commit into
rust-lang:mainfrom
theemathas:let_underscore_drop_guard
Open

theemathas wants to merge 1 commit into
rust-lang:mainfrom
theemathas:let_underscore_drop_guard

Conversation

@theemathas

@theemathas theemathas commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

This lint is similar to the existing let_underscore_lock lint, but applies to DropGuard instead of MutexGuard and similar types. It is deny-by-default, like let_underscore_lock. (Note that the related let_underscore_drop lint is allow-by-default.)

Relevant discussion: #t-libs > Linting `let _ = DropGuard::new(....);`

Note that DropGuard is a newly stabilized type, currently in 1.100 beta, and will be on the 1.100 stable release on November 12.

Tracking issue for DropGuard: #144426

This lint is similar to the existing `let_underscore_lock` lint,
but applies to `DropGuard` instead of `MutexGuard` and similar types.
@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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 16, 2026
@rustbot

rustbot commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

r? @petrochenkov

rustbot has assigned @petrochenkov.
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 18 candidates

@theemathas theemathas added the I-lang-nominated Nominated for discussion during a lang team meeting. label Oct 16, 2026
@theemathas

theemathas commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Lang-nominating to ask for approval for adding a new lint. Also, does it make sense to beta-backport this so that we have the lint at the same time as DropGuard being stabilized? (Although based on zulip discussion, it seems to me like T-libs doesn't want this to be backported, which I find a bit surprising.)

@Jules-Bertholet

Copy link
Copy Markdown
Contributor

As discussed in the Zulip thread, perhaps we want a more general mechanism here?

@scottmcm

Copy link
Copy Markdown
Member

I agree it makes sense to have a lint to catch this kind of problem with drop guards for the same reason as mutex guards.

@rfcbot fcp merge lang

I see the note that a more general mechanism might be nice, and I don't disagree, but we can always remove any behaviour from this lint in future should the general mechanism be created, so I don't see a need to reject this one. If we end up with another dead name in the removed-lints list eventually, so be it.

@rust-rfcbot rust-rfcbot added the T-lang Relevant to the language team label Oct 16, 2026
@rust-rfcbot

rust-rfcbot commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

@scottmcm has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
cc @rust-lang/libs-ping: FCP proposed for libs, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Oct 16, 2026
@programmerjake

programmerjake commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Although based on zulip discussion, it seems to me like T-libs doesn't want this to be backported, which I find a bit surprising.

I think this should be backported. Do you have a link to where some of T-libs disagrees? (I happen to be on T-libs but not on the FCP list.)
Edit: the link #t-libs > Linting `let _ = DropGuard::new(....);` @ 💬

@petrochenkov

Copy link
Copy Markdown
Contributor

As discussed in the Zulip thread, perhaps we want a more general mechanism here?

I agree with this, MutexGuard previously, DropGuard now, some other type next, but they are all the same pattern.

@petrochenkov petrochenkov added S-waiting-on-t-lang Status: Awaiting decision from T-lang and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 16, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. I-lang-nominated Nominated for discussion during a lang team meeting. proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. S-waiting-on-t-lang Status: Awaiting decision from T-lang T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants