From 11f5893610b8511eefde072b580e7f7a286aa422 Mon Sep 17 00:00:00 2001 From: est31 Date: Mon, 16 Apr 2018 05:44:39 +0200 Subject: [PATCH] label-break-value: Parsing and AST/HIR changes --- src/librustc/cfg/construct.rs | 2 +- src/librustc/hir/intravisit.rs | 5 ++++- src/librustc/hir/lowering.rs | 8 ++++--- src/librustc/hir/mod.rs | 4 ++-- src/librustc/hir/print.rs | 16 ++++++++++---- src/librustc/ich/impls_hir.rs | 2 +- src/librustc/middle/expr_use_visitor.rs | 2 +- src/librustc/middle/liveness.rs | 4 +++- src/librustc/middle/region.rs | 2 +- src/librustc_lint/builtin.rs | 2 +- src/librustc_mir/hair/cx/expr.rs | 2 +- src/librustc_mir/transform/add_validation.rs | 2 +- src/librustc_passes/rvalue_promotion.rs | 4 ++-- src/librustc_typeck/check/mod.rs | 4 ++-- src/libsyntax/ast.rs | 6 +++--- src/libsyntax/ext/build.rs | 2 +- src/libsyntax/fold.rs | 5 ++++- src/libsyntax/parse/classify.rs | 2 +- src/libsyntax/parse/parser.rs | 22 +++++++++++++------- src/libsyntax/print/pprust.rs | 15 ++++++++++--- src/libsyntax/visit.rs | 5 ++++- 21 files changed, 77 insertions(+), 39 deletions(-) diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index d8cf147e3ee..7e03288f572 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -179,7 +179,7 @@ fn pats_all<'b, I: Iterator>>(&mut self, fn expr(&mut self, expr: &hir::Expr, pred: CFGIndex) -> CFGIndex { match expr.node { - hir::ExprBlock(ref blk) => { + hir::ExprBlock(ref blk, _) => { let blk_exit = self.block(&blk, pred); self.add_ast_node(expr.hir_id.local_id, &[blk_exit]) } diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 1fb496cca62..59b058e9861 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -1015,7 +1015,10 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { expression.span, expression.id) } - ExprBlock(ref block) => visitor.visit_block(block), + ExprBlock(ref block, ref opt_label) => { + walk_list!(visitor, visit_label, opt_label); + visitor.visit_block(block); + } ExprAssign(ref left_hand_expression, ref right_hand_expression) => { visitor.visit_expr(right_hand_expression); visitor.visit_expr(left_hand_expression) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 7a360f7ee43..09fff64094f 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -3048,7 +3048,7 @@ fn lower_expr(&mut self, e: &Expr) -> hir::Expr { ); block.expr = Some(this.wrap_in_try_constructor( "from_ok", tail, unstable_span)); - hir::ExprBlock(P(block)) + hir::ExprBlock(P(block), None) }) } ExprKind::Match(ref expr, ref arms) => hir::ExprMatch( @@ -3100,7 +3100,9 @@ fn lower_expr(&mut self, e: &Expr) -> hir::Expr { }) }) } - ExprKind::Block(ref blk) => hir::ExprBlock(self.lower_block(blk, false)), + ExprKind::Block(ref blk, opt_label) => { + hir::ExprBlock(self.lower_block(blk, false), self.lower_label(opt_label)) + } ExprKind::Assign(ref el, ref er) => { hir::ExprAssign(P(self.lower_expr(el)), P(self.lower_expr(er))) } @@ -3843,7 +3845,7 @@ fn expr_match( } fn expr_block(&mut self, b: P, attrs: ThinVec) -> hir::Expr { - self.expr(b.span, hir::ExprBlock(b), attrs) + self.expr(b.span, hir::ExprBlock(b, None), attrs) } fn expr_tuple(&mut self, sp: Span, exprs: hir::HirVec) -> P { diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 3f49e0bfd19..722a920d91c 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -1381,8 +1381,8 @@ pub enum Expr_ { /// This may also be a generator literal, indicated by the final boolean, /// in that case there is an GeneratorClause. ExprClosure(CaptureClause, P, BodyId, Span, Option), - /// A block (`{ ... }`) - ExprBlock(P), + /// A block (`'label: { ... }`) + ExprBlock(P, Option