Repository navigation
Tracking issue for release notes of #161520: Stabilize core::mem::DropGuard #162646
Description
Activity
- addedrelnotesMarks issues that should be documented in the release notes of the next release.Marks issues that should be documented in the release notes of the next release.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.relnotes-tracking-issueMarks issues tracking what text to put in release notes.Marks issues tracking what text to put in release notes.needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triagingThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
on Sep 11, 2026 I wrote a snippet for the release blog section. I can't edit the comment above, so I'm pasting it here instead:
DropGuard: run a closure on every exit pathThe
Droptrait in Rust makes it possible to run code when a variable goes out of scope, regardless of whether wereturn,?, or panic.Dropbeing a part of types means that in Rust you never have to close a socket.Implementing
Dropcan however feel a little inconvenient when all you want is to run some code unconditionally when a function exits. This is why we’re introducingcore::mem::DropGuard: a new helper type that runs a closure when dropped.DropGuardtakes two arguments: a variable and a closure. It implementsDerefandDerefMutso you can keep working with the variable as normal. But when dropped it runs the closure and consumes the variable.DropGuardalso implements adismissmethod which returns the variable from the guard without running the destructor. This makes it possible to quickly implement all-or-nothing transaction-like APIs with a rollback. Here is an example implementing a parser which uses a guard to roll back mutations in case of failure:use std::mem::DropGuard; use std::num::ParseIntError; /// Attempt to parse all strings in `items` and push them into `nums`. /// If parsing any of the strings fails, `nums` remains unchanged. fn parse_all(nums: &mut Vec<u32>, strings: &[&str]) -> Result<(), ParseIntError> { let len = nums.len(); let mut nums = DropGuard::new(nums, move |nums| { nums.truncate(len); // ← 1. Reset the vec on failure }); for s in strings { nums.push(s.parse()?); // ← 2. If `?` returns an error, roll back } DropGuard::dismiss(nums); // ← 3. Parsing successful, dismiss the guard Ok(()) }
@rustbot label +release-blog-post
- addedrelease-blog-postMarks issues tracking what text to put in the release blog post.Marks issues tracking what text to put in the release blog post.
on Sep 26, 2026 yep, seems good! pasted it in ^^
- addedrelnotes-needs-reviewMarks release notes tracking issues which have not had their contents updated by a maintainer.Marks release notes tracking issues which have not had their contents updated by a maintainer.and removedneeds-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triagingThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
on Oct 10, 2026
This issue tracks the release notes text for #161520.
cc @yoshuawuyts, @nia-e -- original issue/PR authors and assignees for drafting text
See the forge.rust-lang.org chapter about release notes for an overview of how the release team makes use of these tracking issues.
Release notes text
This section should be edited to specify the correct category(s) for the change, with succinct description(s) of what changed. Some things worth considering:
Stabilized APIsandConst Stabilized APIs?Tip
Use the previous releases for inspiration on how to write the release notes text and which categories to pick.
Release blog section
If this change is notable enough for inclusion in the blog post then this section should be edited to contain a draft for the blog post. Otherwise leave it empty.
Note
If a blog post section is required the
release-blog-postlabel should be added (@rustbot label +release-blog-post) to this issue as otherwise it may be missed by the release team.