Associated type bound from supertrait isn't checked for trait object
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
The following code compiles and causes a use-after-free.
trait Super {
type Assoc;
}
trait Sub: Super<Assoc: Copy> {}
fn unchecked_copy<T: Sub<Assoc = String> + ?Sized>(x: &String) -> String {
*x
}
fn main() {
let x: String = String::from("abc");
let y: String = unchecked_copy::<dyn Sub<Assoc = String>>(&x);
drop(x);
println!("{y}");
}
It seems that the compiler is somehow concluding that T::Assoc = String and T::Assoc: Copy are true at the same time.
cc @lcnr
Meta
Reproducible on the playground with version 1.95.0-nightly (2026-02-12 47611e16044c68ef27ba)
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 running the supplied reproducer on the stated nightly version and inspect the compiler’s handling of associated type bounds inherited through trait objects. Trace the relevant trait-object and bound-checking entry points, then add coverage for this example. Done means the unsound program is rejected or otherwise handled soundly without allowing the use-after-free.
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
- 45/100