Rollup merge of #152745 - TaKO8Ki:fix-ice-suggest-param-env-shadowing-incompatible-args, r=Kivooeo

Fix ICE in `suggest_param_env_shadowing` with incompatible args

Fixes rust-lang/rust#152684
This commit is contained in:
Stuart Cook 2026-02-18 17:29:49 +11:00 committed by GitHub
commit e8327b0a79
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 41 additions and 0 deletions

View file

@ -300,6 +300,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
let rebased_args = alias.args.rebase_onto(tcx, trait_def_id, impl_substs);
let impl_item_def_id = leaf_def.item.def_id;
if !tcx.check_args_compatible(impl_item_def_id, rebased_args) {
return false;
}
let impl_assoc_ty = tcx.type_of(impl_item_def_id).instantiate(tcx, rebased_args);
self.infcx.can_eq(param_env, impl_assoc_ty, concrete)

View file

@ -0,0 +1,18 @@
//@ compile-flags: -Znext-solver=globally
// Regression test for https://github.com/rust-lang/rust/issues/152684.
#![feature(associated_type_defaults)]
trait Foo {
type Assoc<T = u8> = T;
//~^ ERROR defaults for generic parameters are not allowed here
fn foo() -> Self::Assoc;
}
impl Foo for () {
fn foo() -> Self::Assoc {
[] //~ ERROR mismatched types
}
}
fn main() {}

View file

@ -0,0 +1,20 @@
error: defaults for generic parameters are not allowed here
--> $DIR/suggest-param-env-shadowing-incompatible-args.rs:8:16
|
LL | type Assoc<T = u8> = T;
| ^^^^^^
error[E0308]: mismatched types
--> $DIR/suggest-param-env-shadowing-incompatible-args.rs:14:9
|
LL | fn foo() -> Self::Assoc {
| ----------- expected `<() as Foo>::Assoc` because of return type
LL | []
| ^^ expected `u8`, found `[_; 0]`
|
= note: expected type `u8`
found array `[_; 0]`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0308`.