about summary refs log tree commit diff
diff options
context:
space:
mode:
authorreddevilmidzy <midzy0228@gmail.com>2025-05-09 02:26:01 +0900
committerreddevilmidzy <midzy0228@gmail.com>2025-05-09 03:08:40 +0900
commitb67549edd3535bf6d7fb62fce206466db78fa926 (patch)
treef4f799a1f92f8fd5c912f1e5ccb40a21b3471c08
parente964ccafedcf7a505f90f31370d568e649286176 (diff)
downloadrust-b67549edd3535bf6d7fb62fce206466db78fa926.tar.gz
rust-b67549edd3535bf6d7fb62fce206466db78fa926.zip
Add regression test for 125877
-rw-r--r--tests/ui/traits/const-traits/const-trait-impl-parameter-mismatch.rs32
-rw-r--r--tests/ui/traits/const-traits/const-trait-impl-parameter-mismatch.stderr21
2 files changed, 53 insertions, 0 deletions
diff --git a/tests/ui/traits/const-traits/const-trait-impl-parameter-mismatch.rs b/tests/ui/traits/const-traits/const-trait-impl-parameter-mismatch.rs
new file mode 100644
index 00000000000..f90ff91aff4
--- /dev/null
+++ b/tests/ui/traits/const-traits/const-trait-impl-parameter-mismatch.rs
@@ -0,0 +1,32 @@
+// This test demonstrates an ICE that may occur when we try to resolve the instance
+// of a impl that has different generics than the trait it's implementing. This ensures
+// we first check that the args are compatible before resolving the body, just like
+// we do in projection before substituting a GAT.
+//
+// Regression test for issue #125877.
+
+//@ compile-flags: -Znext-solver
+
+#![feature(const_trait_impl, effects)]
+//~^ ERROR feature has been removed
+
+#[const_trait]
+trait Main {
+    fn compute<T: ~const Aux>() -> u32;
+}
+
+impl const Main for () {
+    fn compute<'x>() -> u32 {
+        //~^ ERROR associated function `compute` has 0 type parameters but its trait declaration has 1 type parameter
+        0
+    }
+}
+
+#[const_trait]
+trait Aux {}
+
+impl const Aux for () {}
+
+fn main() {
+    const _: u32 = <()>::compute::<()>();
+}
diff --git a/tests/ui/traits/const-traits/const-trait-impl-parameter-mismatch.stderr b/tests/ui/traits/const-traits/const-trait-impl-parameter-mismatch.stderr
new file mode 100644
index 00000000000..d45c4cba1f8
--- /dev/null
+++ b/tests/ui/traits/const-traits/const-trait-impl-parameter-mismatch.stderr
@@ -0,0 +1,21 @@
+error[E0557]: feature has been removed
+  --> $DIR/const-trait-impl-parameter-mismatch.rs:10:30
+   |
+LL | #![feature(const_trait_impl, effects)]
+   |                              ^^^^^^^ feature has been removed
+   |
+   = note: removed, redundant with `#![feature(const_trait_impl)]`
+
+error[E0049]: associated function `compute` has 0 type parameters but its trait declaration has 1 type parameter
+  --> $DIR/const-trait-impl-parameter-mismatch.rs:19:16
+   |
+LL |     fn compute<T: ~const Aux>() -> u32;
+   |                - expected 1 type parameter
+...
+LL |     fn compute<'x>() -> u32 {
+   |                ^^ found 0 type parameters
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0049, E0557.
+For more information about an error, try `rustc --explain E0049`.