Some(tcx.closure_base_def_id(def_id))
}
Node::Item(item) => match item.kind {
- ItemKind::OpaqueTy(hir::OpaqueTy { impl_trait_fn, .. }) => impl_trait_fn,
+ ItemKind::OpaqueTy(hir::OpaqueTy { impl_trait_fn, .. }) => {
+ impl_trait_fn.or_else(|| {
+ let parent_id = tcx.hir().get_parent_item(hir_id);
+ // This opaque type might occur inside another opaque type
+ // (e.g. `impl Foo<MyType = impl Bar<A>>`)
+ if parent_id != hir_id && parent_id != CRATE_HIR_ID {
+ debug!("generics_of: parent of opaque ty {:?} is {:?}", def_id, parent_id);
+ Some(tcx.hir().local_def_id(parent_id))
+ } else {
+ None
+ }
+ })
+ }
_ => None,
},
_ => None,
--- /dev/null
+// check-pass
+// Regression test for issue #67844
+// Ensures that we properly handle nested TAIT occurences
+// with generic parameters
+
+#![feature(type_alias_impl_trait)]
+
+trait WithAssoc { type AssocType; }
+
+trait WithParam<A> {}
+
+type Return<A> = impl WithAssoc<AssocType = impl WithParam<A>>;
+
+struct MyParam;
+impl<A> WithParam<A> for MyParam {}
+
+struct MyStruct;
+
+impl WithAssoc for MyStruct {
+ type AssocType = MyParam;
+}
+
+
+fn my_fun<A>() -> Return<A> {
+ MyStruct
+}
+
+fn my_other_fn<A>() -> impl WithAssoc<AssocType = impl WithParam<A>> {
+ MyStruct
+}
+
+fn main() {}