Skip to content

Commit

Permalink
Account for non-types in substs for opaque type error messages
Browse files Browse the repository at this point in the history
Fixes #68368

Previously, I assumed that the substs contained only types, which caused
the computed index number to be wrong.
  • Loading branch information
Aaron1011 committed Jan 21, 2020
1 parent 5e8897b commit 4ee4287
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/librustc_typeck/collect.rs
Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions 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<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 () {}
@@ -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

0 comments on commit 4ee4287

Please sign in to comment.