Skip to content

Commit aab149b

Browse files
committed
ConstCx stop using ParamEnv::reveal
1 parent 84295b9 commit aab149b

File tree

6 files changed

+27
-27
lines changed

6 files changed

+27
-27
lines changed

compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_middle::mir::visit::Visitor;
1616
use rustc_middle::mir::*;
1717
use rustc_middle::span_bug;
1818
use rustc_middle::ty::adjustment::PointerCoercion;
19-
use rustc_middle::ty::{self, Instance, InstanceKind, Ty, TypeVisitableExt, TypingMode};
19+
use rustc_middle::ty::{self, Instance, InstanceKind, Ty, TypeVisitableExt};
2020
use rustc_mir_dataflow::Analysis;
2121
use rustc_mir_dataflow::impls::MaybeStorageLive;
2222
use rustc_mir_dataflow::storage::always_storage_live_locals;
@@ -589,7 +589,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
589589
// Typeck only does a "non-const" check since it operates on HIR and cannot distinguish
590590
// which path expressions are getting called on and which path expressions are only used
591591
// as function pointers. This is required for correctness.
592-
let infcx = tcx.infer_ctxt().build(TypingMode::from_param_env(param_env));
592+
let infcx = tcx.infer_ctxt().build(body.phase.typing_mode());
593593
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
594594

595595
let predicates = tcx.predicates_of(callee).instantiate(tcx, fn_args);

compiler/rustc_const_eval/src/check_consts/mod.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,7 @@ impl<'mir, 'tcx> ConstCx<'mir, 'tcx> {
3232
pub fn new(tcx: TyCtxt<'tcx>, body: &'mir mir::Body<'tcx>) -> Self {
3333
let def_id = body.source.def_id().expect_local();
3434
let param_env = tcx.param_env(def_id);
35-
Self::new_with_param_env(tcx, body, param_env)
36-
}
3735

38-
pub fn new_with_param_env(
39-
tcx: TyCtxt<'tcx>,
40-
body: &'mir mir::Body<'tcx>,
41-
param_env: ty::ParamEnv<'tcx>,
42-
) -> Self {
4336
let const_kind = tcx.hir().body_const_context(body.source.def_id().expect_local());
4437
ConstCx { body, tcx, param_env, const_kind }
4538
}

compiler/rustc_const_eval/src/check_consts/ops.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_middle::mir::CallSource;
1212
use rustc_middle::span_bug;
1313
use rustc_middle::ty::print::{PrintTraitRefExt as _, with_no_trimmed_paths};
1414
use rustc_middle::ty::{
15-
self, Closure, FnDef, FnPtr, GenericArgKind, GenericArgsRef, Param, TraitRef, Ty, TypingMode,
15+
self, Closure, FnDef, FnPtr, GenericArgKind, GenericArgsRef, Param, TraitRef, Ty,
1616
suggest_constraining_type_param,
1717
};
1818
use rustc_middle::util::{CallDesugaringKind, CallKind, call_kind};
@@ -116,7 +116,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
116116
let obligation =
117117
Obligation::new(tcx, ObligationCause::dummy(), param_env, trait_ref);
118118

119-
let infcx = tcx.infer_ctxt().build(TypingMode::from_param_env(param_env));
119+
let infcx = tcx.infer_ctxt().build(body.phase.typing_mode());
120120
let mut selcx = SelectionContext::new(&infcx);
121121
let implsrc = selcx.select(&obligation);
122122

compiler/rustc_middle/src/mir/syntax.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ use smallvec::SmallVec;
1919

2020
use super::{BasicBlock, Const, Local, UserTypeProjection};
2121
use crate::mir::coverage::CoverageKind;
22-
use crate::traits::Reveal;
2322
use crate::ty::adjustment::PointerCoercion;
24-
use crate::ty::{self, GenericArgsRef, List, Region, Ty, UserTypeAnnotationIndex};
23+
use crate::ty::{
24+
self, GenericArgsRef, List, Region, Ty, TyCtxt, TypingMode, UserTypeAnnotationIndex,
25+
};
2526

2627
/// Represents the "flavors" of MIR.
2728
///
@@ -102,10 +103,20 @@ impl MirPhase {
102103
}
103104
}
104105

