Skip to content

Commit 6eddc58

Browse files
committed
w
1 parent e4feeb8 commit 6eddc58

File tree

8 files changed

+35
-9
lines changed

8 files changed

+35
-9
lines changed

compiler/rustc_const_eval/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn provide(providers: &mut Providers) {
4747
providers.hooks.try_destructure_mir_constant_for_user_output =
4848
const_eval::try_destructure_mir_constant_for_user_output;
4949
providers.valtree_to_const_val = |tcx, (ty, valtree)| {
50-
const_eval::valtree_to_const_value(tcx, ty::ParamEnv::empty().and(ty), valtree)
50+
const_eval::valtree_to_const_value(tcx, ty::ParamEnv::reveal_all().and(ty), valtree)
5151
};
5252
providers.check_validity_requirement = |tcx, (init_kind, param_env_and_ty)| {
5353
util::check_validity_requirement(tcx, init_kind, param_env_and_ty)

compiler/rustc_infer/src/infer/mod.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,18 @@ impl<'tcx> InferCtxt<'tcx> {
12911291
/// which contains the necessary information to use the trait system without
12921292
/// using canonicalization or carrying this inference context around.
12931293
pub fn typing_env(&self, param_env: ty::ParamEnv<'tcx>) -> ty::TypingEnv<'tcx> {
1294-
ty::TypingEnv { typing_mode: self.typing_mode(param_env), param_env }
1294+
let typing_mode = match self.typing_mode(param_env) {
1295+
ty::TypingMode::Coherence => ty::TypingMode::Coherence,
1296+
// FIXME(#132279): This erases the `defining_opaque_types` as it isn't possible
1297+
// to handle them without proper canonicalization. This means we may cause cycle
1298+
// errors and fail to reveal opaques while inside of bodies. We should rename this
1299+
// function and require explicit comments on all use-sites in the future.
1300+
ty::TypingMode::Analysis { defining_opaque_types: _ } => {
1301+
TypingMode::non_body_analysis()
1302+
}
1303+
ty::TypingMode::PostAnalysis => ty::TypingMode::PostAnalysis,
1304+
};
1305+
ty::TypingEnv { typing_mode, param_env }
12951306
}
12961307

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

compiler/rustc_middle/src/ty/consts/kind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'tcx> ty::UnevaluatedConst<'tcx> {
3737
args: ty::GenericArgs::identity_for_item(tcx, self.def),
3838
})
3939
} else {
40-
(typing_env.with_reveal_all_normalized(tcx), tcx.erase_regions(self))
40+
(tcx.erase_regions(typing_env).with_reveal_all_normalized(tcx), tcx.erase_regions(self))
4141
}
4242
}
4343
}

compiler/rustc_middle/src/ty/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,13 @@ impl<'tcx> TypingEnv<'tcx> {
12021202
T: TypeVisitable<TyCtxt<'tcx>>,
12031203
{
12041204
debug_assert!(!value.has_infer());
1205-
debug_assert!(!value.has_placeholders());
1205+
// FIXME(#132279): We should assert that the value does not contain any placeholders
1206+
// as these placeholders are also local to the current inference context. However, we
1207+
// currently use pseudo-canonical queries in the trait solver which replaces params with
1208+
// placeholders. We should also simply not use pseudo-canonical queries in the trait
1209+
// solver, at which point we can readd this assert.
1210+
//
1211+
// debug_assert!(!value.has_placeholders());
12061212
PseudoCanonicalInput { typing_env: self, value }
12071213
}
12081214
}

compiler/rustc_mir_transform/src/add_moves_for_packed_drops.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_middle::mir::patch::MirPatch;
22
use rustc_middle::mir::*;
3-
use rustc_middle::ty::TyCtxt;
3+
use rustc_middle::ty::{self, TyCtxt};
44
use tracing::debug;
55

66
use crate::util;
@@ -41,7 +41,9 @@ impl<'tcx> crate::MirPass<'tcx> for AddMovesForPackedDrops {
4141
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
4242
debug!("add_moves_for_packed_drops({:?} @ {:?})", body.source, body.span);
4343
let mut patch = MirPatch::new(body);
44-
let typing_env = body.typing_env(tcx);
44+
// FIXME(#132279): This is used during the phase transition from analysis
45+
// to runtime, so we have to manually specify the correct typing mode.
46+
let typing_env = ty::TypingEnv::post_analysis(tcx, body.source.def_id());
4547

4648
for (bb, data) in body.basic_blocks.iter_enumerated() {
4749
let loc = Location { block: bb, statement_index: data.statements.len() };

compiler/rustc_mir_transform/src/elaborate_drops.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ impl<'tcx> crate::MirPass<'tcx> for ElaborateDrops {
5454
#[instrument(level = "trace", skip(self, tcx, body))]
5555
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
5656
debug!("elaborate_drops({:?} @ {:?})", body.source, body.span);
57-
let typing_env = body.typing_env(tcx);
57+
// FIXME(#132279): This is used during the phase transition from analysis
58+
// to runtime, so we have to manually specify the correct typing mode.
59+
let typing_env = ty::TypingEnv::post_analysis(tcx, body.source.def_id());
5860
// For types that do not need dropping, the behaviour is trivial. So we only need to track
5961
// init/uninit for types that do need dropping.
6062
let move_data = MoveData::gather_moves(body, tcx, |ty| ty.needs_drop(tcx, typing_env));

compiler/rustc_mir_transform/src/known_panics_lint.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,12 @@ impl<'tcx> ty::layout::HasTypingEnv<'tcx> for ConstPropagator<'_, 'tcx> {
179179
impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
180180
fn new(body: &'mir Body<'tcx>, tcx: TyCtxt<'tcx>) -> ConstPropagator<'mir, 'tcx> {
181181
let def_id = body.source.def_id();
182-
let typing_env = body.typing_env(tcx);
182+
let typing_env = ty::TypingEnv::post_analysis(tcx, def_id);
183183

184184
let can_const_prop = CanConstProp::check(tcx, typing_env, body);
185+
// FIXME(#132279): This is used during the phase transition from analysis
186+
// to runtime, so we have to manually specify the correct typing mode.
187+
let typing_env = ty::TypingEnv::post_analysis(tcx, body.source.def_id());
185188
let ecx = InterpCx::new(tcx, tcx.def_span(def_id), typing_env.param_env, DummyMachine);
186189

187190
ConstPropagator {

compiler/rustc_mir_transform/src/reveal_all.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ pub(super) struct RevealAll;
88

99
impl<'tcx> crate::MirPass<'tcx> for RevealAll {
1010
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
11-
let typing_env = body.typing_env(tcx);
11+
// FIXME(#132279): This is used during the phase transition from analysis
12+
// to runtime, so we have to manually specify the correct typing mode.
13+
let typing_env = ty::TypingEnv::post_analysis(tcx, body.source.def_id());
1214
RevealAllVisitor { tcx, typing_env }.visit_body_preserves_cfg(body);
1315
}
1416
}

0 commit comments

Comments
 (0)