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 0000000000000..f90ff91aff4bb --- /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() -> 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 0000000000000..d45c4cba1f8b5 --- /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() -> 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`.