Skip to content

Commit 34cf0b3

Browse files
committed
Only use the parent if it's an opaque type
1 parent a60669d commit 34cf0b3

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/librustc_typeck/collect.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -1057,11 +1057,19 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::Generics {
10571057
ItemKind::OpaqueTy(hir::OpaqueTy { impl_trait_fn, .. }) => {
10581058
impl_trait_fn.or_else(|| {
10591059
let parent_id = tcx.hir().get_parent_item(hir_id);
1060-
// This opaque type might occur inside another opaque type
1061-
// (e.g. `impl Foo<MyType = impl Bar<A>>`)
10621060
if parent_id != hir_id && parent_id != CRATE_HIR_ID {
10631061
debug!("generics_of: parent of opaque ty {:?} is {:?}", def_id, parent_id);
1064-
Some(tcx.hir().local_def_id(parent_id))
1062+
// If this 'impl Trait' is nested inside another 'impl Trait'
1063+
// (e.g. `impl Foo<MyType = impl Bar<A>>`), we need to use the 'parent'
1064+
// 'impl Trait' for its generic parameters, since we can reference them
1065+
// from the 'child' 'impl Trait'
1066+
if let Node::Item(hir::Item { kind: ItemKind::OpaqueTy(..), .. }) =
1067+
tcx.hir().get(parent_id)
1068+
{
1069+
Some(tcx.hir().local_def_id(parent_id))
1070+
} else {
1071+
None
1072+
}
10651073
} else {
10661074
None
10671075
}

0 commit comments

Comments
 (0)