about summary refs log tree commit diff
path: root/tests/ui/const-generics/generic_const_exprs
diff options
context:
space:
mode:
authorOli Scherer <github333195615777966@oli-obk.de>2025-01-07 12:33:32 +0000
committerOli Scherer <github333195615777966@oli-obk.de>2025-01-09 08:48:00 +0000
commit07fcead0732d9460978dd3b428cd5edcfa299f9a (patch)
treeb87dde24347f43c54345023c0db5de75af59b3fb /tests/ui/const-generics/generic_const_exprs
parent787af97babcb911f2ce70d3d28959cdccc7901bd (diff)
downloadrust-07fcead0732d9460978dd3b428cd5edcfa299f9a.tar.gz
rust-07fcead0732d9460978dd3b428cd5edcfa299f9a.zip
Always take the `Ok` path in `lit_to_const` and produce error constants instead
Diffstat (limited to 'tests/ui/const-generics/generic_const_exprs')
-rw-r--r--tests/ui/const-generics/generic_const_exprs/lit_type_mismatch.rs22
-rw-r--r--tests/ui/const-generics/generic_const_exprs/lit_type_mismatch.stderr21
2 files changed, 43 insertions, 0 deletions
diff --git a/tests/ui/const-generics/generic_const_exprs/lit_type_mismatch.rs b/tests/ui/const-generics/generic_const_exprs/lit_type_mismatch.rs
new file mode 100644
index 00000000000..1ed0965e1bd
--- /dev/null
+++ b/tests/ui/const-generics/generic_const_exprs/lit_type_mismatch.rs
@@ -0,0 +1,22 @@
+//! ICE regression test for #114317 and #126182
+//! Type mismatches of literals cause errors int typeck,
+//! but those errors cannot be propagated to the various
+//! `lit_to_const` call sites. Now `lit_to_const` just delays
+//! a bug and produces an error constant on its own.
+
+#![feature(adt_const_params)]
+#![feature(generic_const_exprs)]
+#![allow(incomplete_features)]
+
+struct A<const B: () = 1, C>(C);
+//~^ ERROR: generic parameters with a default must be trailing
+//~| ERROR: mismatched types
+
+struct Cond<const B: bool>;
+
+struct Thing<T = Cond<0>>(T);
+//~^ ERROR: mismatched types
+
+impl Thing {}
+
+fn main() {}
diff --git a/tests/ui/const-generics/generic_const_exprs/lit_type_mismatch.stderr b/tests/ui/const-generics/generic_const_exprs/lit_type_mismatch.stderr
new file mode 100644
index 00000000000..e4613e498b2
--- /dev/null
+++ b/tests/ui/const-generics/generic_const_exprs/lit_type_mismatch.stderr
@@ -0,0 +1,21 @@
+error: generic parameters with a default must be trailing
+  --> $DIR/lit_type_mismatch.rs:11:16
+   |
+LL | struct A<const B: () = 1, C>(C);
+   |                ^
+
+error[E0308]: mismatched types
+  --> $DIR/lit_type_mismatch.rs:11:24
+   |
+LL | struct A<const B: () = 1, C>(C);
+   |                        ^ expected `()`, found integer
+
+error[E0308]: mismatched types
+  --> $DIR/lit_type_mismatch.rs:17:23
+   |
+LL | struct Thing<T = Cond<0>>(T);
+   |                       ^ expected `bool`, found integer
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0308`.