Skip to content

Commit 791e7bc

Browse files
committed
Auto merge of #28170 - nagisa:loopctl-label-spans, r=alexcrichton
r? @alexcrichton
2 parents 35b1454 + c493084 commit 791e7bc

File tree

16 files changed

+73
-43
lines changed

16 files changed

+73
-43
lines changed

src/librustc/middle/cfg/construct.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,15 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
284284
}
285285

286286
hir::ExprBreak(label) => {
287-
let loop_scope = self.find_scope(expr, label);
287+
let loop_scope = self.find_scope(expr, label.map(|l| l.node));
288288
let b = self.add_ast_node(expr.id, &[pred]);
289289
self.add_exiting_edge(expr, b,
290290
loop_scope, loop_scope.break_index);
291291
self.add_unreachable_node()
292292
}
293293

294294
hir::ExprAgain(label) => {
295-
let loop_scope = self.find_scope(expr, label);
295+
let loop_scope = self.find_scope(expr, label.map(|l| l.node));
296296
let a = self.add_ast_node(expr.id, &[pred]);
297297
self.add_exiting_edge(expr, a,
298298
loop_scope, loop_scope.continue_index);

src/librustc/middle/liveness.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
10491049

10501050
hir::ExprBreak(opt_label) => {
10511051
// Find which label this break jumps to
1052-
let sc = self.find_loop_scope(opt_label, expr.id, expr.span);
1052+
let sc = self.find_loop_scope(opt_label.map(|l| l.node), expr.id, expr.span);
10531053

10541054
// Now that we know the label we're going to,
10551055
// look it up in the break loop nodes table
@@ -1063,7 +1063,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
10631063

10641064
hir::ExprAgain(opt_label) => {
10651065
// Find which label this expr continues to
1066-
let sc = self.find_loop_scope(opt_label, expr.id, expr.span);
1066+
let sc = self.find_loop_scope(opt_label.map(|l| l.node), expr.id, expr.span);
10671067

10681068
// Now that we know the label we're going to,
10691069
// look it up in the continue loop nodes table

src/librustc_back/svh.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ mod svh_visitor {
277277
ExprRange(..) => SawExprRange,
278278
ExprPath(ref qself, _) => SawExprPath(qself.as_ref().map(|q| q.position)),
279279
ExprAddrOf(m, _) => SawExprAddrOf(m),
280-
ExprBreak(id) => SawExprBreak(id.map(|id| id.name.as_str())),
281-
ExprAgain(id) => SawExprAgain(id.map(|id| id.name.as_str())),
280+
ExprBreak(id) => SawExprBreak(id.map(|id| id.node.name.as_str())),
281+
ExprAgain(id) => SawExprAgain(id.map(|id| id.node.name.as_str())),
282282
ExprRet(..) => SawExprRet,
283283
ExprInlineAsm(ref asm) => SawExprInlineAsm(asm),
284284
ExprStruct(..) => SawExprStruct,

src/librustc_front/fold.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,8 +1124,14 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
11241124
});
11251125
ExprPath(qself, folder.fold_path(path))
11261126
}
1127-
ExprBreak(opt_ident) => ExprBreak(opt_ident.map(|x| folder.fold_ident(x))),
1128-
ExprAgain(opt_ident) => ExprAgain(opt_ident.map(|x| folder.fold_ident(x))),
1127+
ExprBreak(opt_ident) => ExprBreak(opt_ident.map(|label|
1128+
respan(folder.new_span(label.span),
1129+
folder.fold_ident(label.node)))
1130+
),
1131+
ExprAgain(opt_ident) => ExprAgain(opt_ident.map(|label|
1132+
respan(folder.new_span(label.span),
1133+
folder.fold_ident(label.node)))
1134+
),
11291135
ExprRet(e) => ExprRet(e.map(|x| folder.fold_expr(x))),
11301136
ExprInlineAsm(InlineAsm {
11311137
inputs,

src/librustc_front/hir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,9 +730,9 @@ pub enum Expr_ {
730730
/// A referencing operation (`&a` or `&mut a`)
731731
ExprAddrOf(Mutability, P<Expr>),
732732
/// A `break`, with an optional label to break
733-
ExprBreak(Option<Ident>),
733+
ExprBreak(Option<SpannedIdent>),
734734
/// A `continue`, with an optional label
735-
ExprAgain(Option<Ident>),
735+
ExprAgain(Option<SpannedIdent>),
736736
/// A `return`, with an optional value to be returned
737737
ExprRet(Option<P<Expr>>),
738738

src/librustc_front/print/pprust.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,15 +1587,15 @@ impl<'a> State<'a> {
15871587
try!(word(&mut self.s, "break"));
15881588
try!(space(&mut self.s));
15891589
if let Some(ident) = opt_ident {
1590-
try!(self.print_ident(ident));
1590+
try!(self.print_ident(ident.node));
15911591
try!(space(&mut self.s));
15921592
}
15931593
}
15941594
hir::ExprAgain(opt_ident) => {
15951595
try!(word(&mut self.s, "continue"));
15961596
try!(space(&mut self.s));
15971597
if let Some(ident) = opt_ident {
1598-
try!(self.print_ident(ident));
1598+
try!(self.print_ident(ident.node));
15991599
try!(space(&mut self.s))
16001600
}
16011601
}

src/librustc_resolve/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3759,12 +3759,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
37593759
}
37603760

37613761
ExprBreak(Some(label)) | ExprAgain(Some(label)) => {
3762-
let renamed = mtwt::resolve(label);
3762+
let renamed = mtwt::resolve(label.node);
37633763
match self.search_label(renamed) {
37643764
None => {
37653765
resolve_error(self,
3766-
expr.span,
3767-
ResolutionError::UndeclaredLabel(&label.name.as_str()))
3766+
label.span,
3767+
ResolutionError::UndeclaredLabel(&label.node.name.as_str()))
37683768
}
37693769
Some(DlDef(def @ DefLabel(_))) => {
37703770
// Since this def is a label, it is never read.

src/librustc_trans/trans/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,10 +937,10 @@ fn trans_rvalue_stmt_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
937937
trans_into(bcx, &**e, Ignore)
938938
}
939939
hir::ExprBreak(label_opt) => {
940-
controlflow::trans_break(bcx, expr, label_opt)
940+
controlflow::trans_break(bcx, expr, label_opt.map(|l| l.node))
941941
}
942942
hir::ExprAgain(label_opt) => {
943-
controlflow::trans_cont(bcx, expr, label_opt)
943+
controlflow::trans_cont(bcx, expr, label_opt.map(|l| l.node))
944944
}
945945
hir::ExprRet(ref ex) => {
946946
// Check to see if the return expression itself is reachable.

src/libsyntax/ast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,9 +891,9 @@ pub enum Expr_ {
891891
/// A referencing operation (`&a` or `&mut a`)
892892
ExprAddrOf(Mutability, P<Expr>),
893893
/// A `break`, with an optional label to break
894-
ExprBreak(Option<Ident>),
894+
ExprBreak(Option<SpannedIdent>),
895895
/// A `continue`, with an optional label
896-
ExprAgain(Option<Ident>),
896+
ExprAgain(Option<SpannedIdent>),
897897
/// A `return`, with an optional value to be returned
898898
ExprRet(Option<P<Expr>>),
899899

src/libsyntax/fold.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,8 +1299,14 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
12991299
});
13001300
ExprPath(qself, folder.fold_path(path))
13011301
}
1302-
ExprBreak(opt_ident) => ExprBreak(opt_ident.map(|x| folder.fold_ident(x))),
1303-
ExprAgain(opt_ident) => ExprAgain(opt_ident.map(|x| folder.fold_ident(x))),
1302+
ExprBreak(opt_ident) => ExprBreak(opt_ident.map(|label|
1303+
respan(folder.new_span(label.span),
1304+
folder.fold_ident(label.node)))
1305+
),
1306+
ExprAgain(opt_ident) => ExprAgain(opt_ident.map(|label|
1307+
respan(folder.new_span(label.span),
1308+
folder.fold_ident(label.node)))
1309+
),
13041310
ExprRet(e) => ExprRet(e.map(|x| folder.fold_expr(x))),
13051311
ExprInlineAsm(InlineAsm {
13061312
inputs,

0 commit comments

Comments
 (0)