summaryrefslogtreecommitdiffstats
path: root/src/test/ui/associated-types/issue-54108.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui/associated-types/issue-54108.rs')
-rw-r--r--src/test/ui/associated-types/issue-54108.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/test/ui/associated-types/issue-54108.rs b/src/test/ui/associated-types/issue-54108.rs
new file mode 100644
index 000000000..87f67ce4b
--- /dev/null
+++ b/src/test/ui/associated-types/issue-54108.rs
@@ -0,0 +1,41 @@
+use std::ops::Add;
+
+pub trait Encoder {
+ type Size: Add<Output = Self::Size>;
+
+ fn foo(&self) -> Self::Size;
+}
+
+pub trait SubEncoder: Encoder {
+ type ActualSize;
+
+ fn bar(&self) -> Self::Size;
+}
+
+impl<T> Encoder for T
+where
+ T: SubEncoder,
+{
+ type Size = <Self as SubEncoder>::ActualSize;
+ //~^ ERROR: cannot add `<T as SubEncoder>::ActualSize` to `<T as SubEncoder>::ActualSize`
+
+ fn foo(&self) -> Self::Size {
+ self.bar() + self.bar()
+ }
+}
+
+pub struct UnitEncoder;
+
+impl SubEncoder for UnitEncoder {
+ type ActualSize = ();
+
+ fn bar(&self) {}
+}
+
+pub fn fun<R: Encoder>(encoder: &R) {
+ encoder.foo();
+}
+
+fn main() {
+ fun(&UnitEncoder {});
+}