File tree 1 file changed +11
-3
lines changed
1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -1057,11 +1057,19 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::Generics {
1057
1057
ItemKind :: OpaqueTy ( hir:: OpaqueTy { impl_trait_fn, .. } ) => {
1058
1058
impl_trait_fn. or_else ( || {
1059
1059
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>>`)
1062
1060
if parent_id != hir_id && parent_id != CRATE_HIR_ID {
1063
1061
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
+ }
1065
1073
} else {
1066
1074
None
1067
1075
}
You can’t perform that action at this time.
0 commit comments