summaryrefslogtreecommitdiffstats
path: root/tests/ui/const-generics/generic_const_exprs/assoc_const_unification
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/const-generics/generic_const_exprs/assoc_const_unification')
-rw-r--r--tests/ui/const-generics/generic_const_exprs/assoc_const_unification/const_equate_assoc_consts.rs27
-rw-r--r--tests/ui/const-generics/generic_const_exprs/assoc_const_unification/doesnt_unify_evaluatable.rs15
-rw-r--r--tests/ui/const-generics/generic_const_exprs/assoc_const_unification/doesnt_unify_evaluatable.stderr10
-rw-r--r--tests/ui/const-generics/generic_const_exprs/assoc_const_unification/dropck_unifies_assoc_consts.rs20
-rw-r--r--tests/ui/const-generics/generic_const_exprs/assoc_const_unification/unifies_evaluatable.rs18
5 files changed, 90 insertions, 0 deletions
diff --git a/tests/ui/const-generics/generic_const_exprs/assoc_const_unification/const_equate_assoc_consts.rs b/tests/ui/const-generics/generic_const_exprs/assoc_const_unification/const_equate_assoc_consts.rs
new file mode 100644
index 000000000..e8f89cb1a
--- /dev/null
+++ b/tests/ui/const-generics/generic_const_exprs/assoc_const_unification/const_equate_assoc_consts.rs
@@ -0,0 +1,27 @@
+// check-pass
+#![feature(generic_const_exprs)]
+#![allow(incomplete_features)]
+
+trait Trait {
+ const ASSOC: usize;
+}
+impl<T> Trait for T {
+ const ASSOC: usize = std::mem::size_of::<T>();
+}
+
+struct Foo<T: Trait>([u8; T::ASSOC])
+where
+ [(); T::ASSOC]:;
+
+fn bar<T: Trait>()
+where
+ [(); T::ASSOC]:,
+{
+ let _: Foo<T> = Foo::<_>(make());
+}
+
+fn make() -> ! {
+ todo!()
+}
+
+fn main() {}
diff --git a/tests/ui/const-generics/generic_const_exprs/assoc_const_unification/doesnt_unify_evaluatable.rs b/tests/ui/const-generics/generic_const_exprs/assoc_const_unification/doesnt_unify_evaluatable.rs
new file mode 100644
index 000000000..c8f7553da
--- /dev/null
+++ b/tests/ui/const-generics/generic_const_exprs/assoc_const_unification/doesnt_unify_evaluatable.rs
@@ -0,0 +1,15 @@
+#![feature(generic_const_exprs)]
+#![allow(incomplete_features)]
+
+trait Trait {
+ const ASSOC: usize;
+}
+
+fn foo<T: Trait, U: Trait>() where [(); U::ASSOC]:, {
+ bar::<{ T::ASSOC }>();
+ //~^ ERROR: unconstrained generic constant
+}
+
+fn bar<const N: usize>() {}
+
+fn main() {}
diff --git a/tests/ui/const-generics/generic_const_exprs/assoc_const_unification/doesnt_unify_evaluatable.stderr b/tests/ui/const-generics/generic_const_exprs/assoc_const_unification/doesnt_unify_evaluatable.stderr
new file mode 100644
index 000000000..e4a0cabe5
--- /dev/null
+++ b/tests/ui/const-generics/generic_const_exprs/assoc_const_unification/doesnt_unify_evaluatable.stderr
@@ -0,0 +1,10 @@
+error: unconstrained generic constant
+ --> $DIR/doesnt_unify_evaluatable.rs:9:11
+ |
+LL | bar::<{ T::ASSOC }>();
+ | ^^^^^^^^^^^^
+ |
+ = help: try adding a `where` bound using this expression: `where [(); { T::ASSOC }]:`
+
+error: aborting due to previous error
+
diff --git a/tests/ui/const-generics/generic_const_exprs/assoc_const_unification/dropck_unifies_assoc_consts.rs b/tests/ui/const-generics/generic_const_exprs/assoc_const_unification/dropck_unifies_assoc_consts.rs
new file mode 100644
index 000000000..274caa1e9
--- /dev/null
+++ b/tests/ui/const-generics/generic_const_exprs/assoc_const_unification/dropck_unifies_assoc_consts.rs
@@ -0,0 +1,20 @@
+// check-pass
+#![feature(generic_const_exprs)]
+#![allow(incomplete_features)]
+
+trait Trait {
+ const ASSOC: usize;
+}
+
+struct Foo<T: Trait>(T)
+where
+ [(); T::ASSOC]:;
+
+impl<T: Trait> Drop for Foo<T>
+where
+ [(); T::ASSOC]:,
+{
+ fn drop(&mut self) {}
+}
+
+fn main() {}
diff --git a/tests/ui/const-generics/generic_const_exprs/assoc_const_unification/unifies_evaluatable.rs b/tests/ui/const-generics/generic_const_exprs/assoc_const_unification/unifies_evaluatable.rs
new file mode 100644
index 000000000..6597b9f2b
--- /dev/null
+++ b/tests/ui/const-generics/generic_const_exprs/assoc_const_unification/unifies_evaluatable.rs
@@ -0,0 +1,18 @@
+// check-pass
+
+#![feature(generic_const_exprs)]
+#![allow(incomplete_features)]
+
+trait Trait {
+ const ASSOC: usize;
+}
+
+fn foo<T: Trait, U: Trait>() where [(); T::ASSOC]:, {
+ bar::<{ T::ASSOC }>();
+}
+
+fn bar<const N: usize>() -> [(); N] {
+ [(); N]
+}
+
+fn main() {}