summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_mir_build/src/build/matches
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
commitc23a457e72abe608715ac76f076f47dc42af07a5 (patch)
tree2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /compiler/rustc_mir_build/src/build/matches
parentReleasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz
rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_mir_build/src/build/matches')
-rw-r--r--compiler/rustc_mir_build/src/build/matches/mod.rs56
-rw-r--r--compiler/rustc_mir_build/src/build/matches/test.rs29
2 files changed, 62 insertions, 23 deletions
diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs
index 3c4507407..6baf8c7d7 100644
--- a/compiler/rustc_mir_build/src/build/matches/mod.rs
+++ b/compiler/rustc_mir_build/src/build/matches/mod.rs
@@ -64,6 +64,43 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
rhs_then_block.unit()
}
+ ExprKind::LogicalOp { op: LogicalOp::Or, lhs, rhs } => {
+ let local_scope = this.local_scope();
+ let (lhs_success_block, failure_block) =
+ this.in_if_then_scope(local_scope, expr_span, |this| {
+ this.then_else_break(
+ block,
+ &this.thir[lhs],
+ temp_scope_override,
+ local_scope,
+ variable_source_info,
+ )
+ });
+ let rhs_success_block = unpack!(this.then_else_break(
+ failure_block,
+ &this.thir[rhs],
+ temp_scope_override,
+ break_scope,
+ variable_source_info,
+ ));
+ this.cfg.goto(lhs_success_block, variable_source_info, rhs_success_block);
+ rhs_success_block.unit()
+ }
+ ExprKind::Unary { op: UnOp::Not, arg } => {
+ let local_scope = this.local_scope();
+ let (success_block, failure_block) =
+ this.in_if_then_scope(local_scope, expr_span, |this| {
+ this.then_else_break(
+ block,
+ &this.thir[arg],
+ temp_scope_override,
+ local_scope,
+ variable_source_info,
+ )
+ });
+ this.break_for_else(success_block, break_scope, variable_source_info);
+ failure_block.unit()
+ }
ExprKind::Scope { region_scope, lint_level, value } => {
let region_scope = (region_scope, this.source_info(expr_span));
this.in_scope(region_scope, lint_level, |this| {
@@ -76,6 +113,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
)
})
}
+ ExprKind::Use { source } => this.then_else_break(
+ block,
+ &this.thir[source],
+ temp_scope_override,
+ break_scope,
+ variable_source_info,
+ ),
ExprKind::Let { expr, ref pat } => this.lower_let_expr(
block,
&this.thir[expr],
@@ -961,13 +1005,13 @@ enum TestKind<'tcx> {
///
/// For `bool` we always generate two edges, one for `true` and one for
/// `false`.
- options: FxIndexMap<ConstantKind<'tcx>, u128>,
+ options: FxIndexMap<Const<'tcx>, u128>,
},
/// Test for equality with value, possibly after an unsizing coercion to
/// `ty`,
Eq {
- value: ConstantKind<'tcx>,
+ value: Const<'tcx>,
// Integer types are handled by `SwitchInt`, and constants with ADT
// types are converted back into patterns, so this can only be `&str`,
// `&[T]`, `f32` or `f64`.
@@ -1578,9 +1622,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// may want to add cases based on the candidates that are
// available
match test.kind {
- TestKind::SwitchInt { switch_ty, ref mut options } => {
+ TestKind::SwitchInt { switch_ty: _, ref mut options } => {
for candidate in candidates.iter() {
- if !self.add_cases_to_switch(&match_place, candidate, switch_ty, options) {
+ if !self.add_cases_to_switch(&match_place, candidate, options) {
break;
}
}
@@ -1960,7 +2004,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let re_erased = tcx.lifetimes.re_erased;
let scrutinee_source_info = self.source_info(scrutinee_span);
for &(place, temp) in fake_borrows {
- let borrow = Rvalue::Ref(re_erased, BorrowKind::Shallow, place);
+ let borrow = Rvalue::Ref(re_erased, BorrowKind::Fake, place);
self.cfg.push_assign(block, scrutinee_source_info, Place::from(temp), borrow);
}
@@ -2243,6 +2287,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
name,
source_info: debug_source_info,
value: VarDebugInfoContents::Place(for_arm_body.into()),
+ composite: None,
argument_index: None,
});
let locals = if has_guard.0 {
@@ -2262,6 +2307,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
name,
source_info: debug_source_info,
value: VarDebugInfoContents::Place(ref_for_guard.into()),
+ composite: None,
argument_index: None,
});
LocalsForNode::ForGuard { ref_for_guard, for_arm_body }
diff --git a/compiler/rustc_mir_build/src/build/matches/test.rs b/compiler/rustc_mir_build/src/build/matches/test.rs
index 484e84909..795d1db8e 100644
--- a/compiler/rustc_mir_build/src/build/matches/test.rs
+++ b/compiler/rustc_mir_build/src/build/matches/test.rs
@@ -85,8 +85,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
&mut self,
test_place: &PlaceBuilder<'tcx>,
candidate: &Candidate<'pat, 'tcx>,
- switch_ty: Ty<'tcx>,
- options: &mut FxIndexMap<ConstantKind<'tcx>, u128>,
+ options: &mut FxIndexMap<Const<'tcx>, u128>,
) -> bool {
let Some(match_pair) = candidate.match_pairs.iter().find(|mp| mp.place == *test_place)
else {
@@ -95,9 +94,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
match match_pair.pattern.kind {
PatKind::Constant { value } => {
- options
- .entry(value)
- .or_insert_with(|| value.eval_bits(self.tcx, self.param_env, switch_ty));
+ options.entry(value).or_insert_with(|| value.eval_bits(self.tcx, self.param_env));
true
}
PatKind::Variant { .. } => {
@@ -255,10 +252,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block,
source_info,
TerminatorKind::Call {
- func: Operand::Constant(Box::new(Constant {
+ func: Operand::Constant(Box::new(ConstOperand {
span: test.span,
user_ty: None,
- literal: method,
+ const_: method,
})),
args: vec![Operand::Move(ref_string)],
destination: ref_str,
@@ -388,7 +385,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block: BasicBlock,
make_target_blocks: impl FnOnce(&mut Self) -> Vec<BasicBlock>,
source_info: SourceInfo,
- value: ConstantKind<'tcx>,
+ value: Const<'tcx>,
mut val: Place<'tcx>,
mut ty: Ty<'tcx>,
) {
@@ -485,7 +482,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block,
source_info,
TerminatorKind::Call {
- func: Operand::Constant(Box::new(Constant {
+ func: Operand::Constant(Box::new(ConstOperand {
span: source_info.span,
// FIXME(#54571): This constant comes from user input (a
@@ -494,7 +491,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// Need to experiment.
user_ty: None,
- literal: method,
+ const_: method,
})),
args: vec![Operand::Copy(val), expect],
destination: eq_result,
@@ -800,11 +797,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
span_bug!(match_pair.pattern.span, "simplifiable pattern found: {:?}", match_pair.pattern)
}
- fn const_range_contains(
- &self,
- range: &PatRange<'tcx>,
- value: ConstantKind<'tcx>,
- ) -> Option<bool> {
+ fn const_range_contains(&self, range: &PatRange<'tcx>, value: Const<'tcx>) -> Option<bool> {
use std::cmp::Ordering::*;
// For performance, it's important to only do the second
@@ -821,7 +814,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
fn values_not_contained_in_range(
&self,
range: &PatRange<'tcx>,
- options: &FxIndexMap<ConstantKind<'tcx>, u128>,
+ options: &FxIndexMap<Const<'tcx>, u128>,
) -> Option<bool> {
for &val in options.keys() {
if self.const_range_contains(range, val)? {
@@ -866,7 +859,7 @@ fn trait_method<'tcx>(
trait_def_id: DefId,
method_name: Symbol,
args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
-) -> ConstantKind<'tcx> {
+) -> Const<'tcx> {
// The unhygienic comparison here is acceptable because this is only
// used on known traits.
let item = tcx
@@ -877,5 +870,5 @@ fn trait_method<'tcx>(
let method_ty = Ty::new_fn_def(tcx, item.def_id, args);
- ConstantKind::zero_sized(method_ty)
+ Const::zero_sized(method_ty)
}