`Reborrow` unsoundness due to not checking for `Copy`
Open
Nobody has claimed this yet.
C-bug
F-reborrow
I-unsound
T-types
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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 ()
struct Wrap<'a>(&'a mut (), String);
impl<'a> std::marker::Reborrow for Wrap<'a> {}
fn get(x: Wrap<'_>) -> String {
x.1
}
fn main() {
let x = Wrap(&mut (), String::from("a"));
let _y = get(x);
let _z = get(x);
}
cc @aapoalas
Meta
Reproducible on the playground with version 1.97.0-nightly (2026-05-08 fb0a5a5a9c892b351f34)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the provided example with Rust nightly 1.97.0 on the playground, then trace the Reborrow feature implementation and its handling of Copy checks. Done means the example is rejected by the compiler and no longer permits the reported double-free behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100