Skip to content

Commit ebc1f89

Browse files
committed
Add a regression test for issue-54108
1 parent 32bc245 commit ebc1f89

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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`.

0 commit comments

Comments
 (0)