Skip to content

Stabilize core::mem::DropGuard - #161520

Open
yoshuawuyts wants to merge 1 commit into
rust-lang:mainfrom
yoshuawuyts:stabilize-dropguard
Open

Stabilize core::mem::DropGuard#161520
yoshuawuyts wants to merge 1 commit into
rust-lang:mainfrom
yoshuawuyts:stabilize-dropguard

Conversation

@yoshuawuyts

Copy link
Copy Markdown
Member

Closes #144426. This PR stabilizes core::mem::DropGuard, as per the comment in #144426 (comment):

[nia-e]: We discussed this in today's libs meeting - DropGuard is a good name, and we agreed dismiss is Good Enough & better than the other options. Feel free to send a stabilisation PR & ask us to open FCP there!

Thanks!

r? @nia-e

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 22, 2026
@nia-e

nia-e commented Aug 22, 2026

Copy link
Copy Markdown
Member

@rfcbot fcp merge libs

@rust-rfcbot

rust-rfcbot commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

@nia-e 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!

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 Aug 22, 2026
@dtolnay

dtolnay commented Aug 22, 2026

Copy link
Copy Markdown
Member

The feedback in #144426 (comment) / alternative in #150027 may not have been discussed by the team.

I would be open to something like #161550 to make no-value DropGuard feel more like a first class use case.

@yoshuawuyts

yoshuawuyts commented Aug 22, 2026

Copy link
Copy Markdown
Member Author

@dtolnay The question of whether to add an additional constructor which doesn't take a value was discussed during a previous libs call in the context of rust-lang/libs-team#629. Highlighting the relevant section from @Amanieu's comment in rust-lang/libs-team#629 (comment):

We discussed this in the @rust-lang/libs-api meeting. […] We might consider an additional constructor method on DropGuard which don't take a value, but even then the value is questionable since you're only saving a few characters and it doesn't impact readability.

That's not a definitive "no" — but it has at least been considered before, and at least at the time didn't seem like a worthwhile addition.

@clarfonthey

Copy link
Copy Markdown
Contributor

Per the meeting we were pretty fine with this API and its use case and didn't feel the other version needed to block it. Honestly feels like it could be a separate type given the API simplicity.

Zalathar added a commit to Zalathar/rust that referenced this pull request Aug 25, 2026
…they

Use `drop_guard` in some places in {core,alloc,std}

- Tracking issue: rust-lang#144426
- Will conflict with rust-lang#161520
- rust-lang#161550 would also be cool occasionally

Didn't touch the places where manual `impl Drop`s had `#[inline]` on their `fn drop` or where the guard type had other `impl`s beside `Drop` and/or was named a lot.

No LLMs used, only pure human slop.
@yoshuawuyts

Copy link
Copy Markdown
Member Author

Quoting my own comment on #161550 (comment):

In #161550 (comment) @danielhenrymantilla suggests using DropGuard::from or alternatively DropGuard::from_fn as the name for this API instead, stating that: "[...] I wouldn't recommend using new() for the convenience, narrower, case." I believe that #161702 substantiates that a no-value constructor is indeed a: "convenience, narrower case", and the new method should be the one to take a value.

I believe the only decision blocking the DropGuard stabilization right now is whether DropGuard::new should take a value. I believe #161702 makes a good case that new should indeed take a value, which is what what this PR proposes we stabilize. I do think adding a no-value constructor could be a welcome convenience, but as a follow-up after we stabilize the core API.

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. proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

Tracking Issue for core::mem::DropGuard

6 participants