Skip to content

Commit d5689a2

Browse files
committed
Attach closure and other sub-exprs to outermost expr of a Repeat expr
1 parent de03835 commit d5689a2

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

src/librustc/hir/map/def_collector.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,19 @@ impl<'a> DefCollector<'a> {
7474
self.parent_def = parent;
7575
}
7676

77-
pub fn visit_const_expr(&mut self, expr: &Expr) {
77+
pub fn visit_const_expr(&mut self, expr: &Expr) -> Option<DefIndex> {
7878
match expr.node {
7979
// Find the node which will be used after lowering.
80-
ExprKind::Paren(ref inner) => return self.visit_const_expr(inner),
81-
ExprKind::Mac(..) => return self.visit_macro_invoc(expr.id, true),
80+
ExprKind::Paren(ref inner) => self.visit_const_expr(inner),
81+
ExprKind::Mac(..) => {
82+
self.visit_macro_invoc(expr.id, true);
83+
None
84+
}
8285
// FIXME(eddyb) Closures should have separate
8386
// function definition IDs and expression IDs.
84-
ExprKind::Closure(..) => return,
85-
_ => {}
87+
ExprKind::Closure(..) => None,
88+
_ => Some(self.create_def(expr.id, DefPathData::Initializer, REGULAR_SPACE, expr.span))
8689
}
87-
88-
self.create_def(expr.id, DefPathData::Initializer, REGULAR_SPACE, expr.span);
8990
}
9091

9192
fn visit_macro_invoc(&mut self, id: NodeId, const_expr: bool) {
@@ -268,18 +269,17 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
268269
fn visit_expr(&mut self, expr: &'a Expr) {
269270
let parent_def = self.parent_def;
270271

271-
match expr.node {
272+
self.parent_def = match expr.node {
272273
ExprKind::Mac(..) => return self.visit_macro_invoc(expr.id, false),
273274
ExprKind::Repeat(_, ref count) => self.visit_const_expr(count),
274275
ExprKind::Closure(..) => {
275-
let def = self.create_def(expr.id,
276-
DefPathData::ClosureExpr,
277-
REGULAR_SPACE,
278-
expr.span);
279-
self.parent_def = Some(def);
276+
Some(self.create_def(expr.id,
277+
DefPathData::ClosureExpr,
278+
REGULAR_SPACE,
279+
expr.span))
280280
}
281-
_ => {}
282-
}
281+
_ => None
282+
}.or(self.parent_def);
283283

284284
visit::walk_expr(self, expr);
285285
self.parent_def = parent_def;
@@ -288,11 +288,15 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
288288
fn visit_ty(&mut self, ty: &'a Ty) {
289289
match ty.node {
290290
TyKind::Mac(..) => return self.visit_macro_invoc(ty.id, false),
291-
TyKind::Array(_, ref length) => self.visit_const_expr(length),
291+
TyKind::Array(_, ref length) => {
292+
self.visit_const_expr(length);
293+
}
292294
TyKind::ImplTrait(..) => {
293295
self.create_def(ty.id, DefPathData::ImplTrait, REGULAR_SPACE, ty.span);
294296
}
295-
TyKind::Typeof(ref expr) => self.visit_const_expr(expr),
297+
TyKind::Typeof(ref expr) => {
298+
self.visit_const_expr(expr);
299+
}
296300
_ => {}
297301
}
298302
visit::walk_ty(self, ty);

0 commit comments

Comments
 (0)