Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
let impl_assoc_ty = tcx.type_of(impl_item_def_id).instantiate(tcx, rebased_args);

Expand Down
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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