You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pin! in an if let guard of an or-pattern arm never drops the value pinned for the second alternative, which breaks Pin's drop guarantee #165322
A-destructorsArea: Destructors (`Drop`, …)A-patternsRelating to patterns and pattern matchingA-pinArea: PinC-bugCategory: This is a bug.F-super_letit's super, let's go!I-memleakIssue: Runtime memory leak without `mem::forget`.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-mediumMedium priorityS-found-by-fuzzingStatus: This issue was found using fuzzing. It may not arise in practical cases.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
#![forbid(unsafe_code)]structD(u8);implDropforD{fndrop(&mutself){println!("drop {}",self.0);}}fnf(x:Result<u8,u8>){match x {Ok(v) | Err(v)iflet p = std::pin::pin!(D(v)) && p.0 > 0 => println!("arm {v}"),
_ => {}}}fnmain(){f(Ok(1));f(Err(2));// the `D(2)` pinned in the guard is never dropped}
Expected:arm 1, drop 1, arm 2, drop 2.
Actual:arm 1, drop 1, arm 2. D(2) is never dropped, in debug and release builds.
I believe this regressed in 5e781d0. As far as I can tell 4529dd9 does not exhibit the issue.
that's because #143764 changes the order in which or-alternatives are lowered. this bug existed before that, but it would manifest on other alternatives. given the root cause1, I expect this has been around as long as both super let and if let guards were both in nightly2, and it was definitely around before that PR was merged (which was before if let guards were stable). on the previous nightly, the output is
yep! bisecting with a reproducer that counts how many times a pin!'s pinned value is dropped confirms that expectation, too:
Details
********************************************************************************
Regression in nightly-2025-04-20
********************************************************************************
fetching https://static.rust-lang.org/dist/2025-04-19/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2025-04-19: 40 B / 40 B [==============================================================] 100.00 % 865.79 KB/s converted 2025-04-19 to 191df20fcad9331d3a948aa8e8556775ec3fe69d
fetching https://static.rust-lang.org/dist/2025-04-20/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2025-04-20: 40 B / 40 B [==============================================================] 100.00 % 913.89 KB/s converted 2025-04-20 to 077cedc2afa8ac0b727b7a6cbe012940ba228deb
looking for regression commit between 2025-04-19 and 2025-04-20
fetching (via remote github) commits from max(191df20fcad9331d3a948aa8e8556775ec3fe69d, 2025-04-17) to 077cedc2afa8ac0b727b7a6cbe012940ba228deb
ending github query because we found starting sha: 191df20fcad9331d3a948aa8e8556775ec3fe69d
get_commits_between returning commits, len: 4
commit[0] 2025-04-18: Auto merge of #139996 - matthiaskrgr:rollup-0nka2hw, r=matthiaskrgr
commit[1] 2025-04-19: Auto merge of #140015 - GuillaumeGomez:subtree-update_cg_gcc_2025-04-18, r=antoyo
commit[2] 2025-04-19: Auto merge of #139114 - m-ou-se:super-let-pin, r=davidtwco
commit[3] 2025-04-19: Auto merge of #140040 - ChrisDenton:rollup-56bzfuq, r=ChrisDenton
from the reproducer
#![feature(if_let_guard)]#![feature(cell_update)]#![allow(stable_features, irrefutable_let_patterns)]use std::cell::Cell;structD<'a>(&'aCell<usize>);implDropforD<'_>{fndrop(&mutself){self.0.update(|x| x + 1);}}fnmain(){let c = Cell::new(0);for x in[false,true]{match x {false | trueiflet _ = std::pin::pin!(D(&c)) => {}
_ => {}}}assert_eq!(c.get(),2);}
as far as stable rust is concerned, if let guards have always had this bug, but before stabilization it was a nightly-only regression. I don't know if any of our current regression labels fit that case
A-destructorsArea: Destructors (`Drop`, …)A-patternsRelating to patterns and pattern matchingA-pinArea: PinC-bugCategory: This is a bug.F-super_letit's super, let's go!I-memleakIssue: Runtime memory leak without `mem::forget`.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-mediumMedium priorityS-found-by-fuzzingStatus: This issue was found using fuzzing. It may not arise in practical cases.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
Activity
theemathas commentedon Nov 2, 2026
cc @dianne @Nadrieril
theemathas commentedon Nov 2, 2026
Another reproducer:
Output
Hoverbear commentedon Nov 18, 2026
Bisect output
I believe this regressed in 5e781d0. As far as I can tell 4529dd9 does not exhibit the issue.
dianne commentedon Nov 18, 2026
that's because #143764 changes the order in which or-alternatives are lowered. this bug existed before that, but it would manifest on other alternatives. given the root cause1, I expect this has been around as long as both
super letandif letguards were both in nightly2, and it was definitely around before that PR was merged (which was beforeif letguards were stable). on the previous nightly, the output isFootnotes
fixed by deduplicate
super letbindings that have the scope of anif letguard's scrutinee #165363 ↩though this case in particular would also only manifest once
pin!was implemented in terms ofsuper let↩Hoverbear commentedon Nov 20, 2026
Hmm so that'd point to a7c39b6 aka #139114, then?
dianne commentedon Nov 21, 2026
yep! bisecting with a reproducer that counts how many times a
pin!'s pinned value is dropped confirms that expectation, too:Details
from the reproducer
as far as stable rust is concerned,
if letguards have always had this bug, but before stabilization it was a nightly-only regression. I don't know if any of our current regression labels fit that caserustbot commentedon Nov 22, 2026
Assigning P-medium (discussion on Zulip)