1
Fork 0

lower let-else in MIR instead

This commit is contained in:
Ding Xiang Fei 2022-06-02 22:39:47 +08:00
parent 38b72154de
commit 6c529ded86
No known key found for this signature in database
GPG key ID: 3CD748647EEF6359
71 changed files with 421 additions and 264 deletions

View file

@ -1296,7 +1296,8 @@ pub struct Stmt<'hir> {
#[derive(Debug, HashStable_Generic)]
pub enum StmtKind<'hir> {
/// A local (`let`) binding.
Local(&'hir Local<'hir>),
/// FIXME: bundle the last two components into another `struct`
Local(&'hir Local<'hir>, Option<&'hir Block<'hir>>),
/// An item binding.
Item(ItemId),

View file

@ -310,8 +310,8 @@ pub trait Visitor<'v>: Sized {
fn visit_foreign_item(&mut self, i: &'v ForeignItem<'v>) {
walk_foreign_item(self, i)
}
fn visit_local(&mut self, l: &'v Local<'v>) {
walk_local(self, l)
fn visit_local(&mut self, l: &'v Local<'v>, els: Option<&'v Block<'v>>) {
walk_local(self, l, els)
}
fn visit_block(&mut self, b: &'v Block<'v>) {
walk_block(self, b)
@ -466,12 +466,19 @@ pub fn walk_body<'v, V: Visitor<'v>>(visitor: &mut V, body: &'v Body<'v>) {
visitor.visit_expr(&body.value);
}
pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local<'v>) {
pub fn walk_local<'v, V: Visitor<'v>>(
visitor: &mut V,
local: &'v Local<'v>,
els: Option<&'v Block<'v>>,
) {
// Intentionally visiting the expr first - the initialization expr
// dominates the local's definition.
walk_list!(visitor, visit_expr, &local.init);
visitor.visit_id(local.hir_id);
visitor.visit_pat(&local.pat);
if let Some(els) = els {
visitor.visit_block(els);
}
walk_list!(visitor, visit_ty, &local.ty);
}
@ -1055,9 +1062,9 @@ pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block<'v>) {
pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt<'v>) {
visitor.visit_id(statement.hir_id);
match statement.kind {
StmtKind::Local(ref local) => visitor.visit_local(local),
StmtKind::Item(item) => visitor.visit_nested_item(item),
match &statement.kind {
StmtKind::Local(ref local, els) => visitor.visit_local(local, *els),
StmtKind::Item(item) => visitor.visit_nested_item(*item),
StmtKind::Expr(ref expression) | StmtKind::Semi(ref expression) => {
visitor.visit_expr(expression)
}