diff options
| author | Aaron Hill <aa1ronham@gmail.com> | 2020-02-10 23:35:49 -0500 |
|---|---|---|
| committer | Aaron Hill <aa1ronham@gmail.com> | 2020-02-10 23:41:16 -0500 |
| commit | 34cf0b32674da79403746716e5a7ed2072dfabe2 (patch) | |
| tree | 561bcb3b1d4e22850a6927fa5bd69a4c2f19acee | |
| parent | a60669d95cdad0e28cf28790b717bbcf235153f8 (diff) | |
| download | rust-34cf0b32674da79403746716e5a7ed2072dfabe2.tar.gz rust-34cf0b32674da79403746716e5a7ed2072dfabe2.zip | |
Only use the parent if it's an opaque type
| -rw-r--r-- | src/librustc_typeck/collect.rs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 49b1bfb72a3..242faebe53e 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1057,11 +1057,19 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::Generics { 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)) + // If this 'impl Trait' is nested inside another 'impl Trait' + // (e.g. `impl Foo<MyType = impl Bar<A>>`), we need to use the 'parent' + // 'impl Trait' for its generic parameters, since we can reference them + // from the 'child' 'impl Trait' + if let Node::Item(hir::Item { kind: ItemKind::OpaqueTy(..), .. }) = + tcx.hir().get(parent_id) + { + Some(tcx.hir().local_def_id(parent_id)) + } else { + None + } } else { None } |
