fork download
  1. mod my_struct {
  2. pub struct MyStruct {}
  3. }
  4.  
  5. mod traits_1 {
  6. pub trait Trait1 {
  7. fn print(&self);
  8. }
  9.  
  10. impl Trait1 for ::my_struct::MyStruct {
  11. fn print(&self) {
  12. println!("Good morning!");
  13. }
  14. }
  15. }
  16.  
  17. mod traits_2 {
  18. pub trait Trait2 {
  19. fn print(&self);
  20. }
  21.  
  22. impl Trait2 for ::my_struct::MyStruct {
  23. fn print(&self) {
  24. println!("Goodbye!");
  25. }
  26. }
  27. }
  28.  
  29. fn main() {
  30. use traits_1::Trait1;
  31. use traits_2::Trait2;
  32.  
  33. let instance = my_struct::MyStruct {};
  34. println!("{}", instance.print());
  35. }
  36.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
error[E0034]: multiple applicable items in scope
  --> prog.rs:34:29
   |
34 |     println!("{}", instance.print());
   |                             ^^^^^ multiple `print` found
   |
note: candidate #1 is defined in an impl of the trait `traits_1::Trait1` for the type `my_struct::MyStruct`
  --> prog.rs:11:9
   |
11 |         fn print(&self) {
   |         ^
note: candidate #2 is defined in an impl of the trait `traits_2::Trait2` for the type `my_struct::MyStruct`
  --> prog.rs:23:9
   |
23 |         fn print(&self) {
   |         ^

error: aborting due to previous error

stdout
Standard output is empty