diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-08-10 17:37:10 +0200 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-08-10 20:24:43 +0200 |
| commit | 29e9b5ddd49dffbdee8b8ad6aa1cbc090db1cbf1 (patch) | |
| tree | f4a60ad1b0cdcdd2a05cc4cf239858eb15c81158 | |
| parent | 961ace3fc229f203c2c84f977a14f8833de47f55 (diff) | |
| download | rust-29e9b5ddd49dffbdee8b8ad6aa1cbc090db1cbf1.tar.gz rust-29e9b5ddd49dffbdee8b8ad6aa1cbc090db1cbf1.zip | |
lowering: refactor label/dest -> expr.rs
| -rw-r--r-- | src/librustc/hir/lowering.rs | 30 | ||||
| -rw-r--r-- | src/librustc/hir/lowering/expr.rs | 60 |
2 files changed, 43 insertions, 47 deletions
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 480ab228d9a..1ada058a8bc 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1263,36 +1263,6 @@ impl<'a> LoweringContext<'a> { } } - fn lower_label(&mut self, label: Option<Label>) -> Option<hir::Label> { - label.map(|label| hir::Label { - ident: label.ident, - }) - } - - fn lower_loop_destination(&mut self, destination: Option<(NodeId, Label)>) -> hir::Destination { - let target_id = match destination { - Some((id, _)) => { - if let Some(loop_id) = self.resolver.get_label_res(id) { - Ok(self.lower_node_id(loop_id)) - } else { - Err(hir::LoopIdError::UnresolvedLabel) - } - } - None => { - self.loop_scopes - .last() - .cloned() - .map(|id| Ok(self.lower_node_id(id))) - .unwrap_or(Err(hir::LoopIdError::OutsideLoopScope)) - .into() - } - }; - hir::Destination { - label: self.lower_label(destination.map(|(_, label)| label)), - target_id, - } - } - fn lower_attrs_extendable(&mut self, attrs: &[Attribute]) -> Vec<Attribute> { attrs .iter() diff --git a/src/librustc/hir/lowering/expr.rs b/src/librustc/hir/lowering/expr.rs index 718f51adc22..a1c8af8c80d 100644 --- a/src/librustc/hir/lowering/expr.rs +++ b/src/librustc/hir/lowering/expr.rs @@ -138,28 +138,13 @@ impl LoweringContext<'_> { hir::ExprKind::Path(qpath) } ExprKind::Break(opt_label, ref opt_expr) => { - let destination = if self.is_in_loop_condition && opt_label.is_none() { - hir::Destination { - label: None, - target_id: Err(hir::LoopIdError::UnlabeledCfInWhileCondition).into(), - } - } else { - self.lower_loop_destination(opt_label.map(|label| (e.id, label))) - }; hir::ExprKind::Break( - destination, + self.lower_jump_destination(e.id, opt_label), opt_expr.as_ref().map(|x| P(self.lower_expr(x))), ) } ExprKind::Continue(opt_label) => { - hir::ExprKind::Continue(if self.is_in_loop_condition && opt_label.is_none() { - hir::Destination { - label: None, - target_id: Err(hir::LoopIdError::UnlabeledCfInWhileCondition).into(), - } - } else { - self.lower_loop_destination(opt_label.map(|label| (e.id, label))) - }) + hir::ExprKind::Continue(self.lower_jump_destination(e.id, opt_label)) } ExprKind::Ret(ref e) => hir::ExprKind::Ret(e.as_ref().map(|x| P(self.lower_expr(x)))), ExprKind::InlineAsm(ref asm) => self.lower_expr_asm(asm), @@ -818,6 +803,47 @@ impl LoweringContext<'_> { } } + fn lower_label(&mut self, label: Option<Label>) -> Option<hir::Label> { + label.map(|label| hir::Label { + ident: label.ident, + }) + } + + fn lower_loop_destination(&mut self, destination: Option<(NodeId, Label)>) -> hir::Destination { + let target_id = match destination { + Some((id, _)) => { + if let Some(loop_id) = self.resolver.get_label_res(id) { + Ok(self.lower_node_id(loop_id)) + } else { + Err(hir::LoopIdError::UnresolvedLabel) + } + } + None => { + self.loop_scopes + .last() + .cloned() + .map(|id| Ok(self.lower_node_id(id))) + .unwrap_or(Err(hir::LoopIdError::OutsideLoopScope)) + .into() + } + }; + hir::Destination { + label: self.lower_label(destination.map(|(_, label)| label)), + target_id, + } + } + + fn lower_jump_destination(&mut self, id: NodeId, opt_label: Option<Label>) -> hir::Destination { + if self.is_in_loop_condition && opt_label.is_none() { + hir::Destination { + label: None, + target_id: Err(hir::LoopIdError::UnlabeledCfInWhileCondition).into(), + } + } else { + self.lower_loop_destination(opt_label.map(|label| (id, label))) + } + } + fn lower_expr_asm(&mut self, asm: &InlineAsm) -> hir::ExprKind { let hir_asm = hir::InlineAsm { inputs: asm.inputs.iter().map(|&(ref c, _)| c.clone()).collect(), |
