diff options
| author | Oliver Schneider <github35764891676564198441@oli-obk.de> | 2018-06-22 12:03:44 +0200 |
|---|---|---|
| committer | Oliver Schneider <github35764891676564198441@oli-obk.de> | 2018-06-27 11:17:55 +0200 |
| commit | 2ec5eab368b3320950007b07b00600b9a981827a (patch) | |
| tree | fe06e724f3b9218495db45e627e4442e057bd431 | |
| parent | 1b202426dcac3febc06b89a9ceecc8eb47db59e8 (diff) | |
| download | rust-2ec5eab368b3320950007b07b00600b9a981827a.tar.gz rust-2ec5eab368b3320950007b07b00600b9a981827a.zip | |
Also place method impl trait into the surrounding module
| -rw-r--r-- | src/librustc/hir/lowering.rs | 62 |
1 files changed, 49 insertions, 13 deletions
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index a21d2b69135..b7260dded92 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -3076,6 +3076,45 @@ impl<'a> LoweringContext<'a> { } } + /// Lowers `impl Trait` items and appends them to the list + fn lower_impl_trait_ids( + &mut self, + decl: &FnDecl, + ids: &mut SmallVector<hir::ItemId>, + ) { + struct IdVisitor<'a> { ids: &'a mut SmallVector<hir::ItemId> } + impl<'a, 'b> Visitor<'a> for IdVisitor<'b> { + fn visit_ty(&mut self, ty: &'a Ty) { + match ty.node { + | TyKind::Typeof(_) + | TyKind::BareFn(_) + => return, + + TyKind::ImplTrait(id, _) => self.ids.push(hir::ItemId { id }), + _ => {}, + } + visit::walk_ty(self, ty); + } + fn visit_path_segment( + &mut self, + path_span: Span, + path_segment: &'v PathSegment, + ) { + if let Some(ref p) = path_segment.parameters { + if let PathParameters::Parenthesized(..) = **p { + return; + } + } + visit::walk_path_segment(self, path_span, path_segment) + } + } + let mut visitor = IdVisitor { ids }; + match decl.output { + FunctionRetTy::Default(_) => {}, + FunctionRetTy::Ty(ref ty) => visitor.visit_ty(ty), + } + } + fn lower_item_id(&mut self, i: &Item) -> SmallVector<hir::ItemId> { match i.node { ItemKind::Use(ref use_tree) => { @@ -3085,21 +3124,18 @@ impl<'a> LoweringContext<'a> { } ItemKind::MacroDef(..) => SmallVector::new(), ItemKind::Fn(ref decl, ..) => { - struct IdVisitor { ids: SmallVector<hir::ItemId> } - impl<'a> Visitor<'a> for IdVisitor { - fn visit_ty(&mut self, ty: &'a Ty) { - if let TyKind::ImplTrait(id, _) = ty.node { - self.ids.push(hir::ItemId { id }); - } - visit::walk_ty(self, ty); + let mut ids = SmallVector::one(hir::ItemId { id: i.id }); + self.lower_impl_trait_ids(decl, &mut ids); + ids + }, + ItemKind::Impl(.., ref items) => { + let mut ids = SmallVector::one(hir::ItemId { id: i.id }); + for item in items { + if let ImplItemKind::Method(ref sig, _) = item.node { + self.lower_impl_trait_ids(&sig.decl, &mut ids); } } - let mut visitor = IdVisitor { ids: SmallVector::one(hir::ItemId { id: i.id }) }; - match decl.output { - FunctionRetTy::Default(_) => {}, - FunctionRetTy::Ty(ref ty) => visitor.visit_ty(ty), - } - visitor.ids + ids }, _ => SmallVector::one(hir::ItemId { id: i.id }), } |
