Rollup merge of #68438 - Aaron1011:fix/tait-non-defining, r=estebank

Account for non-types in substs for opaque type error messages

Fixes #68368

Previously, I assumed that the substs contained only types, which caused
the computed index number to be wrong.
This commit is contained in:
Tyler Mandry 2020-01-24 00:30:55 -08:00 committed by GitHub
commit 143059deaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 2 deletions

View File

@ -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 {

View File

@ -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<T> {}
type Alias<'a, U> = impl Trait<U>; //~ 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 () {}

View File

@ -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<U>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors