summaryrefslogtreecommitdiffstats
path: root/tests/ui/associated-consts/associated-const-type-parameters.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/associated-consts/associated-const-type-parameters.rs')
-rw-r--r--tests/ui/associated-consts/associated-const-type-parameters.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/ui/associated-consts/associated-const-type-parameters.rs b/tests/ui/associated-consts/associated-const-type-parameters.rs
new file mode 100644
index 000000000..e7ead1045
--- /dev/null
+++ b/tests/ui/associated-consts/associated-const-type-parameters.rs
@@ -0,0 +1,44 @@
+// run-pass
+
+trait Foo {
+ const X: i32;
+ fn get_x() -> i32 {
+ Self::X
+ }
+}
+
+struct Abc;
+impl Foo for Abc {
+ const X: i32 = 11;
+}
+
+struct Def;
+impl Foo for Def {
+ const X: i32 = 97;
+}
+
+struct Proxy<T>(#[allow(unused_tuple_struct_fields)] T);
+
+impl<T: Foo> Foo for Proxy<T> {
+ const X: i32 = T::X;
+}
+
+fn sub<A: Foo, B: Foo>() -> i32 {
+ A::X - B::X
+}
+
+trait Bar: Foo {
+ const Y: i32 = Self::X;
+}
+
+fn main() {
+ assert_eq!(11, Abc::X);
+ assert_eq!(97, Def::X);
+ assert_eq!(11, Abc::get_x());
+ assert_eq!(97, Def::get_x());
+ assert_eq!(-86, sub::<Abc, Def>());
+ assert_eq!(86, sub::<Def, Abc>());
+ assert_eq!(-86, sub::<Proxy<Abc>, Def>());
+ assert_eq!(-86, sub::<Abc, Proxy<Def>>());
+ assert_eq!(86, sub::<Proxy<Def>, Proxy<Abc>>());
+}