Skip to content

Commit 356d683

Browse files
committed
Also place method impl trait into the surrounding module
1 parent 1bf351d commit 356d683

File tree

1 file changed

+49
-30
lines changed

1 file changed

+49
-30
lines changed

src/librustc/hir/lowering.rs

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2785,6 +2785,45 @@ impl<'a> LoweringContext<'a> {
27852785
}
27862786
}
27872787

2788+
/// Lowers `impl Trait` items and appends them to the list
2789+
fn lower_impl_trait_ids(
2790+
&mut self,
2791+
decl: &FnDecl,
2792+
ids: &mut SmallVector<hir::ItemId>,
2793+
) {
2794+
struct IdVisitor<'a> { ids: &'a mut SmallVector<hir::ItemId> }
2795+
impl<'a, 'b> Visitor<'a> for IdVisitor<'b> {
2796+
fn visit_ty(&mut self, ty: &'a Ty) {
2797+
match ty.node {
2798+
| TyKind::Typeof(_)
2799+
| TyKind::BareFn(_)
2800+
=> return,
2801+
2802+
TyKind::ImplTrait(id, _) => self.ids.push(hir::ItemId { id }),
2803+
_ => {},
2804+
}
2805+
visit::walk_ty(self, ty);
2806+
}
2807+
fn visit_path_segment(
2808+
&mut self,
2809+
path_span: Span,
2810+
path_segment: &'v PathSegment,
2811+
) {
2812+
if let Some(ref p) = path_segment.parameters {
2813+
if let PathParameters::Parenthesized(..) = **p {
2814+
return;
2815+
}
2816+
}
2817+
visit::walk_path_segment(self, path_span, path_segment)
2818+
}
2819+
}
2820+
let mut visitor = IdVisitor { ids };
2821+
match decl.output {
2822+
FunctionRetTy::Default(_) => {},
2823+
FunctionRetTy::Ty(ref ty) => visitor.visit_ty(ty),
2824+
}
2825+
}
2826+
27882827
fn lower_item_id(&mut self, i: &Item) -> SmallVector<hir::ItemId> {
27892828
match i.node {
27902829
ItemKind::Use(ref use_tree) => {
@@ -2794,38 +2833,18 @@ impl<'a> LoweringContext<'a> {
27942833
}
27952834
ItemKind::MacroDef(..) => SmallVector::new(),
27962835
ItemKind::Fn(ref decl, ..) => {
2797-
struct IdVisitor { ids: SmallVector<hir::ItemId> }
2798-
impl<'a> Visitor<'a> for IdVisitor {
2799-
fn visit_ty(&mut self, ty: &'a Ty) {
2800-
match ty.node {
2801-
| TyKind::Typeof(_)
2802-
| TyKind::BareFn(_)
2803-
=> return,
2804-
2805-
TyKind::ImplTrait(id, _) => self.ids.push(hir::ItemId { id }),
2806-
_ => {},
2807-
}
2808-
visit::walk_ty(self, ty);
2809-
}
2810-
fn visit_path_segment(
2811-
&mut self,
2812-
path_span: Span,
2813-
path_segment: &'v PathSegment,
2814-
) {
2815-
if let Some(ref p) = path_segment.parameters {
2816-
if let PathParameters::Parenthesized(..) = **p {
2817-
return;
2818-
}
2819-
}
2820-
visit::walk_path_segment(self, path_span, path_segment)
2836+
let mut ids = SmallVector::one(hir::ItemId { id: i.id });
2837+
self.lower_impl_trait_ids(decl, &mut ids);
2838+
ids
2839+
},
2840+
ItemKind::Impl(.., ref items) => {
2841+
let mut ids = SmallVector::one(hir::ItemId { id: i.id });
2842+
for item in items {
2843+
if let ImplItemKind::Method(ref sig, _) = item.node {
2844+
self.lower_impl_trait_ids(&sig.decl, &mut ids);
28212845
}
28222846
}
2823-
let mut visitor = IdVisitor { ids: SmallVector::one(hir::ItemId { id: i.id }) };
2824-
match decl.output {
2825-
FunctionRetTy::Default(_) => {},
2826-
FunctionRetTy::Ty(ref ty) => visitor.visit_ty(ty),
2827-
}
2828-
visitor.ids
2847+
ids
28292848
},
28302849
_ => SmallVector::one(hir::ItemId { id: i.id }),
28312850
}

0 commit comments

Comments
 (0)