Skip to content

Commit feee5f6

Browse files
committed
use the right typing mode for each mir phase
1 parent e283cb3 commit feee5f6

2 files changed

Lines changed: 39 additions & 15 deletions

File tree

compiler/rustc_const_eval/src/check_consts/qualifs.rs

Lines changed: 9 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, Ty};
12+
use rustc_middle::ty::{self, AdtDef, Ty, TypingMode};
1313
use rustc_middle::{bug, mir};
1414
use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt};
1515
use tracing::instrument;
@@ -100,13 +100,14 @@ impl Qualif for HasMutInterior {
100100
// Instead we invoke an obligation context manually, and provide the opaque type inference settings
101101
// that allow the trait solver to just error out instead of cycling.
102102
let freeze_def_id = cx.tcx.require_lang_item(LangItem::Freeze, cx.body.span);
103-
// FIXME(#132279): Once we've got a typing mode which reveals opaque types using the HIR
104-
// typeck results without causing query cycles, we should use this here instead of defining
105-
// opaque types.
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-
);
103+
let did = cx.body.source.def_id().expect_local();
104+
105+
let typing_env = if cx.tcx.use_typing_mode_borrowck() {
106+
cx.typing_env
107+
} else {
108+
ty::TypingEnv::new(cx.typing_env.param_env, TypingMode::analysis_in_body(cx.tcx, did))
109+
};
110+
110111
let (infcx, param_env) = cx.tcx.infer_ctxt().build_with_typing_env(typing_env);
111112
let ocx = ObligationCtxt::new(&infcx);
112113
let obligation = Obligation::new(

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -413,13 +413,36 @@ impl<'tcx> Body<'tcx> {
413413
}
414414

415415
pub fn typing_env(&self, tcx: TyCtxt<'tcx>) -> TypingEnv<'tcx> {
416-
match self.phase {
417-
// FIXME(#132279): we should reveal the opaques defined in the body during analysis.
418-
MirPhase::Built | MirPhase::Analysis(_) => TypingEnv::new(
419-
tcx.param_env(self.source.def_id()),
420-
ty::TypingMode::non_body_analysis(),
421-
),
422-
MirPhase::Runtime(_) => TypingEnv::post_analysis(tcx, self.source.def_id()),
416+
if tcx.use_typing_mode_borrowck() {
417+
match self.phase {
418+
MirPhase::Built if let Some(def_id) = self.source.def_id().as_local() => {
419+
TypingEnv::new(
420+
tcx.param_env(self.source.def_id()),
421+
ty::TypingMode::borrowck(tcx, def_id),
422+
)
423+
}
424+
MirPhase::Analysis(_) if let Some(def_id) = self.source.def_id().as_local() => {
425+
TypingEnv::new(
426+
tcx.param_env(self.source.def_id()),
427+
ty::TypingMode::post_borrowck_analysis(tcx, def_id),
428+
)
429+
}
430+
MirPhase::Built | MirPhase::Analysis(_) => {
431+
// This branch happens for drop glue and fn ptr shims.
432+
// FIXME: why do we do any of this analysis on drop glue etc?
433+
// This should ideally all be skipped.
434+
TypingEnv::post_analysis(tcx, self.source.def_id())
435+
}
436+
MirPhase::Runtime(_) => TypingEnv::post_analysis(tcx, self.source.def_id()),
437+
}
438+
} else {
439+
match self.phase {
440+
MirPhase::Built | MirPhase::Analysis(_) => TypingEnv::new(
441+
tcx.param_env(self.source.def_id()),
442+
ty::TypingMode::non_body_analysis(),
443+
),
444+
MirPhase::Runtime(_) => TypingEnv::post_analysis(tcx, self.source.def_id()),
445+
}
423446
}
424447
}
425448

0 commit comments

Comments
 (0)