Skip to content

Commit 09c65b0

Browse files
committed
Auto 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.
2 parents e0bbe79 + 4ee4287 commit 09c65b0

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

src/librustc_typeck/collect.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1673,8 +1673,15 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
16731673
ty::Param(_) => true,
16741674
_ => false,
16751675
};
1676-
let bad_substs: Vec<_> =
1677-
substs.types().enumerate().filter(|(_, ty)| !is_param(ty)).collect();
1676+
let bad_substs: Vec<_> = substs
1677+
.iter()
1678+
.enumerate()
1679+
.filter_map(|(i, k)| {
1680+
if let GenericArgKind::Type(ty) = k.unpack() { Some((i, ty)) } else { None }
1681+
})
1682+
.filter(|(_, ty)| !is_param(ty))
1683+
.collect();
1684+
16781685
if !bad_substs.is_empty() {
16791686
let identity_substs = InternalSubsts::identity_for_item(self.tcx, self.def_id);
16801687
for (i, bad_subst) in bad_substs {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Regression test for issue #68368
2+
// Ensures that we don't ICE when emitting an error
3+
// for a non-defining use when lifetimes are involved
4+
5+
#![feature(type_alias_impl_trait)]
6+
trait Trait<T> {}
7+
type Alias<'a, U> = impl Trait<U>; //~ ERROR could not find defining uses
8+
fn f<'a>() -> Alias<'a, ()> {}
9+
//~^ ERROR defining opaque type use does not fully define opaque type: generic parameter `U`
10+
11+
fn main() {}
12+
13+
impl Trait<()> for () {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: defining opaque type use does not fully define opaque type: generic parameter `U` is specified as concrete type `()`
2+
--> $DIR/issue-68368-non-defining-use.rs:8:1
3+
|
4+
LL | fn f<'a>() -> Alias<'a, ()> {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: could not find defining uses
8+
--> $DIR/issue-68368-non-defining-use.rs:7:1
9+
|
10+
LL | type Alias<'a, U> = impl Trait<U>;
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to 2 previous errors
14+

0 commit comments

Comments
 (0)