diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 5821977391b..843872d0ff9 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1673,8 +1673,15 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { ty::Param(_) => true, _ => false, }; - let bad_substs: Vec<_> = - substs.types().enumerate().filter(|(_, ty)| !is_param(ty)).collect(); + let bad_substs: Vec<_> = substs + .iter() + .enumerate() + .filter_map(|(i, k)| { + if let GenericArgKind::Type(ty) = k.unpack() { Some((i, ty)) } else { None } + }) + .filter(|(_, ty)| !is_param(ty)) + .collect(); + if !bad_substs.is_empty() { let identity_substs = InternalSubsts::identity_for_item(self.tcx, self.def_id); for (i, bad_subst) in bad_substs { diff --git a/src/test/ui/type-alias-impl-trait/issue-68368-non-defining-use.rs b/src/test/ui/type-alias-impl-trait/issue-68368-non-defining-use.rs new file mode 100644 index 00000000000..d00f8d7a901 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/issue-68368-non-defining-use.rs @@ -0,0 +1,13 @@ +// Regression test for issue #68368 +// Ensures that we don't ICE when emitting an error +// for a non-defining use when lifetimes are involved + +#![feature(type_alias_impl_trait)] +trait Trait {} +type Alias<'a, U> = impl Trait; //~ ERROR could not find defining uses +fn f<'a>() -> Alias<'a, ()> {} +//~^ ERROR defining opaque type use does not fully define opaque type: generic parameter `U` + +fn main() {} + +impl Trait<()> for () {} diff --git a/src/test/ui/type-alias-impl-trait/issue-68368-non-defining-use.stderr b/src/test/ui/type-alias-impl-trait/issue-68368-non-defining-use.stderr new file mode 100644 index 00000000000..b585942406f --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/issue-68368-non-defining-use.stderr @@ -0,0 +1,14 @@ +error: defining opaque type use does not fully define opaque type: generic parameter `U` is specified as concrete type `()` + --> $DIR/issue-68368-non-defining-use.rs:8:1 + | +LL | fn f<'a>() -> Alias<'a, ()> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: could not find defining uses + --> $DIR/issue-68368-non-defining-use.rs:7:1 + | +LL | type Alias<'a, U> = impl Trait; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors +