diff options
| author | Kivooeo <Kivooeo123@gmail.com> | 2025-06-03 20:59:42 +0500 |
|---|---|---|
| committer | Kivooeo <Kivooeo123@gmail.com> | 2025-06-04 19:32:06 +0500 |
| commit | 06ab34e51604ae09d56b42cb4576a87dd44db5be (patch) | |
| tree | d299949dbabf571c5dfeb88af58d819dc4b2c3b0 /tests/ui/privacy | |
| parent | aae43c4532690153af7465227816c93036bb1604 (diff) | |
| download | rust-06ab34e51604ae09d56b42cb4576a87dd44db5be.tar.gz rust-06ab34e51604ae09d56b42cb4576a87dd44db5be.zip | |
cleaned up some tests
Diffstat (limited to 'tests/ui/privacy')
| -rw-r--r-- | tests/ui/privacy/trait-object-method-error.rs | 20 | ||||
| -rw-r--r-- | tests/ui/privacy/trait-object-method-error.stderr | 15 |
2 files changed, 35 insertions, 0 deletions
diff --git a/tests/ui/privacy/trait-object-method-error.rs b/tests/ui/privacy/trait-object-method-error.rs new file mode 100644 index 00000000000..f0214dc6361 --- /dev/null +++ b/tests/ui/privacy/trait-object-method-error.rs @@ -0,0 +1,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 +} diff --git a/tests/ui/privacy/trait-object-method-error.stderr b/tests/ui/privacy/trait-object-method-error.stderr new file mode 100644 index 00000000000..40dde8fc47e --- /dev/null +++ b/tests/ui/privacy/trait-object-method-error.stderr @@ -0,0 +1,15 @@ +error[E0599]: no method named `struct_impl_method` found for struct `Box<dyn MyTrait>` in the current scope + --> $DIR/trait-object-method-error.rs:19:9 + | +LL | obj.struct_impl_method(); + | ^^^^^^^^^^^^^^^^^^ + | +help: there is a method `trait_method` with a similar name + | +LL - obj.struct_impl_method(); +LL + obj.trait_method(); + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0599`. |
