Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2020
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
11 changes: 9 additions & 2 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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 () {}
Original file line number Diff line number Diff line change
@@ -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