fork download
  1. trait SuperTrait {
  2. type Raw;
  3.  
  4. fn raw(&self) -> Self::Raw;
  5. }
  6.  
  7. trait SubTrait: SuperTrait<Raw=i32> {}
  8.  
  9. // compiler suggests changing 'B' to 'B: SuperTrait'
  10. // while correct solution is 'B: SubTrait'
  11. fn generic_method<A: SubTrait, B>(a: A, b: B) -> A::Raw {
  12. a.raw() + b.raw()
  13. }
  14.  
  15. fn main() {}
  16.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
error: no method named `raw` found for type `B` in the current scope
  --> prog.rs:12:17
   |
12 |     a.raw() + b.raw()
   |                 ^^^
   |
   = help: items from traits can only be used if the trait is implemented and in scope; the following trait defines an item `raw`, perhaps you need to implement it:
   = help: candidate #1: `SuperTrait`

error: aborting due to previous error

stdout
Standard output is empty