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
Reborrow unsoundness due to not checking for Copy #156380
C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.F-reborrow`#![feature(reborrow)]`; see #145612I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-typesRelevant to the types team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
This unsoundness was discovered by @coolcatcoder. I'm filing this issue on their behalf.
The following code causes a double free. It should not compile.
#![feature(reborrow)]#[expect(dead_code)]// This code correctly gives a compile error if &'a mut () is changed to &'a ()structWrap<'a>(&'amut(),String);impl<'a> std::marker::ReborrowforWrap<'a>{}fnget(x:Wrap<'_>) -> String{
x.1}fnmain(){let x = Wrap(&mut(),String::from("a"));let _y = get(x);let _z = get(x);}
Below is a related unsoundness which I independently discovered. This code creates aliasing &muts, which should not be allowed.
#![feature(reborrow)]#[expect(dead_code)]// This works even if the field is &'a (), not &'a mut ()structWrap<'a,T>(&'a(),T);impl<'a> std::marker::ReborrowforWrap<'a,&'staticmuti32>{}fnget<'a,'b>(x:Wrap<'a,&'bmuti32>) -> &'bmuti32{
x.1}fnmain(){letmut x = 1;let thing = Wrap(&(),&mut x);let y = get(thing);let z = get(thing);*y = 2;*z = 3;*y = 4;*z = 5;assert!(std::ptr::eq(y, z));}
C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.F-reborrow`#![feature(reborrow)]`; see #145612I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-typesRelevant to the types team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Activity
theemathas commentedon May 10, 2026
Below is a related unsoundness which I independently discovered. This code creates aliasing
&muts, which should not be allowed.theemathas commentedon May 24, 2026
The first snippet in this issue has been fixed by #156784. The second snippet has not been fixed yet.
Jules-Bertholet commentedon Sep 30, 2026
The second snipped no longer compiles
yashaggarwal85d commentedon Oct 25, 2026
Rollup merge of rust-lang#164888 - yashaggarwal85d:fix-156380-reborro…
Rollup merge of rust-lang#164888 - yashaggarwal85d:fix-156380-reborro…
Auto merge of #165000 - JonathanBrouwer:rollup-qAF68v2, r=JonathanBro…
Rollup merge of rust-lang#164888 - yashaggarwal85d:fix-156380-reborro…
Auto merge of #165002 - JonathanBrouwer:rollup-XbLRp0m, r=JonathanBro…
Unrolled build for #164888 in rollup 165002
Rollup merge of #164888 - yashaggarwal85d:fix-156380-reborrow-test, r…