]> git.lizzy.rs Git - rust.git/blob - tests/ui/associated-types/issue-54108.rs
Rollup merge of #107306 - compiler-errors:correct-sugg-for-closure-arg-needs-borrow...
[rust.git] / tests / ui / associated-types / issue-54108.rs
1 use std::ops::Add;
2
3 pub trait Encoder {
4     type Size: Add<Output = Self::Size>;
5
6     fn foo(&self) -> Self::Size;
7 }
8
9 pub trait SubEncoder: Encoder {
10     type ActualSize;
11
12     fn bar(&self) -> Self::Size;
13 }
14
15 impl<T> Encoder for T
16 where
17     T: SubEncoder,
18 {
19     type Size = <Self as SubEncoder>::ActualSize;
20     //~^ ERROR: cannot add `<T as SubEncoder>::ActualSize` to `<T as SubEncoder>::ActualSize`
21
22     fn foo(&self) -> Self::Size {
23         self.bar() + self.bar()
24     }
25 }
26
27 pub struct UnitEncoder;
28
29 impl SubEncoder for UnitEncoder {
30     type ActualSize = ();
31
32     fn bar(&self) {}
33 }
34
35 pub fn fun<R: Encoder>(encoder: &R) {
36     encoder.foo();
37 }
38
39 fn main() {
40     fun(&UnitEncoder {});
41 }