auto trait leakage can be used to leak arbitrary types
Open
@bit-aloo is already working on this.
Since Jun 11, 2026.
A-auto-traits
A-impl-trait
C-bug
I-ICE
T-types
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- PR merge metrics
- PR metrics pending
Description
When leaking the hidden type of opaques when proving auto traits, we can leak their hidden type to the caller by relying on type inference. See https://github.com/lcnr/random-rust-snippets/issues/13 for minimized examples.
Note that this allows us to access foreign closures during typeck/borrowck. This very easily results in ICE, as this code expects all encountered closures to be local:
// crate dep
struct WaddupGamers<T, U>(Option<T>, U);
impl<T: Leak<Assoc = U>, U> Unpin for WaddupGamers<T, U> {}
pub trait Leak {
type Assoc;
}
impl<T> Leak for T {
type Assoc = T;
}
pub fn define<T>() -> impl Sized {
WaddupGamers(None::<T>, || ())
}
// root
#![feature(type_alias_impl_trait)]
#![allow(unused)]
#![crate_type = "rlib"]
use dep::*;
fn require_auto<T: Unpin>(x: T) -> T { x }
type NameMe<T> = impl Sized;
fn leak<T>() -> NameMe<T>
where
T: Leak<Assoc = NameMe<T>>,
{
// Proving `impl Sized: Unpin` constrains `NameMe<T>` to
// the closure of `define`.
let opaque = require_auto(define::<T>());
let closure;
loop {}
return closure; // This constrains this infer var to that closure
}
results in
thread 'rustc' panicked at compiler/rustc_hir_typeck/src/coercion.rs:1202:62:
DefId::expect_local: `DefId(20:20 ~ dep[6a51]::define::{closure#0})` isn't local
There are a lot of such uses, this was simply the first one i've triggered.
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.
Assessment
This issue has not been assessed yet.