1
Fork 0

Add Span to StmtKind::Let.

This commit is contained in:
Camille GILLOT 2023-02-26 21:35:54 +00:00
parent 28d74a9b72
commit 3b47cdc439
6 changed files with 71 additions and 2 deletions

View file

@ -115,6 +115,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
initializer: Some(initializer),
lint_level,
else_block: Some(else_block),
span: _,
} => {
// When lowering the statement `let <pat> = <expr> else { <else> };`,
// the `<else>` block is nested in the parent scope enclosing this statement.
@ -278,6 +279,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
initializer,
lint_level,
else_block: None,
span: _,
} => {
let ignores_expr_result = matches!(pattern.kind, PatKind::Wild);
this.block_context.push(BlockFrame::Statement { ignores_expr_result });

View file

@ -105,6 +105,10 @@ impl<'tcx> Cx<'tcx> {
}
}
let span = match local.init {
Some(init) => local.span.with_hi(init.span.hi()),
None => local.span,
};
let stmt = Stmt {
kind: StmtKind::Let {
remainder_scope,
@ -116,6 +120,7 @@ impl<'tcx> Cx<'tcx> {
initializer: local.init.map(|init| self.mirror_expr(init)),
else_block,
lint_level: LintLevel::Explicit(local.hir_id),
span,
},
opt_destruction_scope: opt_dxn_ext,
};

View file

@ -151,6 +151,7 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> {
initializer,
else_block,
lint_level,
span,
} => {
print_indented!(self, "kind: Let {", depth_lvl + 1);
print_indented!(
@ -181,6 +182,7 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> {
}
print_indented!(self, format!("lint_level: {:?}", lint_level), depth_lvl + 2);
print_indented!(self, format!("span: {:?}", span), depth_lvl + 2);
print_indented!(self, "}", depth_lvl + 1);
}
}