1
Fork 0

Rollup merge of #137305 - nnethercote:rustc_middle-2, r=lcnr

Tweaks in and around `rustc_middle`

A bunch of tiny improvements I found while working on bigger things.

r? ```@lcnr```
This commit is contained in:
Matthias Krüger 2025-02-21 12:45:25 +01:00 committed by GitHub
commit 1f6c75e682
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 59 additions and 91 deletions

View file

@ -331,8 +331,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let expr = &this.thir[expr_id];
let tail_result_is_ignored =
destination_ty.is_unit() || this.block_context.currently_ignores_tail_results();
this.block_context
.push(BlockFrame::TailExpr { tail_result_is_ignored, span: expr.span });
this.block_context.push(BlockFrame::TailExpr {
info: BlockTailInfo { tail_result_is_ignored, span: expr.span },
});
block = this.expr_into_dest(destination, block, expr_id).into_block();
let popped = this.block_context.pop();

View file

@ -142,7 +142,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// Overwrite temp local info if we have something more interesting to record.
if !matches!(local_info, LocalInfo::Boring) {
let decl_info =
this.local_decls[operand].local_info.as_mut().assert_crate_local();
this.local_decls[operand].local_info.as_mut().unwrap_crate_local();
if let LocalInfo::Boring | LocalInfo::BlockTailTemp(_) = **decl_info {
**decl_info = local_info;
}

View file

@ -85,7 +85,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
_ => LocalInfo::Boring,
};
**local_decl.local_info.as_mut().assert_crate_local() = local_info;
**local_decl.local_info.as_mut().unwrap_crate_local() = local_info;
this.local_decls.push(local_decl)
};
debug!(?temp);

View file

@ -164,8 +164,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
}
this.block_context.push(BlockFrame::TailExpr {
tail_result_is_ignored: true,
span: expr.span,
info: BlockTailInfo { tail_result_is_ignored: true, span: expr.span },
});
Some(expr.span)
} else {

View file

@ -722,7 +722,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
if let LocalInfo::User(BindingForm::Var(VarBindingForm {
opt_match_place: Some((ref mut match_place, _)),
..
})) = **self.local_decls[local].local_info.as_mut().assert_crate_local()
})) = **self.local_decls[local].local_info.as_mut().unwrap_crate_local()
{
*match_place = Some(place);
} else {

View file

@ -112,16 +112,7 @@ enum BlockFrame {
/// Evaluation is currently within the tail expression of a block.
///
/// Example: `{ STMT_1; STMT_2; EXPR }`
TailExpr {
/// If true, then the surrounding context of the block ignores
/// the result of evaluating the block's tail expression.
///
/// Example: `let _ = { STMT_1; EXPR };`
tail_result_is_ignored: bool,
/// `Span` of the tail expression.
span: Span,
},
TailExpr { info: BlockTailInfo },
/// Generic mark meaning that the block occurred as a subexpression
/// where the result might be used.
@ -277,9 +268,7 @@ impl BlockContext {
match bf {
BlockFrame::SubExpr => continue,
BlockFrame::Statement { .. } => break,
&BlockFrame::TailExpr { tail_result_is_ignored, span } => {
return Some(BlockTailInfo { tail_result_is_ignored, span });
}
&BlockFrame::TailExpr { info } => return Some(info),
}
}
@ -302,9 +291,9 @@ impl BlockContext {
// otherwise: use accumulated is_ignored state.
Some(
BlockFrame::TailExpr { tail_result_is_ignored: ignored, .. }
| BlockFrame::Statement { ignores_expr_result: ignored },
) => *ignored,
BlockFrame::TailExpr { info: BlockTailInfo { tail_result_is_ignored: ign, .. } }
| BlockFrame::Statement { ignores_expr_result: ign },
) => *ign,
}
}
}
@ -967,7 +956,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
} => {
self.local_decls[local].mutability = mutability;
self.local_decls[local].source_info.scope = self.source_scope;
**self.local_decls[local].local_info.as_mut().assert_crate_local() =
**self.local_decls[local].local_info.as_mut().unwrap_crate_local() =
if let Some(kind) = param.self_kind {
LocalInfo::User(BindingForm::ImplicitSelf(kind))
} else {
@ -1032,7 +1021,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let parent_id = self.source_scopes[original_source_scope]
.local_data
.as_ref()
.assert_crate_local()
.unwrap_crate_local()
.lint_root;
self.maybe_new_source_scope(pattern_span, arg_hir_id, parent_id);
}

View file

@ -604,7 +604,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let source_scope = self.source_scope;
if let LintLevel::Explicit(current_hir_id) = lint_level {
let parent_id =
self.source_scopes[source_scope].local_data.as_ref().assert_crate_local().lint_root;
self.source_scopes[source_scope].local_data.as_ref().unwrap_crate_local().lint_root;
self.maybe_new_source_scope(region_scope.1.span, current_hir_id, parent_id);
}
self.push_scope(region_scope);
@ -992,7 +992,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
lint_root: if let LintLevel::Explicit(lint_root) = lint_level {
lint_root
} else {
self.source_scopes[parent].local_data.as_ref().assert_crate_local().lint_root
self.source_scopes[parent].local_data.as_ref().unwrap_crate_local().lint_root
},
};
self.source_scopes.push(SourceScopeData {