Skip to content

Commit 2ec5eab

Browse files
committed
Also place method impl trait into the surrounding module
1 parent 1b20242 commit 2ec5eab

File tree

1 file changed

+49
-13
lines changed

1 file changed

+49
-13
lines changed

src/librustc/hir/lowering.rs

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3076,6 +3076,45 @@ impl<'a> LoweringContext<'a> {
30763076
}
30773077
}
30783078

3079+
/// Lowers `impl Trait` items and appends them to the list
3080+
fn lower_impl_trait_ids(
3081+
&mut self,
3082+
decl: &FnDecl,
3083+
ids: &mut SmallVector<hir::ItemId>,
3084+
) {
3085+
struct IdVisitor<'a> { ids: &'a mut SmallVector<hir::ItemId> }
3086+
impl<'a, 'b> Visitor<'a> for IdVisitor<'b> {
3087+
fn visit_ty(&mut self, ty: &'a Ty) {
3088+
match ty.node {
3089+
| TyKind::Typeof(_)
3090+
| TyKind::BareFn(_)
3091+
=> return,
3092+
3093+
TyKind::ImplTrait(id, _) => self.ids.push(hir::ItemId { id }),
3094+
_ => {},
3095+
}
3096+
visit::walk_ty(self, ty);
3097+
}
3098+
fn visit_path_segment(
3099+
&mut self,
3100+
path_span: Span,
3101+
path_segment: &'v PathSegment,
3102+
) {
3103+
if let Some(ref p) = path_segment.parameters {
3104+
if let PathParameters::Parenthesized(..) = **p {
3105+
return;
3106+
}
3107+
}
3108+
visit::walk_path_segment(self, path_span, path_segment)
3109+
}
3110+
}
3111+
let mut visitor = IdVisitor { ids };
3112+
match decl.output {
3113+
FunctionRetTy::Default(_) => {},
3114+
FunctionRetTy::Ty(ref ty) => visitor.visit_ty(ty),
3115+
}
3116+
}
3117+
30793118
fn lower_item_id(&mut self, i: &Item) -> SmallVector<hir::ItemId> {
30803119
match i.node {
30813120
ItemKind::Use(ref use_tree) => {
@@ -3085,21 +3124,18 @@ impl<'a> LoweringContext<'a> {
30853124
}
30863125
ItemKind::MacroDef(..) => SmallVector::new(),
30873126
ItemKind::Fn(ref decl, ..) => {
3088-
struct IdVisitor { ids: SmallVector<hir::ItemId> }
3089-
impl<'a> Visitor<'a> for IdVisitor {
3090-
fn visit_ty(&mut self, ty: &'a Ty) {
3091-
if let TyKind::ImplTrait(id, _) = ty.node {
3092-
self.ids.push(hir::ItemId { id });
3093-
}
3094-
visit::walk_ty(self, ty);
3127+
let mut ids = SmallVector::one(hir::ItemId { id: i.id });
3128+
self.lower_impl_trait_ids(decl, &mut ids);
3129+
ids
3130+
},
3131+
ItemKind::Impl(.., ref items) => {
3132+
let mut ids = SmallVector::one(hir::ItemId { id: i.id });
3133+
for item in items {
3134+
if let ImplItemKind::Method(ref sig, _) = item.node {
3135+
self.lower_impl_trait_ids(&sig.decl, &mut ids);
30953136
}
30963137
}
3097-
let mut visitor = IdVisitor { ids: SmallVector::one(hir::ItemId { id: i.id }) };
3098-
match decl.output {
3099-
FunctionRetTy::Default(_) => {},
3100-
FunctionRetTy::Ty(ref ty) => visitor.visit_ty(ty),
3101-
}
3102-
visitor.ids
3138+
ids
31033139
},
31043140
_ => SmallVector::one(hir::ItemId { id: i.id }),
31053141
}

0 commit comments

Comments
 (0)