File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed
src/test/ui/associated-types Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ error[E0277]: cannot add `<T as SubEncoder>::ActualSize` to `<T as SubEncoder>::ActualSize`
2
+ --> $DIR/issue-54108.rs:19:5
3
+ |
4
+ LL | type Size: Add<Output = Self::Size>;
5
+ | ------------------------ required by this bound in `Encoder::Size`
6
+ ...
7
+ LL | type Size = <Self as SubEncoder>::ActualSize;
8
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `<T as SubEncoder>::ActualSize + <T as SubEncoder>::ActualSize`
9
+ |
10
+ = help: the trait `Add` is not implemented for `<T as SubEncoder>::ActualSize`
11
+ help: consider further restricting the associated type
12
+ |
13
+ LL | T: SubEncoder, <T as SubEncoder>::ActualSize: Add
14
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15
+
16
+ error: aborting due to previous error
17
+
18
+ For more information about this error, try `rustc --explain E0277`.
You can’t perform that action at this time.
0 commit comments