105-
pub fn reveal(&self) -> Reveal {
106-
match *self {
107-
MirPhase::Built | MirPhase::Analysis(_) => Reveal::UserFacing,
108-
MirPhase::Runtime(_) => Reveal::All,
106+
pub fn typing_mode<'tcx>(&self) -> TypingMode<'tcx> {
107+
match self {
108+
// FIXME(#132279): the MIR is quite clearly inside of a body, so we
109+
// should instead reveal opaques defined by that body here.
110+
MirPhase::Built | MirPhase::Analysis(_) => TypingMode::non_body_analysis(),
111+
MirPhase::Runtime(_) => TypingMode::PostAnalysis,
112+
}
113+
}
114+
115+
pub fn param_env<'tcx>(&self, tcx: TyCtxt<'tcx>, body_def_id: DefId) -> ty::ParamEnv<'tcx> {
116+
match self.typing_mode() {
117+
TypingMode::Coherence => unreachable!(),
118+
TypingMode::Analysis { defining_opaque_types: _ } => tcx.param_env(body_def_id),
119+
TypingMode::PostAnalysis => tcx.param_env_reveal_all_normalized(body_def_id),
109120
}
110121
}
111122
}

compiler/rustc_mir_transform/src/validate.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ use rustc_hir::LangItem;
55
use rustc_index::IndexVec;
66
use rustc_index::bit_set::BitSet;
77
use rustc_infer::infer::TyCtxtInferExt;
8-
use rustc_infer::traits::{Obligation, ObligationCause, Reveal};
8+
use rustc_infer::traits::{Obligation, ObligationCause};
99
use rustc_middle::mir::coverage::CoverageKind;
1010
use rustc_middle::mir::visit::{NonUseContext, PlaceContext, Visitor};
1111
use rustc_middle::mir::*;
1212
use rustc_middle::ty::adjustment::PointerCoercion;
1313
use rustc_middle::ty::{
1414
self, CoroutineArgsExt, InstanceKind, ParamEnv, ScalarInt, Ty, TyCtxt, TypeVisitableExt,
15-
TypingMode, Variance,
15+
Variance,
1616
};
1717
use rustc_middle::{bug, span_bug};
1818
use rustc_target::abi::{FIRST_VARIANT, Size};
@@ -50,11 +50,7 @@ impl<'tcx> crate::MirPass<'tcx> for Validator {
5050
}
5151
let def_id = body.source.def_id();
5252
let mir_phase = self.mir_phase;
53-
let param_env = match mir_phase.reveal() {
54-
Reveal::UserFacing => tcx.param_env(def_id),
55-
Reveal::All => tcx.param_env_reveal_all_normalized(def_id),
56-
};
57-
53+
let param_env = mir_phase.param_env(tcx, def_id);
5854
let can_unwind = if mir_phase <= MirPhase::Runtime(RuntimePhase::Initial) {
5955
// In this case `AbortUnwindingCalls` haven't yet been executed.
6056
true
@@ -606,7 +602,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
606602
return true;
607603
}
608604

609-
let infcx = self.tcx.infer_ctxt().build(TypingMode::from_param_env(self.param_env));
605+
let infcx = self.tcx.infer_ctxt().build(self.body.phase.typing_mode());
610606
let ocx = ObligationCtxt::new(&infcx);
611607
ocx.register_obligation(Obligation::new(
612608
self.tcx,

src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_middle::mir::{
1717
};
1818
use rustc_middle::traits::{BuiltinImplSource, ImplSource, ObligationCause};
1919
use rustc_middle::ty::adjustment::PointerCoercion;
20-
use rustc_middle::ty::{self, GenericArgKind, TraitRef, Ty, TyCtxt, TypingMode};
20+
use rustc_middle::ty::{self, GenericArgKind, TraitRef, Ty, TyCtxt};
2121
use rustc_span::Span;
2222
use rustc_span::symbol::sym;
2323
use rustc_trait_selection::traits::{ObligationCtxt, SelectionContext};
@@ -420,7 +420,7 @@ fn is_ty_const_destruct<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, body: &Body<'tcx>
420420
TraitRef::new(tcx, tcx.require_lang_item(LangItem::Destruct, Some(body.span)), [ty]),
421421
);
422422

423-
let infcx = tcx.infer_ctxt().build(TypingMode::from_param_env(obligation.param_env));
423+
let infcx = tcx.infer_ctxt().build(body.phase.typing_mode());
424424
let mut selcx = SelectionContext::new(&infcx);
425425
let Some(impl_src) = selcx.select(&obligation).ok().flatten() else {
426426
return false;

0 commit comments

Comments
 (0)