Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions compiler/rustc_const_eval/src/check_consts/qualifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_errors::ErrorGuaranteed;
use rustc_hir::LangItem;
use rustc_infer::infer::TyCtxtInferExt;
use rustc_middle::mir::*;
use rustc_middle::ty::{self, AdtDef, Ty};
use rustc_middle::ty::{self, AdtDef, Ty, TypingMode};
use rustc_middle::{bug, mir};
use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt};
use tracing::instrument;
Expand Down Expand Up @@ -103,10 +103,14 @@ impl Qualif for HasMutInterior {
// FIXME(#132279): Once we've got a typing mode which reveals opaque types using the HIR
// typeck results without causing query cycles, we should use this here instead of defining
// opaque types.
Comment on lines 103 to 105
Copy link
Copy Markdown
Contributor

@lcnr lcnr May 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do remove the fixme please

View changes since the review

let typing_env = ty::TypingEnv::new(
cx.typing_env.param_env,
ty::TypingMode::analysis_in_body(cx.tcx, cx.body.source.def_id().expect_local()),
);
let did = cx.body.source.def_id().expect_local();

let typing_env = if cx.tcx.use_typing_mode_borrowck() {
cx.typing_env
} else {
ty::TypingEnv::new(cx.typing_env.param_env, TypingMode::analysis_in_body(cx.tcx, did))
};

let (infcx, param_env) = cx.tcx.infer_ctxt().build_with_typing_env(typing_env);
let ocx = ObligationCtxt::new(&infcx);
let obligation = Obligation::new(
Expand Down
38 changes: 31 additions & 7 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,37 @@ impl<'tcx> Body<'tcx> {
}

pub fn typing_env(&self, tcx: TyCtxt<'tcx>) -> TypingEnv<'tcx> {
match self.phase {
// FIXME(#132279): we should reveal the opaques defined in the body during analysis.
MirPhase::Built | MirPhase::Analysis(_) => TypingEnv::new(
tcx.param_env(self.source.def_id()),
ty::TypingMode::non_body_analysis(),
),
MirPhase::Runtime(_) => TypingEnv::post_analysis(tcx, self.source.def_id()),
if tcx.use_typing_mode_borrowck() {
match self.phase {
MirPhase::Built if let Some(def_id) = self.source.def_id().as_local() => {
TypingEnv::new(
tcx.param_env(self.source.def_id()),
ty::TypingMode::borrowck(tcx, def_id),
)
}
MirPhase::Analysis(_) if let Some(def_id) = self.source.def_id().as_local() => {
TypingEnv::new(
tcx.param_env(self.source.def_id()),
ty::TypingMode::post_borrowck_analysis(tcx, def_id),
)
}
MirPhase::Built | MirPhase::Analysis(_) => {
// This branch happens for drop glue and fn ptr shims.
// FIXME: why do we do any of this analysis on drop glue etc?
// This should ideally all be skipped.
TypingEnv::post_analysis(tcx, self.source.def_id())
}
MirPhase::Runtime(_) => TypingEnv::post_analysis(tcx, self.source.def_id()),
}
} else {
match self.phase {
// FIXME(#132279): we should reveal the opaques defined in the body during analysis.
Copy link
Copy Markdown
Contributor

@lcnr lcnr May 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that fixme can also be removed 🤷 there's nothing actionable here

View changes since the review

MirPhase::Built | MirPhase::Analysis(_) => TypingEnv::new(
tcx.param_env(self.source.def_id()),
ty::TypingMode::non_body_analysis(),
),
MirPhase::Runtime(_) => TypingEnv::post_analysis(tcx, self.source.def_id()),
}
}
}

Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,12 +539,6 @@ pub trait HasTyCtxt<'tcx>: HasDataLayout {

pub trait HasTypingEnv<'tcx> {
fn typing_env(&self) -> ty::TypingEnv<'tcx>;

/// FIXME(#132279): This method should not be used as in the future
/// everything should take a `TypingEnv` instead. Remove it as that point.
fn param_env(&self) -> ty::ParamEnv<'tcx> {
self.typing_env().param_env
}
}

impl<'tcx> HasDataLayout for TyCtxt<'tcx> {
Expand Down