From 6f833aa057f7db01dcdc919c66bbd0a179c58ad4 Mon Sep 17 00:00:00 2001
From: Ross Sullivan <rosssullivan101@gmail.com>
Date: Sun, 12 Jan 2025 12:19:42 +0900
Subject: [PATCH] re-added regression test for #122638

---
 ...malizing_with_unconstrained_impl_params.rs | 18 ++++++
 ...zing_with_unconstrained_impl_params.stderr | 60 +++++++++++++++++++
 2 files changed, 78 insertions(+)
 create mode 100644 tests/ui/const-generics/normalizing_with_unconstrained_impl_params.rs
 create mode 100644 tests/ui/const-generics/normalizing_with_unconstrained_impl_params.stderr

diff --git a/tests/ui/const-generics/normalizing_with_unconstrained_impl_params.rs b/tests/ui/const-generics/normalizing_with_unconstrained_impl_params.rs
new file mode 100644
index 0000000000000..ba37087135fe6
--- /dev/null
+++ b/tests/ui/const-generics/normalizing_with_unconstrained_impl_params.rs
@@ -0,0 +1,18 @@
+//! Regression test for <https://github.com/rust-lang/rust/issues/122638>.
+//@ check-fail
+#![feature(min_specialization)]
+impl<'a, T: std::fmt::Debug, const N: usize> Iterator for ConstChunksExact<'a, T, { N }> {
+    //~^ ERROR not all trait items implemented, missing: `Item` [E0046]
+    fn next(&mut self) -> Option<Self::Item> {}
+    //~^ ERROR mismatched types [E0308]
+}
+struct ConstChunksExact<'a, T: '_, const assert: usize> {}
+//~^ ERROR `'_` cannot be used here [E0637]
+//~| ERROR lifetime parameter `'a` is never used [E0392]
+//~| ERROR type parameter `T` is never used [E0392]
+impl<'a, T: std::fmt::Debug, const N: usize> Iterator for ConstChunksExact<'a, T, {}> {
+    //~^ ERROR mismatched types [E0308]
+    //~| ERROR the const parameter `N` is not constrained by the impl trait, self type, or predicates [E0207]
+    type Item = &'a [T; N]; }
+
+fn main() {}
diff --git a/tests/ui/const-generics/normalizing_with_unconstrained_impl_params.stderr b/tests/ui/const-generics/normalizing_with_unconstrained_impl_params.stderr
new file mode 100644
index 0000000000000..1ee6864759471
--- /dev/null
+++ b/tests/ui/const-generics/normalizing_with_unconstrained_impl_params.stderr
@@ -0,0 +1,60 @@
+error[E0637]: `'_` cannot be used here
+  --> $DIR/normalizing_with_unconstrained_impl_params.rs:9:32
+   |
+LL | struct ConstChunksExact<'a, T: '_, const assert: usize> {}
+   |                                ^^ `'_` is a reserved lifetime name
+
+error[E0308]: mismatched types
+  --> $DIR/normalizing_with_unconstrained_impl_params.rs:13:83
+   |
+LL | impl<'a, T: std::fmt::Debug, const N: usize> Iterator for ConstChunksExact<'a, T, {}> {
+   |                                                                                   ^^ expected `usize`, found `()`
+
+error[E0046]: not all trait items implemented, missing: `Item`
+  --> $DIR/normalizing_with_unconstrained_impl_params.rs:4:1
+   |
+LL | impl<'a, T: std::fmt::Debug, const N: usize> Iterator for ConstChunksExact<'a, T, { N }> {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Item` in implementation
+   |
+   = help: implement the missing item: `type Item = /* Type */;`
+
+error[E0392]: lifetime parameter `'a` is never used
+  --> $DIR/normalizing_with_unconstrained_impl_params.rs:9:25
+   |
+LL | struct ConstChunksExact<'a, T: '_, const assert: usize> {}
+   |                         ^^ unused lifetime parameter
+   |
+   = help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData`
+
+error[E0392]: type parameter `T` is never used
+  --> $DIR/normalizing_with_unconstrained_impl_params.rs:9:29
+   |
+LL | struct ConstChunksExact<'a, T: '_, const assert: usize> {}
+   |                             ^ unused type parameter
+   |
+   = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
+
+error[E0207]: the const parameter `N` is not constrained by the impl trait, self type, or predicates
+  --> $DIR/normalizing_with_unconstrained_impl_params.rs:13:30
+   |
+LL | impl<'a, T: std::fmt::Debug, const N: usize> Iterator for ConstChunksExact<'a, T, {}> {
+   |                              ^^^^^^^^^^^^^^ unconstrained const parameter
+   |
+   = note: expressions using a const parameter must map each value to a distinct output value
+   = note: proving the result of expressions other than the parameter are unique is not supported
+
+error[E0308]: mismatched types
+  --> $DIR/normalizing_with_unconstrained_impl_params.rs:6:27
+   |
+LL |     fn next(&mut self) -> Option<Self::Item> {}
+   |        ----               ^^^^^^^^^^^^^^^^^^ expected `Option<_>`, found `()`
+   |        |
+   |        implicitly returns `()` as its body has no tail or `return` expression
+   |
+   = note:   expected enum `Option<_>`
+           found unit type `()`
+
+error: aborting due to 7 previous errors
+
+Some errors have detailed explanations: E0046, E0207, E0308, E0392, E0637.
+For more information about an error, try `rustc --explain E0046`.