about summary refs log tree commit diff
path: root/tests/ui/const-generics/generic_const_exprs
diff options
context:
space:
mode:
authorNoah Lev <camelidcamel@gmail.com>2024-08-05 17:26:46 -0700
committerNoah Lev <camelidcamel@gmail.com>2024-08-05 17:37:12 -0700
commit9479792cb4e6bdb0eba18d91af5ba3096c9007df (patch)
tree63145f73731c50c9f92e2c9d412b195e89c5191d /tests/ui/const-generics/generic_const_exprs
parent18906754ccee76cebf92803c487942465c7f79a4 (diff)
downloadrust-9479792cb4e6bdb0eba18d91af5ba3096c9007df.tar.gz
rust-9479792cb4e6bdb0eba18d91af5ba3096c9007df.zip
WF-check struct field types at construction site
Rustc of course already WF-checked the field types at the definition
site, but for error tainting of consts to work properly, there needs to
be an error emitted at the use site. Previously, with no use-site error,
we proceeded with CTFE and ran into ICEs since we are running code with
type errors.

Emitting use-site errors also brings struct-like constructors more in
line with fn-like constructors since they already emit use-site errors
for WF issues.
Diffstat (limited to 'tests/ui/const-generics/generic_const_exprs')
-rw-r--r--tests/ui/const-generics/generic_const_exprs/no_where_clause.rs1
-rw-r--r--tests/ui/const-generics/generic_const_exprs/no_where_clause.stderr13
2 files changed, 13 insertions, 1 deletions
diff --git a/tests/ui/const-generics/generic_const_exprs/no_where_clause.rs b/tests/ui/const-generics/generic_const_exprs/no_where_clause.rs
index 77cce66e4ec..53230469491 100644
--- a/tests/ui/const-generics/generic_const_exprs/no_where_clause.rs
+++ b/tests/ui/const-generics/generic_const_exprs/no_where_clause.rs
@@ -17,6 +17,7 @@ impl<const N: usize> Example<N> {
       a: [0.; N],
       b: [0.; complex_maths(N)],
       //~^ ERROR: unconstrained generic constant
+      //~| ERROR: unconstrained generic constant
     }
   }
 }
diff --git a/tests/ui/const-generics/generic_const_exprs/no_where_clause.stderr b/tests/ui/const-generics/generic_const_exprs/no_where_clause.stderr
index a2680eac039..88fc68a4d1b 100644
--- a/tests/ui/const-generics/generic_const_exprs/no_where_clause.stderr
+++ b/tests/ui/const-generics/generic_const_exprs/no_where_clause.stderr
@@ -10,6 +10,17 @@ LL | pub struct Example<const N: usize> where [(); complex_maths(N)]: {
    |                                    +++++++++++++++++++++++++++++
 
 error: unconstrained generic constant
+  --> $DIR/no_where_clause.rs:18:10
+   |
+LL |       b: [0.; complex_maths(N)],
+   |          ^^^^^^^^^^^^^^^^^^^^^^
+   |
+help: try adding a `where` bound
+   |
+LL |   pub fn new() -> Self where [(); complex_maths(N)]: {
+   |                        +++++++++++++++++++++++++++++
+
+error: unconstrained generic constant
   --> $DIR/no_where_clause.rs:18:15
    |
 LL |       b: [0.; complex_maths(N)],
@@ -20,5 +31,5 @@ help: try adding a `where` bound
 LL |   pub fn new() -> Self where [(); complex_maths(N)]: {
    |                        +++++++++++++++++++++++++++++
 
-error: aborting due to 2 previous errors
+error: aborting due to 3 previous errors