about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorBoxy <supbscripter@gmail.com>2024-06-10 14:32:50 +0100
committerBoxy <supbscripter@gmail.com>2024-06-10 14:32:50 +0100
commitbfb7757c3c059d3bbcfbc604ab326fa777be13aa (patch)
tree583eaffc39fc265a5b5f48b334fc83bd4d0eef1b /tests
parentd2fb97fceccb7b7d71c40cc2d3c9b376fd2883aa (diff)
Correct parent for nested anon consts
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/const-generics/repeat_expr_hack_gives_right_generics.rs20
-rw-r--r--tests/ui/const-generics/repeat_expr_hack_gives_right_generics.stderr11
2 files changed, 31 insertions, 0 deletions
diff --git a/tests/ui/const-generics/repeat_expr_hack_gives_right_generics.rs b/tests/ui/const-generics/repeat_expr_hack_gives_right_generics.rs
new file mode 100644
index 00000000000..899db191ae7
--- /dev/null
+++ b/tests/ui/const-generics/repeat_expr_hack_gives_right_generics.rs
@@ -0,0 +1,20 @@
+// Given an anon const `a`: `{ N }` and some anon const `b` which references the
+// first anon const: `{ [1; a] }`. `b` should not have any generics as it is not
+// a simple `N` argument nor is it a repeat expr count.
+//
+// On the other hand `b` *is* a repeat expr count and so it should inherit its
+// parents generics as part of the `const_evaluatable_unchecked` fcw (#76200).
+//
+// In this specific case however `b`'s parent should be `a` and so it should wind
+// up not having any generics after all. If `a` were to inherit its generics from
+// the enclosing item then the reference to `a` from `b` would contain generic
+// parameters not usable by `b` which would cause us to ICE.
+
+fn bar<const N: usize>() {}
+
+fn foo<const N: usize>() {
+    bar::<{ [1; N] }>();
+    //~^ ERROR: generic parameters may not be used in const operations
+}
+
+fn main() {}
diff --git a/tests/ui/const-generics/repeat_expr_hack_gives_right_generics.stderr b/tests/ui/const-generics/repeat_expr_hack_gives_right_generics.stderr
new file mode 100644
index 00000000000..64548cc5a30
--- /dev/null
+++ b/tests/ui/const-generics/repeat_expr_hack_gives_right_generics.stderr
@@ -0,0 +1,11 @@
+error: generic parameters may not be used in const operations
+  --> $DIR/repeat_expr_hack_gives_right_generics.rs:16:17
+   |
+LL |     bar::<{ [1; N] }>();
+   |                 ^ cannot perform const operation using `N`
+   |
+   = help: const parameters may only be used as standalone arguments, i.e. `N`
+   = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
+
+error: aborting due to 1 previous error
+