Skip to content

Commit e1956eb

Browse files
committed
make typing_mode getter
1 parent 766c796 commit e1956eb

10 files changed

Lines changed: 32 additions & 39 deletions

File tree

compiler/rustc_const_eval/src/check_consts/qualifs.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_errors::ErrorGuaranteed;
99
use rustc_hir::LangItem;
1010
use rustc_infer::infer::TyCtxtInferExt;
1111
use rustc_middle::mir::*;
12-
use rustc_middle::ty::{self, AdtDef, EqTypingMode, Ty};
12+
use rustc_middle::ty::{self, AdtDef, Ty};
1313
use rustc_middle::{bug, mir};
1414
use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt};
1515
use tracing::instrument;
@@ -103,13 +103,10 @@ impl Qualif for HasMutInterior {
103103
// FIXME(#132279): Once we've got a typing mode which reveals opaque types using the HIR
104104
// typeck results without causing query cycles, we should use this here instead of defining
105105
// opaque types.
106-
let typing_env = ty::TypingEnv {
107-
typing_mode: EqTypingMode(ty::TypingMode::analysis_in_body(
108-
cx.tcx,
109-
cx.body.source.def_id().expect_local(),
110-
)),
111-
param_env: cx.typing_env.param_env,
112-
};
106+
let typing_env = ty::TypingEnv::new(
107+
cx.typing_env.param_env,
108+
ty::TypingMode::analysis_in_body(cx.tcx, cx.body.source.def_id().expect_local()),
109+
);
113110
let (infcx, param_env) = cx.tcx.infer_ctxt().build_with_typing_env(typing_env);
114111
let ocx = ObligationCtxt::new(&infcx);
115112
let obligation = Obligation::new(

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
373373
assert!(key.value.promoted.is_some() || !tcx.is_static(key.value.instance.def_id()));
374374

375375
#[cfg(debug_assertions)]
376-
match key.typing_env.typing_mode.0 {
376+
match key.typing_env.typing_mode() {
377377
ty::TypingMode::PostAnalysis => {}
378378
ty::TypingMode::Coherence
379379
| ty::TypingMode::Analysis { .. }

compiler/rustc_const_eval/src/const_eval/valtrees.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ pub(crate) fn eval_to_valtree<'tcx>(
237237
cid: GlobalId<'tcx>,
238238
) -> EvalToValTreeResult<'tcx> {
239239
#[cfg(debug_assertions)]
240-
match typing_env.typing_mode.0 {
240+
match typing_env.typing_mode() {
241241
ty::TypingMode::PostAnalysis => {}
242242
ty::TypingMode::Coherence
243243
| ty::TypingMode::Analysis { .. }

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::debug_assert_matches;
2-
31
use either::{Left, Right};
42
use rustc_abi::{Align, HasDataLayout, Size, TargetDataLayout};
53
use rustc_hir::def_id::DefId;
@@ -243,9 +241,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
243241
// opaque types. This is needed for trivial things like `size_of`, but also for using associated
244242
// types that are not specified in the opaque type. We also use MIR bodies whose opaque types have
245243
// already been revealed, so we'd be able to at least partially observe the hidden types anyways.
246-
debug_assert_matches!(typing_env.typing_mode.0, ty::TypingMode::PostAnalysis);
247244
#[cfg(debug_assertions)]
248-
match typing_env.typing_mode.0 {
245+
match typing_env.typing_mode() {
249246
ty::TypingMode::PostAnalysis => {}
250247
ty::TypingMode::Coherence
251248
| ty::TypingMode::Analysis { .. }

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use rustc_middle::ty::{
3333
TypeSuperFoldable, TypeVisitable, TypeVisitableExt, TypingEnv, TypingMode, fold_regions,
3434
};
3535
use rustc_span::{DUMMY_SP, Span, Symbol};
36-
use rustc_type_ir::EqTypingMode;
3736
use snapshot::undo_log::InferCtxtUndoLogs;
3837
use tracing::{debug, instrument};
3938
use type_variable::TypeVariableOrigin;
@@ -572,9 +571,9 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
572571

573572
pub fn build_with_typing_env(
574573
mut self,
575-
TypingEnv { typing_mode, param_env }: TypingEnv<'tcx>,
574+
typing_env: TypingEnv<'tcx>,
576575
) -> (InferCtxt<'tcx>, ty::ParamEnv<'tcx>) {
577-
(self.build(typing_mode.0), param_env)
576+
(self.build(typing_env.typing_mode()), typing_env.param_env)
578577
}
579578

580579
pub fn build(&mut self, typing_mode: TypingMode<'tcx>) -> InferCtxt<'tcx> {
@@ -1377,7 +1376,7 @@ impl<'tcx> InferCtxt<'tcx> {
13771376
| ty::TypingMode::PostBorrowckAnalysis { .. }
13781377
| ty::TypingMode::PostAnalysis) => mode,
13791378
};
1380-
ty::TypingEnv { typing_mode: EqTypingMode(typing_mode), param_env }
1379+
ty::TypingEnv::new(param_env, typing_mode)
13811380
}
13821381

13831382
/// Similar to [`Self::canonicalize_query`], except that it returns

compiler/rustc_lint/src/context.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ use rustc_middle::lint::LevelAndSource;
2424
use rustc_middle::middle::privacy::EffectiveVisibilities;
2525
use rustc_middle::ty::layout::{LayoutError, LayoutOfHelpers, TyAndLayout};
2626
use rustc_middle::ty::print::{PrintError, PrintTraitRefExt as _, Printer, with_no_trimmed_paths};
27-
use rustc_middle::ty::{
28-
self, EqTypingMode, GenericArg, RegisteredTools, Ty, TyCtxt, TypingEnv, TypingMode,
29-
};
27+
use rustc_middle::ty::{self, GenericArg, RegisteredTools, Ty, TyCtxt, TypingEnv, TypingMode};
3028
use rustc_session::lint::{
3129
CheckLintNameResult, FutureIncompatibleInfo, Lint, LintExpectationId, LintId, TargetLint,
3230
};
@@ -617,7 +615,7 @@ impl<'tcx> LateContext<'tcx> {
617615
}
618616

619617
pub fn typing_env(&self) -> TypingEnv<'tcx> {
620-
TypingEnv { typing_mode: EqTypingMode(self.typing_mode()), param_env: self.param_env }
618+
TypingEnv::new(self.param_env, self.typing_mode())
621619
}
622620

623621
pub fn type_is_copy_modulo_regions(&self, ty: Ty<'tcx>) -> bool {

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ use crate::mir::interpret::{AllocRange, Scalar};
3232
use crate::ty::codec::{TyDecoder, TyEncoder};
3333
use crate::ty::print::{FmtPrinter, Printer, pretty_print_const, with_no_trimmed_paths};
3434
use crate::ty::{
35-
self, EqTypingMode, GenericArg, GenericArgsRef, Instance, InstanceKind, List, Ty, TyCtxt,
36-
TypeVisitableExt, TypingEnv, UserTypeAnnotationIndex,
35+
self, GenericArg, GenericArgsRef, Instance, InstanceKind, List, Ty, TyCtxt, TypeVisitableExt,
36+
TypingEnv, UserTypeAnnotationIndex,
3737
};
3838

3939
mod basic_blocks;
@@ -415,10 +415,10 @@ impl<'tcx> Body<'tcx> {
415415
pub fn typing_env(&self, tcx: TyCtxt<'tcx>) -> TypingEnv<'tcx> {
416416
match self.phase {
417417
// FIXME(#132279): we should reveal the opaques defined in the body during analysis.
418-
MirPhase::Built | MirPhase::Analysis(_) => TypingEnv {
419-
typing_mode: EqTypingMode(ty::TypingMode::non_body_analysis()),
420-
param_env: tcx.param_env(self.source.def_id()),
421-
},
418+
MirPhase::Built | MirPhase::Analysis(_) => TypingEnv::new(
419+
tcx.param_env(self.source.def_id()),
420+
ty::TypingMode::non_body_analysis(),
421+
),
422422
MirPhase::Runtime(_) => TypingEnv::post_analysis(tcx, self.source.def_id()),
423423
}
424424
}

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -981,11 +981,19 @@ pub struct ParamEnvAnd<'tcx, T> {
981981
pub struct TypingEnv<'tcx> {
982982
#[type_foldable(identity)]
983983
#[type_visitable(ignore)]
984-
pub typing_mode: EqTypingMode<'tcx>,
984+
typing_mode: EqTypingMode<'tcx>,
985985
pub param_env: ParamEnv<'tcx>,
986986
}
987987

988988
impl<'tcx> TypingEnv<'tcx> {
989+
pub fn new(param_env: ParamEnv<'tcx>, typing_mode: TypingMode<'tcx>) -> Self {
990+
Self { typing_mode: EqTypingMode(typing_mode), param_env }
991+
}
992+
993+
pub fn typing_mode(&self) -> TypingMode<'tcx> {
994+
self.typing_mode.0
995+
}
996+
989997
/// Create a typing environment with no where-clauses in scope
990998
/// where all opaque types and default associated items are revealed.
991999
///
@@ -994,10 +1002,7 @@ impl<'tcx> TypingEnv<'tcx> {
9941002
/// use `TypingMode::PostAnalysis`, they may still have where-clauses
9951003
/// in scope.
9961004
pub fn fully_monomorphized() -> TypingEnv<'tcx> {
997-
TypingEnv {
998-
typing_mode: EqTypingMode(TypingMode::PostAnalysis),
999-
param_env: ParamEnv::empty(),
1000-
}
1005+
Self::new(ParamEnv::empty(), TypingMode::PostAnalysis)
10011006
}
10021007

10031008
/// Create a typing environment for use during analysis outside of a body.
@@ -1010,10 +1015,7 @@ impl<'tcx> TypingEnv<'tcx> {
10101015
def_id: impl IntoQueryKey<DefId>,
10111016
) -> TypingEnv<'tcx> {
10121017
let def_id = def_id.into_query_key();
1013-
TypingEnv {
1014-
typing_mode: EqTypingMode(TypingMode::non_body_analysis()),
1015-
param_env: tcx.param_env(def_id),
1016-
}
1018+
Self::new(tcx.param_env(def_id), TypingMode::non_body_analysis())
10171019
}
10181020

10191021
pub fn post_analysis(tcx: TyCtxt<'tcx>, def_id: impl IntoQueryKey<DefId>) -> TypingEnv<'tcx> {

compiler/rustc_mir_transform/src/elaborate_drop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ where
548548
let subpath = self.elaborator.field_subpath(variant_path, field_idx);
549549
let tcx = self.tcx();
550550

551-
match self.elaborator.typing_env().typing_mode.0 {
551+
match self.elaborator.typing_env().typing_mode() {
552552
ty::TypingMode::PostAnalysis => {}
553553
ty::TypingMode::Coherence
554554
| ty::TypingMode::Analysis { .. }

compiler/rustc_ty_utils/src/instance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ fn resolve_associated_item<'tcx>(
154154
// and the obligation is monomorphic, otherwise passes such as
155155
// transmute checking and polymorphic MIR optimizations could
156156
// get a result which isn't correct for all monomorphizations.
157-
match typing_env.typing_mode.0 {
157+
match typing_env.typing_mode() {
158158
ty::TypingMode::Coherence
159159
| ty::TypingMode::Analysis { .. }
160160
| ty::TypingMode::Borrowck { .. }

0 commit comments

Comments
 (0)