lowering: refactor label/dest -> expr.rs
This commit is contained in:
parent
961ace3fc2
commit
29e9b5ddd4
2 changed files with 43 additions and 47 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue