External Publication
Visit Post

Pre-Pre-RFC: Prefacing items in methods with `Self::` implements them as associated items

Rust Internals [Unofficial] March 28, 2026
Source

The idea is that you'd be allow to define associated items inside methods so you can use associated generics. Visibility would be restricted to inside the function.

Commented example:

struct Foo<T: Sized> {
    ...
}

impl<T> Foo<T> {
    // You can already do this
    const A: usize = core::mem::size_of::<T>();

    fn foo(&self) {
        // you still can't do this though.
        const B: usize = core::mem::size_of::<T>();

        // doing this would be equivalent to defining `B` outside this method,
        // but in the `impl` block except that it is only visible inside this method.
        const Self::B: usize = core::mem::size_of::<T>();
    }
}

Discussion in the ATmosphere

Loading comments...