Skip to content

Commit 94dcfce

Browse files
committed
gamer
1 parent c70c0f1 commit 94dcfce

File tree

4 files changed

+20
-25
lines changed

4 files changed

+20
-25
lines changed

compiler/rustc_mir_build/src/build/expr/stmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_middle::middle::region;
22
use rustc_middle::mir::*;
3+
use rustc_middle::span_bug;
34
use rustc_middle::thir::*;
4-
use rustc_middle::{span_bug, ty};
55
use rustc_span::source_map::Spanned;
66
use tracing::debug;
77

compiler/rustc_mir_build/src/build/matches/test.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
568568
let is_covering_range = |test_case: &TestCase<'_, 'tcx>| {
569569
test_case.as_range().is_some_and(|range| {
570570
matches!(
571-
range.contains(value, self.tcx, self.infcx.typing_env(self.param_env),),
571+
range.contains(value, self.tcx, self.typing_env(),),
572572
None | Some(true)
573573
)
574574
})
@@ -587,7 +587,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
587587
None
588588
} else {
589589
fully_matched = true;
590-
let bits = value.eval_bits(self.tcx, self.infcx.typing_env(self.param_env));
590+
let bits = value.eval_bits(self.tcx, self.typing_env());
591591
Some(TestBranch::Constant(value, bits))
592592
}
593593
}
@@ -597,16 +597,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
597597
// the values being tested. (This restricts what values can be
598598
// added to the test by subsequent candidates.)
599599
fully_matched = false;
600-
let not_contained = sorted_candidates
601-
.keys()
602-
.filter_map(|br| br.as_constant())
603-
.copied()
604-
.all(|val| {
605-
matches!(
606-
range.contains(val, self.tcx, self.infcx.typing_env(self.param_env),),
607-
Some(false)
608-
)
609-
});
600+
let not_contained =
601+
sorted_candidates.keys().filter_map(|br| br.as_constant()).copied().all(
602+
|val| {
603+
matches!(range.contains(val, self.tcx, self.typing_env(),), Some(false))
604+
},
605+
);
610606

611607
not_contained.then(|| {
612608
// No switch values are contained in the pattern range,
@@ -617,11 +613,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
617613

618614
(TestKind::If, TestCase::Constant { value }) => {
619615
fully_matched = true;
620-
let value = value
621-
.try_eval_bool(self.tcx, self.infcx.typing_env(self.param_env))
622-
.unwrap_or_else(|| {
623-
span_bug!(test.span, "expected boolean value but got {value:?}")
624-
});
616+
let value = value.try_eval_bool(self.tcx, self.typing_env()).unwrap_or_else(|| {
617+
span_bug!(test.span, "expected boolean value but got {value:?}")
618+
});
625619
Some(if value { TestBranch::Success } else { TestBranch::Failure })
626620
}
627621

@@ -699,7 +693,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
699693
fully_matched = false;
700694
// If the testing range does not overlap with pattern range,
701695
// the pattern can be matched only if this test fails.
702-
if !test.overlaps(pat, self.tcx, self.infcx.typing_env(self.param_env))? {
696+
if !test.overlaps(pat, self.tcx, self.typing_env())? {
703697
Some(TestBranch::Failure)
704698
} else {
705699
None
@@ -708,7 +702,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
708702
}
709703
(TestKind::Range(range), &TestCase::Constant { value }) => {
710704
fully_matched = false;
711-
if !range.contains(value, self.tcx, self.infcx.typing_env(self.param_env))? {
705+
if !range.contains(value, self.tcx, self.typing_env())? {
712706
// `value` is not contained in the testing range,
713707
// so `value` can be matched only if this test fails.
714708
Some(TestBranch::Failure)

compiler/rustc_mir_build/src/build/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ struct Capture<'tcx> {
230230
}
231231

232232
impl<'a, 'tcx> Builder<'a, 'tcx> {
233+
fn typing_env(&self) -> ty::TypingEnv<'tcx> {
234+
self.infcx.typing_env(self.param_env)
235+
}
236+
233237
fn is_bound_var_in_guard(&self, id: LocalVarId) -> bool {
234238
self.guard_context.iter().any(|frame| frame.locals.iter().any(|local| local.id == id))
235239
}

compiler/rustc_mir_build/src/build/scope.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ use rustc_index::{IndexSlice, IndexVec};
8989
use rustc_middle::middle::region;
9090
use rustc_middle::mir::*;
9191
use rustc_middle::thir::{ExprId, LintLevel};
92-
use rustc_middle::{bug, span_bug, ty};
92+
use rustc_middle::{bug, span_bug};
9393
use rustc_session::lint::Level;
9494
use rustc_span::source_map::Spanned;
9595
use rustc_span::{DUMMY_SP, Span};
@@ -1010,10 +1010,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
10101010
) {
10111011
let needs_drop = match drop_kind {
10121012
DropKind::Value => {
1013-
if !self.local_decls[local]
1014-
.ty
1015-
.needs_drop(self.tcx, ty::TypingEnv::from_param_env(self.param_env))
1016-
{
1013+
if !self.local_decls[local].ty.needs_drop(self.tcx, self.typing_env()) {
10171014
return;
10181015
}
10191016
true

0 commit comments

Comments
 (0)