Rollup merge of #152792 - ShoyuVanilla:issue-152663, r=petrochenkov
Fix an ICE while checking param env shadowing on an erroneous trait impl Fixes https://github.com/rust-lang/rust/issues/152663
This commit is contained in:
commit
506327e61c
3 changed files with 56 additions and 0 deletions
|
|
@ -299,6 +299,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
let trait_def_id = alias.trait_def_id(tcx);
|
||||
let rebased_args = alias.args.rebase_onto(tcx, trait_def_id, impl_substs);
|
||||
|
||||
// The impl is erroneous missing a definition for the associated type.
|
||||
// Skipping it since calling `TyCtxt::type_of` on its assoc ty will trigger an ICE.
|
||||
if !leaf_def.item.defaultness(tcx).has_value() {
|
||||
return false;
|
||||
}
|
||||
|
||||
let impl_item_def_id = leaf_def.item.def_id;
|
||||
if !tcx.check_args_compatible(impl_item_def_id, rebased_args) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
// A regression test for https://github.com/rust-lang/rust/issues/152663
|
||||
// Previously triggered an ICE when checking whether the param-env
|
||||
// shadows a global impl. The crash occurred due to calling
|
||||
// `TyCtxt::type_of` on an erroneous associated type in a trait impl
|
||||
// that had no corresponding value.
|
||||
|
||||
trait Iterable {
|
||||
type Iter;
|
||||
}
|
||||
|
||||
impl<T> Iterable for [T] {
|
||||
//~^ ERROR: not all trait items implemented
|
||||
fn iter() -> Self::Iter {}
|
||||
//~^ ERROR: method `iter` is not a member of trait `Iterable`
|
||||
//~| ERROR: mismatched types
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
error[E0407]: method `iter` is not a member of trait `Iterable`
|
||||
--> $DIR/param-env-shadowing-suggestion-no-ice-on-missing-assoc-value.rs:13:5
|
||||
|
|
||||
LL | fn iter() -> Self::Iter {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ not a member of trait `Iterable`
|
||||
|
||||
error[E0046]: not all trait items implemented, missing: `Iter`
|
||||
--> $DIR/param-env-shadowing-suggestion-no-ice-on-missing-assoc-value.rs:11:1
|
||||
|
|
||||
LL | type Iter;
|
||||
| --------- `Iter` from trait
|
||||
...
|
||||
LL | impl<T> Iterable for [T] {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ missing `Iter` in implementation
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/param-env-shadowing-suggestion-no-ice-on-missing-assoc-value.rs:13:18
|
||||
|
|
||||
LL | fn iter() -> Self::Iter {}
|
||||
| ---- ^^^^^^^^^^ expected associated type, found `()`
|
||||
| |
|
||||
| implicitly returns `()` as its body has no tail or `return` expression
|
||||
|
|
||||
= note: expected associated type `<[T] as Iterable>::Iter`
|
||||
found unit type `()`
|
||||
= help: consider constraining the associated type `<[T] as Iterable>::Iter` to `()` or calling a method that returns `<[T] as Iterable>::Iter`
|
||||
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0046, E0308, E0407.
|
||||
For more information about an error, try `rustc --explain E0046`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue