`CoerceShared` unsoundness due to not checking `repr`.
Open
Nobody has claimed this yet.
A-repr
C-bug
F-reborrow
I-unsound
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
The following code causes a segmentation fault at run time. The compiler seems to be incorrectly assuming that MyMut and MyRef have the same size.
#![feature(reborrow)]
use std::marker::{Reborrow, CoerceShared};
#[repr(align(4096))]
struct MyMut<'a>(&'a i32);
impl Reborrow for MyMut<'_> {}
#[derive(Clone, Copy)]
#[repr(align(65536))]
struct MyRef<'a>(&'a i32);
impl<'a> CoerceShared<MyRef<'a>> for MyMut<'a> {}
fn main() {
foo(MyMut(&1));
}
fn foo(x: MyMut<'_>) {
bar(x);
}
fn bar(x: MyRef<'_>) {}
cc @aapoalas
Meta
Reproducible on the playground with version 1.97.0-nightly (2026-05-10 4b0c9d76ae7d387229ca)
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 minimized example with the stated nightly compiler and trace how the compiler handles the CoerceShared implementation and the two differently aligned types. Identify the missing repr compatibility check, then add a regression test showing that the unsound coercion no longer compiles or runs unsafely.
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