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
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));}
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…