about summary refs log tree commit diff
path: root/tests/ui/privacy/trait-object-method-error.rs
blob: f0214dc636138a3041139d528d58572b2aa7667e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//! Trait objects only allow access to methods defined in the trait.

trait MyTrait {
    fn trait_method(&mut self);
}

struct ImplType;

impl MyTrait for ImplType {
    fn trait_method(&mut self) {}
}

impl ImplType {
    fn struct_impl_method(&mut self) {}
}

fn main() {
    let obj: Box<dyn MyTrait> = Box::new(ImplType);
    obj.struct_impl_method(); //~ ERROR no method named `struct_impl_method` found
}