rust/tests/ui/privacy/trait-object-method-error.rs
2025-06-04 19:32:06 +05:00

21 lines
412 B
Rust

//! 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
}