External Publication
Visit Post

Pre-RFC: Unsafe traits conditionally depending on safe trait behaviour

Rust Internals [Unofficial] May 27, 2026
Source

We spoke about this in the libs meeting today and concluded that we're going to do marker traits for now, and try to migrate to this backwards-compatibly if feasible. Effectively:

#[unsafe(has_preconditions(A))]
trait B {}

#[unsafe(satisfies_preconditions(A))]
impl<T: Whatever> B for T {}

can expand to:

unsafe trait Unsafe_A_and_B: A + B {}
trait B {}

unsafe impl<T: Whatever + A + B> Unsafe_A_and_B for T {}
impl<T: Whatever> B for T {}

with unsafe code just relying on Unsafe_A_and_B being implemented as part of its safety contract.

Discussion in the ATmosphere

Loading comments...