Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b71fb5e

Browse files
committedNov 18, 2024
Auto merge of #132460 - lcnr:questionable-uwu, r=compiler-errors
Use `TypingMode` throughout the compiler instead of `ParamEnv` Hopefully the biggest single PR as part of rust-lang/types-team#128. ## `infcx.typing_env` while defining opaque types I don't know how'll be able to correctly handle opaque types when using something taking a `TypingEnv` while defining opaque types. To correctly handle the opaques we need to be able to pass in the current `opaque_type_storage` and return constraints, i.e. we need to use a proper canonical query. We should migrate all the queries used during HIR typeck and borrowck where this matters to proper canonical queries. This is ## `layout_of` and `Reveal::All` We convert the `ParamEnv` to `Reveal::All` right at the start of the `layout_of` query, so I've changed callers of `layout_of` to already use a post analysis `TypingEnv` when encountering it. https://github.com/rust-lang/rust/blob/ca87b535a05097df6abbe2a031b057de2cefac5b/compiler/rustc_ty_utils/src/layout.rs#L51 ## `Ty::is_[unpin|sized|whatever]` I haven't migrated `fn is_item_raw` to use `TypingEnv`, will do so in a followup PR, this should significantly reduce the amount of `typing_env.param_env`. At some point there will probably be zero such uses as using the type system while ignoring the `typing_mode` is incorrect. ## `MirPhase` and phase-transitions When inside of a MIR-body, we can mostly use its `MirPhase` to figure out the right `typing_mode`. This does not work during phase transitions, most notably when transitioning from `Analysis` to `Runtime`: https://github.com/rust-lang/rust/blob/dae7ac133b9eda152784c075facb31a6688c92b1/compiler/rustc_mir_transform/src/lib.rs#L606-L625 All these passes still run with `MirPhase::Analysis`, but we should only use `Reveal::All` once we're run the `RevealAll` pass. This required me to manually construct the right `TypingEnv` in all these passes. Given that it feels somewhat easy to accidentally miss this going forward, I would maybe like to change `Body::phase` to an `Option` and replace it at the start of phase transitions. This then makes it clear that the MIR is currently in a weird state. r? `@ghost`
2 parents 03ee484 + 2e087d2 commit b71fb5e

File tree

240 files changed

+1745
-1341
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

240 files changed

+1745
-1341
lines changed
 

‎compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
682682
// Normalize before comparing to see through type aliases and projections.
683683
let old_ty = ty::EarlyBinder::bind(ty).instantiate(tcx, generic_args);
684684
let new_ty = ty::EarlyBinder::bind(ty).instantiate(tcx, new_args);
685-
if let Ok(old_ty) = tcx.try_normalize_erasing_regions(self.param_env, old_ty)
686-
&& let Ok(new_ty) = tcx.try_normalize_erasing_regions(self.param_env, new_ty)
685+
if let Ok(old_ty) =
686+
tcx.try_normalize_erasing_regions(self.infcx.typing_env(self.param_env), old_ty)
687+
&& let Ok(new_ty) = tcx.try_normalize_erasing_regions(
688+
self.infcx.typing_env(self.param_env),
689+
new_ty,
690+
)
687691
{
688692
old_ty == new_ty
689693
} else {
@@ -703,7 +707,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
703707
// Test the callee's predicates, substituting in `ref_ty` for the moved argument type.
704708
clauses.instantiate(tcx, new_args).predicates.iter().all(|&(mut clause)| {
705709
// Normalize before testing to see through type aliases and projections.
706-
if let Ok(normalized) = tcx.try_normalize_erasing_regions(self.param_env, clause) {
710+
if let Ok(normalized) =
711+
tcx.try_normalize_erasing_regions(self.infcx.typing_env(self.param_env), clause)
712+
{
707713
clause = normalized;
708714
}
709715
self.infcx.predicate_must_hold_modulo_regions(&Obligation::new(
@@ -3831,11 +3837,16 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
38313837
if tcx.is_diagnostic_item(sym::deref_method, method_did) {
38323838
let deref_target =
38333839
tcx.get_diagnostic_item(sym::deref_target).and_then(|deref_target| {
3834-
Instance::try_resolve(tcx, self.param_env, deref_target, method_args)
3835-
.transpose()
3840+
Instance::try_resolve(
3841+
tcx,
3842+
self.infcx.typing_env(self.param_env),
3843+
deref_target,
3844+
method_args,
3845+
)
3846+
.transpose()
38363847
});
38373848
if let Some(Ok(instance)) = deref_target {
3838-
let deref_target_ty = instance.ty(tcx, self.param_env);
3849+
let deref_target_ty = instance.ty(tcx, self.infcx.typing_env(self.param_env));
38393850
err.note(format!("borrow occurs due to deref coercion to `{deref_target_ty}`"));
38403851
err.span_note(tcx.def_span(instance.def_id()), "deref defined here");
38413852
}

‎compiler/rustc_borrowck/src/diagnostics/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
864864

865865
let kind = call_kind(
866866
self.infcx.tcx,
867-
self.param_env,
867+
self.infcx.typing_env(self.param_env),
868868
method_did,
869869
method_args,
870870
*fn_span,

0 commit comments

Comments
 (0)
Please sign in to comment.