6 - Make more use of let_chains

Continuation of #94376.

cc #53667
This commit is contained in:
Caio
2022-02-28 21:12:52 -03:00
parent 4ce3749235
commit fe94f78b9b
8 changed files with 97 additions and 118 deletions

View File

@@ -116,22 +116,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// it is usually better to focus on `the_value` rather
// than the entirety of block(s) surrounding it.
let adjusted_span = (|| {
if let ExprKind::Block { body } = &expr.kind {
if let Some(tail_expr) = body.expr {
let mut expr = &this.thir[tail_expr];
while let ExprKind::Block {
body: Block { expr: Some(nested_expr), .. },
}
| ExprKind::Scope { value: nested_expr, .. } = expr.kind
{
expr = &this.thir[nested_expr];
}
this.block_context.push(BlockFrame::TailExpr {
tail_result_is_ignored: true,
span: expr.span,
});
return Some(expr.span);
if let ExprKind::Block { body } = &expr.kind && let Some(tail_ex) = body.expr {
let mut expr = &this.thir[tail_ex];
while let ExprKind::Block {
body: Block { expr: Some(nested_expr), .. },
}
| ExprKind::Scope { value: nested_expr, .. } = expr.kind
{
expr = &this.thir[nested_expr];
}
this.block_context.push(BlockFrame::TailExpr {
tail_result_is_ignored: true,
span: expr.span,
});
return Some(expr.span);
}
None
})();

View File

@@ -1597,13 +1597,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
// Insert a Shallow borrow of any places that is switched on.
if let Some(fb) = fake_borrows {
if let Ok(match_place_resolved) =
match_place.clone().try_upvars_resolved(self.tcx, self.typeck_results)
{
let resolved_place = match_place_resolved.into_place(self.tcx, self.typeck_results);
fb.insert(resolved_place);
}
if let Some(fb) = fake_borrows && let Ok(match_place_resolved) =
match_place.clone().try_upvars_resolved(self.tcx, self.typeck_results)
{
let resolved_place = match_place_resolved.into_place(self.tcx, self.typeck_results);
fb.insert(resolved_place);
}
// perform the test, branching to one of N blocks. For each of

View File

@@ -877,14 +877,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let arg_local = self.local_decls.push(LocalDecl::with_source_info(ty, source_info));
// If this is a simple binding pattern, give debuginfo a nice name.
if let Some(arg) = arg_opt {
if let Some(ident) = arg.pat.simple_ident() {
self.var_debug_info.push(VarDebugInfo {
name: ident.name,
source_info,
value: VarDebugInfoContents::Place(arg_local.into()),
});
}
if let Some(arg) = arg_opt && let Some(ident) = arg.pat.simple_ident() {
self.var_debug_info.push(VarDebugInfo {
name: ident.name,
source_info,
value: VarDebugInfoContents::Place(arg_local.into()),
});
}
}