diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index fdb350ebaac..122543aee40 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -303,17 +303,17 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { self.add_unreachable_node() } - hir::ExprBreak(label, ref opt_expr) => { + hir::ExprBreak(destination, ref opt_expr) => { let v = self.opt_expr(opt_expr, pred); - let loop_scope = self.find_scope(expr, label); + let loop_scope = self.find_scope(expr, destination); let b = self.add_ast_node(expr.id, &[v]); self.add_exiting_edge(expr, b, loop_scope, loop_scope.break_index); self.add_unreachable_node() } - hir::ExprAgain(label) => { - let loop_scope = self.find_scope(expr, label); + hir::ExprAgain(destination) => { + let loop_scope = self.find_scope(expr, destination); let a = self.add_ast_node(expr.id, &[pred]); self.add_exiting_edge(expr, a, loop_scope, loop_scope.continue_index); @@ -588,9 +588,9 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { fn find_scope(&self, expr: &hir::Expr, - label: hir::Label) -> LoopScope { + destination: hir::Destination) -> LoopScope { - match label.loop_id.into() { + match destination.loop_id.into() { Ok(loop_id) => { for l in &self.loop_scopes { if l.loop_id == loop_id { diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 55226fa7605..efb351e0325 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -326,9 +326,11 @@ impl<'a> LoweringContext<'a> { o_id.map(|sp_ident| respan(sp_ident.span, sp_ident.node.name)) } - fn lower_label(&mut self, label: Option<(NodeId, Spanned)>) -> hir::Label { - match label { - Some((id, label_ident)) => hir::Label { + fn lower_destination(&mut self, destination: Option<(NodeId, Spanned)>) + -> hir::Destination + { + match destination { + Some((id, label_ident)) => hir::Destination { ident: Some(label_ident), loop_id: if let Def::Label(loop_id) = self.expect_full_def(id) { hir::LoopIdResult::Ok(loop_id) @@ -336,7 +338,7 @@ impl<'a> LoweringContext<'a> { hir::LoopIdResult::Err(hir::LoopIdError::UnresolvedLabel) } }, - None => hir::Label { + None => hir::Destination { ident: None, loop_id: self.loop_scopes.last().map(|innermost_loop_id| Ok(*innermost_loop_id)) .unwrap_or(Err(hir::LoopIdError::OutsideLoopScope)).into() @@ -1729,12 +1731,12 @@ impl<'a> LoweringContext<'a> { } ExprKind::Break(opt_ident, ref opt_expr) => { let label_result = if self.is_in_loop_condition && opt_ident.is_none() { - hir::Label { + hir::Destination { ident: opt_ident, loop_id: Err(hir::LoopIdError::UnlabeledCfInWhileCondition).into(), } } else { - self.lower_label(opt_ident.map(|ident| (e.id, ident))) + self.lower_destination(opt_ident.map(|ident| (e.id, ident))) }; hir::ExprBreak( label_result, @@ -1743,13 +1745,13 @@ impl<'a> LoweringContext<'a> { ExprKind::Continue(opt_ident) => hir::ExprAgain( if self.is_in_loop_condition && opt_ident.is_none() { - hir::Label { + hir::Destination { ident: opt_ident, loop_id: Err( hir::LoopIdError::UnlabeledCfInWhileCondition).into(), } } else { - self.lower_label(opt_ident.map( | ident| (e.id, ident))) + self.lower_destination(opt_ident.map( |ident| (e.id, ident))) }), ExprKind::Ret(ref e) => hir::ExprRet(e.as_ref().map(|x| P(self.lower_expr(x)))), ExprKind::InlineAsm(ref asm) => { @@ -2244,7 +2246,7 @@ impl<'a> LoweringContext<'a> { } fn expr_break(&mut self, span: Span, attrs: ThinVec) -> P { - let expr_break = hir::ExprBreak(self.lower_label(None), None); + let expr_break = hir::ExprBreak(self.lower_destination(None), None); P(self.expr(span, expr_break, attrs)) } diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 4e4187cbf89..e8c5f2447cd 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -959,9 +959,9 @@ pub enum Expr_ { /// A referencing operation (`&a` or `&mut a`) ExprAddrOf(Mutability, P), /// A `break`, with an optional label to break - ExprBreak(Label, Option>), + ExprBreak(Destination, Option>), /// A `continue`, with an optional label - ExprAgain(Label), + ExprAgain(Destination), /// A `return`, with an optional value to be returned ExprRet(Option>), @@ -1073,7 +1073,7 @@ impl From> for LoopIdResult { } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] -pub struct Label { +pub struct Destination { // This is `Some(_)` iff there is an explicit user-specified `label pub ident: Option>,