summaryrefslogtreecommitdiffstats
path: root/src/test/ui/const-generics/occurs-check
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/const-generics/occurs-check
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/const-generics/occurs-check')
-rw-r--r--src/test/ui/const-generics/occurs-check/bind-param.rs17
-rw-r--r--src/test/ui/const-generics/occurs-check/unify-fixpoint.rs12
-rw-r--r--src/test/ui/const-generics/occurs-check/unify-fixpoint.stderr11
-rw-r--r--src/test/ui/const-generics/occurs-check/unify-n-nplusone.rs16
-rw-r--r--src/test/ui/const-generics/occurs-check/unify-n-nplusone.stderr9
-rw-r--r--src/test/ui/const-generics/occurs-check/unused-substs-1.rs13
-rw-r--r--src/test/ui/const-generics/occurs-check/unused-substs-1.stderr19
-rw-r--r--src/test/ui/const-generics/occurs-check/unused-substs-2.rs28
-rw-r--r--src/test/ui/const-generics/occurs-check/unused-substs-2.stderr9
-rw-r--r--src/test/ui/const-generics/occurs-check/unused-substs-3.rs19
-rw-r--r--src/test/ui/const-generics/occurs-check/unused-substs-3.stderr11
-rw-r--r--src/test/ui/const-generics/occurs-check/unused-substs-4.rs11
-rw-r--r--src/test/ui/const-generics/occurs-check/unused-substs-4.stderr9
-rw-r--r--src/test/ui/const-generics/occurs-check/unused-substs-5.rs20
-rw-r--r--src/test/ui/const-generics/occurs-check/unused-substs-5.stderr11
15 files changed, 215 insertions, 0 deletions
diff --git a/src/test/ui/const-generics/occurs-check/bind-param.rs b/src/test/ui/const-generics/occurs-check/bind-param.rs
new file mode 100644
index 000000000..ee4244051
--- /dev/null
+++ b/src/test/ui/const-generics/occurs-check/bind-param.rs
@@ -0,0 +1,17 @@
+// build-pass
+#![feature(generic_const_exprs)]
+#![allow(incomplete_features)]
+
+// This test does not use any "unevaluated" consts, so it should compile just fine.
+
+fn bind<const N: usize>(value: [u8; N]) -> [u8; N] {
+ todo!()
+}
+
+fn sink(_: [u8; 5]) {}
+
+fn main() {
+ let mut arr = Default::default();
+ arr = bind(arr);
+ sink(arr);
+}
diff --git a/src/test/ui/const-generics/occurs-check/unify-fixpoint.rs b/src/test/ui/const-generics/occurs-check/unify-fixpoint.rs
new file mode 100644
index 000000000..e6f8e4ad3
--- /dev/null
+++ b/src/test/ui/const-generics/occurs-check/unify-fixpoint.rs
@@ -0,0 +1,12 @@
+// check-pass
+#![feature(generic_const_exprs)] //~ WARN the feature `generic_const_exprs` is incomplete
+
+
+fn bind<const N: usize>(value: [u8; N + 2]) -> [u8; N * 2] {
+ todo!()
+}
+
+fn main() {
+ let mut arr = Default::default();
+ arr = bind::<2>(arr);
+}
diff --git a/src/test/ui/const-generics/occurs-check/unify-fixpoint.stderr b/src/test/ui/const-generics/occurs-check/unify-fixpoint.stderr
new file mode 100644
index 000000000..f9b56bd38
--- /dev/null
+++ b/src/test/ui/const-generics/occurs-check/unify-fixpoint.stderr
@@ -0,0 +1,11 @@
+warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
+ --> $DIR/unify-fixpoint.rs:2:12
+ |
+LL | #![feature(generic_const_exprs)]
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+ = note: `#[warn(incomplete_features)]` on by default
+ = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
+
+warning: 1 warning emitted
+
diff --git a/src/test/ui/const-generics/occurs-check/unify-n-nplusone.rs b/src/test/ui/const-generics/occurs-check/unify-n-nplusone.rs
new file mode 100644
index 000000000..c6324bca1
--- /dev/null
+++ b/src/test/ui/const-generics/occurs-check/unify-n-nplusone.rs
@@ -0,0 +1,16 @@
+#![feature(generic_const_exprs)]
+#![allow(incomplete_features)]
+
+// This test would tries to unify `N` with `N + 1` which must fail the occurs check.
+
+fn bind<const N: usize>(value: [u8; N]) -> [u8; N + 1] {
+ todo!()
+}
+
+fn sink(_: [u8; 5]) {}
+
+fn main() {
+ let mut arr = Default::default();
+ arr = bind(arr); //~ ERROR mismatched types
+ sink(arr);
+}
diff --git a/src/test/ui/const-generics/occurs-check/unify-n-nplusone.stderr b/src/test/ui/const-generics/occurs-check/unify-n-nplusone.stderr
new file mode 100644
index 000000000..6b8e688fb
--- /dev/null
+++ b/src/test/ui/const-generics/occurs-check/unify-n-nplusone.stderr
@@ -0,0 +1,9 @@
+error[E0308]: mismatched types
+ --> $DIR/unify-n-nplusone.rs:14:11
+ |
+LL | arr = bind(arr);
+ | ^^^^^^^^^ encountered a self-referencing constant
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/const-generics/occurs-check/unused-substs-1.rs b/src/test/ui/const-generics/occurs-check/unused-substs-1.rs
new file mode 100644
index 000000000..9d12250c9
--- /dev/null
+++ b/src/test/ui/const-generics/occurs-check/unused-substs-1.rs
@@ -0,0 +1,13 @@
+#![feature(generic_const_exprs)]
+#![allow(incomplete_features)]
+
+trait Bar<const M: usize> {}
+impl<const N: usize> Bar<N> for A<{ 6 + 1 }> {}
+
+struct A<const N: usize>
+where
+ A<N>: Bar<N>;
+
+fn main() {
+ let _ = A; //~ERROR the trait bound
+}
diff --git a/src/test/ui/const-generics/occurs-check/unused-substs-1.stderr b/src/test/ui/const-generics/occurs-check/unused-substs-1.stderr
new file mode 100644
index 000000000..a3c011d92
--- /dev/null
+++ b/src/test/ui/const-generics/occurs-check/unused-substs-1.stderr
@@ -0,0 +1,19 @@
+error[E0277]: the trait bound `A<_>: Bar<_>` is not satisfied
+ --> $DIR/unused-substs-1.rs:12:13
+ |
+LL | let _ = A;
+ | ^ the trait `Bar<_>` is not implemented for `A<_>`
+ |
+ = help: the trait `Bar<N>` is implemented for `A<7>`
+note: required by a bound in `A`
+ --> $DIR/unused-substs-1.rs:9:11
+ |
+LL | struct A<const N: usize>
+ | - required by a bound in this
+LL | where
+LL | A<N>: Bar<N>;
+ | ^^^^^^ required by this bound in `A`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/const-generics/occurs-check/unused-substs-2.rs b/src/test/ui/const-generics/occurs-check/unused-substs-2.rs
new file mode 100644
index 000000000..9a73f1a53
--- /dev/null
+++ b/src/test/ui/const-generics/occurs-check/unused-substs-2.rs
@@ -0,0 +1,28 @@
+#![feature(generic_const_exprs)]
+#![allow(incomplete_features)]
+
+// The goal is is to get an unevaluated const `ct` with a `Ty::Infer(TyVar(_#1t)` subst.
+//
+// If we are then able to infer `ty::Infer(TyVar(_#1t) := Ty<ct>` we introduced an
+// artificial inference cycle.
+struct Foo<const N: usize>;
+
+trait Bind<T> {
+ fn bind() -> (T, Self);
+}
+
+// `N` has to be `ConstKind::Unevaluated`.
+impl<T> Bind<T> for Foo<{ 6 + 1 }> {
+ fn bind() -> (T, Self) {
+ (panic!(), Foo)
+ }
+}
+
+fn main() {
+ let (mut t, foo) = Foo::bind();
+ // `t` is `ty::Infer(TyVar(_#1t))`
+ // `foo` contains `ty::Infer(TyVar(_#1t))` in its substs
+ t = foo;
+ //~^ ERROR mismatched types
+ //~| NOTE cyclic type
+}
diff --git a/src/test/ui/const-generics/occurs-check/unused-substs-2.stderr b/src/test/ui/const-generics/occurs-check/unused-substs-2.stderr
new file mode 100644
index 000000000..9532fc21a
--- /dev/null
+++ b/src/test/ui/const-generics/occurs-check/unused-substs-2.stderr
@@ -0,0 +1,9 @@
+error[E0308]: mismatched types
+ --> $DIR/unused-substs-2.rs:25:9
+ |
+LL | t = foo;
+ | ^^^ cyclic type of infinite size
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/const-generics/occurs-check/unused-substs-3.rs b/src/test/ui/const-generics/occurs-check/unused-substs-3.rs
new file mode 100644
index 000000000..0d38bd393
--- /dev/null
+++ b/src/test/ui/const-generics/occurs-check/unused-substs-3.rs
@@ -0,0 +1,19 @@
+#![feature(generic_const_exprs)]
+#![allow(incomplete_features)]
+
+// The goal is is to get an unevaluated const `ct` with a `Ty::Infer(TyVar(_#1t)` subst.
+//
+// If we are then able to infer `ty::Infer(TyVar(_#1t) := Ty<ct>` we introduced an
+// artificial inference cycle.
+fn bind<T>() -> (T, [u8; 6 + 1]) {
+ todo!()
+}
+
+fn main() {
+ let (mut t, foo) = bind();
+ // `t` is `ty::Infer(TyVar(_#1t))`
+ // `foo` contains `ty::Infer(TyVar(_#1t))` in its substs
+ t = foo;
+ //~^ ERROR mismatched types
+ //~| NOTE cyclic type
+}
diff --git a/src/test/ui/const-generics/occurs-check/unused-substs-3.stderr b/src/test/ui/const-generics/occurs-check/unused-substs-3.stderr
new file mode 100644
index 000000000..fd8f8b269
--- /dev/null
+++ b/src/test/ui/const-generics/occurs-check/unused-substs-3.stderr
@@ -0,0 +1,11 @@
+error[E0308]: mismatched types
+ --> $DIR/unused-substs-3.rs:16:9
+ |
+LL | t = foo;
+ | ^^^- help: try using a conversion method: `.to_vec()`
+ | |
+ | cyclic type of infinite size
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/const-generics/occurs-check/unused-substs-4.rs b/src/test/ui/const-generics/occurs-check/unused-substs-4.rs
new file mode 100644
index 000000000..03c2f5486
--- /dev/null
+++ b/src/test/ui/const-generics/occurs-check/unused-substs-4.rs
@@ -0,0 +1,11 @@
+#![feature(generic_const_exprs)]
+#![allow(incomplete_features)]
+
+fn bind<const N: usize>(value: [u8; N]) -> [u8; 3 + 4] {
+ todo!()
+}
+
+fn main() {
+ let mut arr = Default::default();
+ arr = bind(arr); //~ ERROR mismatched type
+}
diff --git a/src/test/ui/const-generics/occurs-check/unused-substs-4.stderr b/src/test/ui/const-generics/occurs-check/unused-substs-4.stderr
new file mode 100644
index 000000000..5685eedbd
--- /dev/null
+++ b/src/test/ui/const-generics/occurs-check/unused-substs-4.stderr
@@ -0,0 +1,9 @@
+error[E0308]: mismatched types
+ --> $DIR/unused-substs-4.rs:10:11
+ |
+LL | arr = bind(arr);
+ | ^^^^^^^^^ encountered a self-referencing constant
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/const-generics/occurs-check/unused-substs-5.rs b/src/test/ui/const-generics/occurs-check/unused-substs-5.rs
new file mode 100644
index 000000000..383ab4cd8
--- /dev/null
+++ b/src/test/ui/const-generics/occurs-check/unused-substs-5.rs
@@ -0,0 +1,20 @@
+#![feature(generic_const_exprs)]
+#![allow(incomplete_features)]
+
+// `N + 1` also depends on `T` here even if it doesn't use it.
+fn q<T, const N: usize>(_: T) -> [u8; N + 1] {
+ todo!()
+}
+
+fn supplier<T>() -> T {
+ todo!()
+}
+
+fn catch_me<const N: usize>() where [u8; N + 1]: Default {
+ let mut x = supplier();
+ x = q::<_, N>(x); //~ ERROR mismatched types
+}
+
+fn main() {
+ catch_me::<3>();
+}
diff --git a/src/test/ui/const-generics/occurs-check/unused-substs-5.stderr b/src/test/ui/const-generics/occurs-check/unused-substs-5.stderr
new file mode 100644
index 000000000..be289f44f
--- /dev/null
+++ b/src/test/ui/const-generics/occurs-check/unused-substs-5.stderr
@@ -0,0 +1,11 @@
+error[E0308]: mismatched types
+ --> $DIR/unused-substs-5.rs:15:9
+ |
+LL | x = q::<_, N>(x);
+ | ^^^^^^^^^^^^- help: try using a conversion method: `.to_vec()`
+ | |
+ | cyclic type of infinite size
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.