Attribute for default trait impl?

Hi,
Do we have a way to know that a trait impl is a default one or a customised one ?

Using VSCode and rust-analyzer.

trait A {
    fn myfn_a(&self) {
        println!("Default impl")
    }

    fn myfn_b(&self);
}

struct MyStruct {
    el: u32,
}

impl A for MyStruct {
    fn myfn_b(&self) {
        println!("Non default impl")
    }
}

fn called_fn(input: MyStruct) {
    input.myfn_a(); //<- popup tells me it's default impl
    input.myfn_b(); //<- popup tells me it's non default impl
}


fn main(){
    let input = MyStruct{el: 0};
    
    called_fn(input)
}

So I would like the IDE's function popup to tell me if the trait's called function is a default impl or a custom impl.

Is there a rust attribute out there doing/helping this ?

Thanks guys

Someone else will have to answer your direct question, as I'm not a rust-analyzer user.

But if you want to make a default method non-overridable, you can put it in an extension trait instead of the main one:

trait A: AExt {
    fn myfn_b(&self);
}

/// Non-overridable methods of `A`
trait AExt {
    fn myfn_a(&self);
}

// Because this `impl` exists, there can't be any others
impl<T:A> AExt for T {
    fn myfn_a(&self) {
        println!("Default impl")
    }
}
1 Like

Thanks!