summaryrefslogtreecommitdiffstats
path: root/tests/ui/rfc-2632-const-trait-impl/assoc-type.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/rfc-2632-const-trait-impl/assoc-type.rs')
-rw-r--r--tests/ui/rfc-2632-const-trait-impl/assoc-type.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/ui/rfc-2632-const-trait-impl/assoc-type.rs b/tests/ui/rfc-2632-const-trait-impl/assoc-type.rs
new file mode 100644
index 000000000..7d9dae52c
--- /dev/null
+++ b/tests/ui/rfc-2632-const-trait-impl/assoc-type.rs
@@ -0,0 +1,32 @@
+#![feature(const_trait_impl)]
+
+struct NonConstAdd(i32);
+
+impl std::ops::Add for NonConstAdd {
+ type Output = Self;
+
+ fn add(self, rhs: Self) -> Self {
+ NonConstAdd(self.0 + rhs.0)
+ }
+}
+
+#[const_trait]
+trait Foo {
+ type Bar: ~const std::ops::Add;
+}
+
+impl const Foo for NonConstAdd {
+ type Bar = NonConstAdd;
+ //~^ ERROR: cannot add `NonConstAdd` to `NonConstAdd` in const contexts
+}
+
+#[const_trait]
+trait Baz {
+ type Qux: std::ops::Add;
+}
+
+impl const Baz for NonConstAdd {
+ type Qux = NonConstAdd; // OK
+}
+
+fn main() {}