about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBoxy <supbscripter@gmail.com>2023-01-14 19:01:31 +0000
committerBoxy <supbscripter@gmail.com>2023-01-18 04:07:39 +0000
commit88f81a0de122843afc122468823f1ed6f0b8f2c8 (patch)
treea62f6cb3e166278aaf3f2260ddc0f77bdf0d25a8
parent4ca5368a122e06e33fd8fb5f3e2c4b63492273f1 (diff)
downloadrust-88f81a0de122843afc122468823f1ed6f0b8f2c8.tar.gz
rust-88f81a0de122843afc122468823f1ed6f0b8f2c8.zip
test for non local anon const printing
-rw-r--r--tests/ui/const-generics/generic_const_exprs/auxiliary/anon_const_non_local.rs8
-rw-r--r--tests/ui/const-generics/generic_const_exprs/non_local_anon_const_diagnostics.rs16
-rw-r--r--tests/ui/const-generics/generic_const_exprs/non_local_anon_const_diagnostics.stderr12
3 files changed, 36 insertions, 0 deletions
diff --git a/tests/ui/const-generics/generic_const_exprs/auxiliary/anon_const_non_local.rs b/tests/ui/const-generics/generic_const_exprs/auxiliary/anon_const_non_local.rs
new file mode 100644
index 00000000000..97be074933d
--- /dev/null
+++ b/tests/ui/const-generics/generic_const_exprs/auxiliary/anon_const_non_local.rs
@@ -0,0 +1,8 @@
+#![feature(generic_const_exprs)]
+#![allow(incomplete_features)]
+
+pub struct Foo<const N: usize>;
+
+pub fn foo<const N: usize>() -> Foo<{ N + 1 }> {
+    Foo
+}
diff --git a/tests/ui/const-generics/generic_const_exprs/non_local_anon_const_diagnostics.rs b/tests/ui/const-generics/generic_const_exprs/non_local_anon_const_diagnostics.rs
new file mode 100644
index 00000000000..1254b4435f7
--- /dev/null
+++ b/tests/ui/const-generics/generic_const_exprs/non_local_anon_const_diagnostics.rs
@@ -0,0 +1,16 @@
+// aux-build:anon_const_non_local.rs
+
+#![feature(generic_const_exprs)]
+#![allow(incomplete_features)]
+
+extern crate anon_const_non_local;
+
+fn bar<const M: usize>()
+where
+    [(); M + 1]:,
+{
+    let _: anon_const_non_local::Foo<2> = anon_const_non_local::foo::<M>();
+    //~^ ERROR: mismatched types
+}
+
+fn main() {}
diff --git a/tests/ui/const-generics/generic_const_exprs/non_local_anon_const_diagnostics.stderr b/tests/ui/const-generics/generic_const_exprs/non_local_anon_const_diagnostics.stderr
new file mode 100644
index 00000000000..c18281beb05
--- /dev/null
+++ b/tests/ui/const-generics/generic_const_exprs/non_local_anon_const_diagnostics.stderr
@@ -0,0 +1,12 @@
+error[E0308]: mismatched types
+  --> $DIR/non_local_anon_const_diagnostics.rs:12:43
+   |
+LL |     let _: anon_const_non_local::Foo<2> = anon_const_non_local::foo::<M>();
+   |                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `2`, found `_`
+   |
+   = note: expected constant `2`
+              found constant `_`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.