Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ pub(crate) struct BorrowckInferCtxt<'tcx> {

impl<'tcx> BorrowckInferCtxt<'tcx> {
pub(crate) fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId, root_def_id: LocalDefId) -> Self {
let typing_mode = if tcx.use_typing_mode_borrowck() {
let typing_mode = if tcx.use_typing_mode_post_typeck_until_borrowck() {
TypingMode::borrowck(tcx, def_id)
} else {
TypingMode::analysis_in_body(tcx, def_id)
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_borrowck/src/region_infer/opaque_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ fn collect_defining_uses<'tcx>(
DefiningScopeKind::MirBorrowck,
) {
// A non-defining use. This is a hard error on stable and gets ignored
// with `TypingMode::Borrowck`.
if infcx.tcx.use_typing_mode_borrowck() {
// with `TypingMode::PostTypeckUntilBorrowck`.
if infcx.tcx.use_typing_mode_post_typeck_until_borrowck() {
match err {
NonDefiningUseReason::Tainted(guar) => add_hidden_type(
infcx.tcx,
Expand Down Expand Up @@ -327,7 +327,7 @@ fn compute_definition_site_hidden_types_from_defining_uses<'tcx>(
// If we're using the next solver, the unconstrained region may be resolved by a
// fully defining use from another body.
// So we don't generate error eagerly here.
if rcx.infcx.tcx.use_typing_mode_borrowck() {
if rcx.infcx.tcx.use_typing_mode_post_typeck_until_borrowck() {
unconstrained_hidden_type_errors.push(UnexpectedHiddenRegion {
def_id,
hidden_type,
Expand Down Expand Up @@ -366,7 +366,7 @@ fn compute_definition_site_hidden_types_from_defining_uses<'tcx>(
// the hidden type becomes the opaque type itself. In this case, this was an opaque
// usage of the opaque type and we can ignore it. This check is mirrored in typeck's
// writeback.
if !rcx.infcx.tcx.use_typing_mode_borrowck() {
if !rcx.infcx.tcx.use_typing_mode_post_typeck_until_borrowck() {
if let &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) =
hidden_type.ty.skip_binder().kind()
&& def_id == opaque_type_key.def_id.to_def_id()
Expand Down Expand Up @@ -540,7 +540,7 @@ pub(crate) fn apply_definition_site_hidden_types<'tcx>(
let mut errors = Vec::new();
for &(key, hidden_type) in opaque_types {
let Some(expected) = hidden_types.get(&key.def_id) else {
if !tcx.use_typing_mode_borrowck() {
if !tcx.use_typing_mode_post_typeck_until_borrowck() {
if let &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) =
hidden_type.ty.kind()
&& def_id == key.def_id.to_def_id()
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/check_consts/qualifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl Qualif for HasMutInterior {
let freeze_def_id = cx.tcx.require_lang_item(LangItem::Freeze, cx.body.span);
let did = cx.body.source.def_id().expect_local();

let typing_env = if cx.tcx.use_typing_mode_borrowck() {
let typing_env = if cx.tcx.use_typing_mode_post_typeck_until_borrowck() {
cx.typing_env
} else {
ty::TypingEnv::new(cx.typing_env.param_env, TypingMode::analysis_in_body(cx.tcx, did))
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_const_eval/src/const_eval/eval_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ fn retry_codegen_mode_with_postanalysis<'tcx, K: TypeVisitable<TyCtxt<'tcx>>, V>
}
}
ty::TypingMode::Coherence
| ty::TypingMode::Analysis { .. }
| ty::TypingMode::Borrowck { .. }
| ty::TypingMode::PostBorrowckAnalysis { .. }
| ty::TypingMode::Typeck { .. }
| ty::TypingMode::PostTypeckUntilBorrowck { .. }
| ty::TypingMode::PostBorrowck { .. }
| ty::TypingMode::PostAnalysis => {}
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_const_eval/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ fn assert_typing_mode(typing_mode: ty::TypingMode<'_>) {
// Const eval always happens in PostAnalysis or Codegen mode. See the comment in
// `InterpCx::new` for more details.
ty::TypingMode::Coherence
| ty::TypingMode::Analysis { .. }
| ty::TypingMode::Borrowck { .. }
| ty::TypingMode::PostBorrowckAnalysis { .. } => bug!(
| ty::TypingMode::Typeck { .. }
| ty::TypingMode::PostTypeckUntilBorrowck { .. }
| ty::TypingMode::PostBorrowck { .. } => bug!(
"Const eval should always happens in PostAnalysis or Codegen mode. See the comment on `assert_typing_mode` for more details."
),
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ fn check_opaque_meets_bounds<'tcx>(
};
let param_env = tcx.param_env(defining_use_anchor);

// FIXME(#132279): Once `PostBorrowckAnalysis` is supported in the old solver, this branch should be removed.
// FIXME(#132279): Once `PostBorrowck` is supported in the old solver, this branch should be removed.
let infcx = tcx.infer_ctxt().build(if tcx.next_trait_solver_globally() {
TypingMode::post_borrowck_analysis(tcx, defining_use_anchor)
} else {
Expand Down Expand Up @@ -2321,7 +2321,7 @@ pub(super) fn check_coroutine_obligations(
}
} else {
// We're not checking region constraints here, so we can simply drop the
// added opaque type uses in `TypingMode::Borrowck`.
// added opaque type uses in `TypingMode::PostTypeckUntilBorrowck`.
let _ = infcx.take_opaque_types();
}

Expand All @@ -2338,7 +2338,7 @@ pub(super) fn check_potentially_region_dependent_goals<'tcx>(
let typeck_results = tcx.typeck(def_id);
let param_env = tcx.param_env(def_id);

// We use `TypingMode::Borrowck` as we want to use the opaque types computed by HIR typeck.
// We use `TypingMode::PostTypeckUntilBorrowck` as we want to use the opaque types computed by HIR typeck.
let typing_mode = TypingMode::borrowck(tcx, def_id);
let infcx = tcx.infer_ctxt().ignoring_regions().build(typing_mode);
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,12 +657,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.select_obligations_where_possible(|_| {});

let defining_opaque_types_and_generators = match self.typing_mode() {
ty::TypingMode::Analysis { defining_opaque_types_and_generators } => {
ty::TypingMode::Typeck { defining_opaque_types_and_generators } => {
defining_opaque_types_and_generators
}
ty::TypingMode::Coherence
| ty::TypingMode::Borrowck { .. }
| ty::TypingMode::PostBorrowckAnalysis { .. }
| ty::TypingMode::PostTypeckUntilBorrowck { .. }
| ty::TypingMode::PostBorrowck { .. }
| ty::TypingMode::PostAnalysis
| ty::TypingMode::Codegen => {
bug!()
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_typeck/src/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ impl<'tcx> FnCtxt<'_, 'tcx> {

let tcx = self.tcx;
let defining_opaque_types_and_generators = match self.typing_mode() {
ty::TypingMode::Analysis { defining_opaque_types_and_generators } => {
ty::TypingMode::Typeck { defining_opaque_types_and_generators } => {
defining_opaque_types_and_generators
}
ty::TypingMode::Coherence
| ty::TypingMode::Borrowck { .. }
| ty::TypingMode::PostBorrowckAnalysis { .. }
| ty::TypingMode::PostTypeckUntilBorrowck { .. }
| ty::TypingMode::PostBorrowck { .. }
| ty::TypingMode::PostAnalysis
| ty::TypingMode::Codegen => {
bug!()
Expand Down
30 changes: 14 additions & 16 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,19 +342,19 @@ impl<'tcx> Drop for InferCtxt<'tcx> {
let mut inner = self.inner.borrow_mut();
let opaque_type_storage = &mut inner.opaque_type_storage;

// No need for the drop bomb when we're in TypingMode::Borrowck, and the InferCtxt doesn't consider regions.
// This is okay since in `Borrowck`, the only reason we care about opaques is in relation to regions.
// In some places *after* typeck, like in lints we use `TypingMode::Borrowck`
// to prevent defining opaque types and we simply don't care about regions.
// No need for the drop bomb when we're in `TypingMode::PostTypeckUntilBorrowck`, and the `InferCtxt`
// doesn't consider regions. This is okay since after typeck, the only reason we care about opaques is
// in relation to regions. In some places *after* typeck that aren't borrowck, like in lints we use
// `TypingMode::PostTypeckUntilBorrowck` to prevent defining opaque types and we simply don't care about regions.
match self.typing_mode_raw() {
TypingMode::Coherence
| TypingMode::Analysis { .. }
| TypingMode::PostBorrowckAnalysis { .. }
| TypingMode::Typeck { .. }
| TypingMode::PostBorrowck { .. }
| TypingMode::PostAnalysis
| TypingMode::Codegen => {}
// In erased mode, the opaque type storage is always empty
TypingMode::ErasedNotCoherence(..) => {}
TypingMode::Borrowck { .. } => {
TypingMode::PostTypeckUntilBorrowck { .. } => {
if !self.considering_regions {
return;
}
Expand Down Expand Up @@ -1146,17 +1146,15 @@ impl<'tcx> InferCtxt<'tcx> {
pub fn can_define_opaque_ty(&self, id: impl Into<DefId>) -> bool {
debug_assert!(!self.next_trait_solver());
match self.typing_mode_raw().assert_not_erased() {
TypingMode::Analysis {
defining_opaque_types_and_generators: defining_opaque_types,
}
| TypingMode::Borrowck { defining_opaque_types } => {
TypingMode::Typeck { defining_opaque_types_and_generators: defining_opaque_types }
| TypingMode::PostTypeckUntilBorrowck { defining_opaque_types } => {
id.into().as_local().is_some_and(|def_id| defining_opaque_types.contains(&def_id))
}
// FIXME(#132279): This function is quite weird in post-analysis
// and post-borrowck analysis mode. We may need to modify its uses
// to support PostBorrowckAnalysis in the old solver as well.
// to support PostBorrowck in the old solver as well.
TypingMode::Coherence
| TypingMode::PostBorrowckAnalysis { .. }
| TypingMode::PostBorrowck { .. }
| TypingMode::PostAnalysis
| TypingMode::Codegen => false,
}
Expand Down Expand Up @@ -1482,12 +1480,12 @@ impl<'tcx> InferCtxt<'tcx> {
// to handle them without proper canonicalization. This means we may cause cycle
// errors and fail to reveal opaques while inside of bodies. We should rename this
// function and require explicit comments on all use-sites in the future.
ty::TypingMode::Analysis { defining_opaque_types_and_generators: _ }
| ty::TypingMode::Borrowck { defining_opaque_types: _ } => {
ty::TypingMode::Typeck { defining_opaque_types_and_generators: _ }
| ty::TypingMode::PostTypeckUntilBorrowck { defining_opaque_types: _ } => {
TypingMode::non_body_analysis()
}
mode @ (ty::TypingMode::Coherence
| ty::TypingMode::PostBorrowckAnalysis { .. }
| ty::TypingMode::PostBorrowck { .. }
| ty::TypingMode::PostAnalysis
| ty::TypingMode::Codegen) => mode,
ty::TypingMode::ErasedNotCoherence(MayBeErased) => unreachable!(),
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_infer/src/infer/opaque_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl<'tcx> InferCtxt<'tcx> {
// our trait.
goals.push(Goal::new(tcx, param_env, ty::PredicateKind::Ambiguous));
}
ty::TypingMode::Analysis { .. } => {
ty::TypingMode::Typeck { .. } => {
let prev = self
.inner
.borrow_mut()
Expand All @@ -254,7 +254,7 @@ impl<'tcx> InferCtxt<'tcx> {
);
}
}
ty::TypingMode::Borrowck { .. } => {
ty::TypingMode::PostTypeckUntilBorrowck { .. } => {
let prev = self
.inner
.borrow_mut()
Expand Down Expand Up @@ -283,7 +283,7 @@ impl<'tcx> InferCtxt<'tcx> {
.map(|obligation| obligation.as_goal()),
);
}
mode @ (ty::TypingMode::PostBorrowckAnalysis { .. }
mode @ (ty::TypingMode::PostBorrowck { .. }
| ty::TypingMode::PostAnalysis
| ty::TypingMode::Codegen) => {
bug!("insert hidden type in {mode:?}")
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ impl<'tcx> LateContext<'tcx> {
/// building a new `InferCtxt`.
pub fn typing_mode(&self) -> TypingMode<'tcx> {
if let Some(body_id) = self.enclosing_body
&& self.tcx.use_typing_mode_borrowck()
&& self.tcx.use_typing_mode_post_typeck_until_borrowck()
{
let def_id = self.tcx.hir_enclosing_body_owner(body_id.hir_id);
TypingMode::borrowck(self.tcx, def_id)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ impl<'tcx> Body<'tcx> {
}

pub fn typing_env(&self, tcx: TyCtxt<'tcx>) -> TypingEnv<'tcx> {
if tcx.use_typing_mode_borrowck() {
if tcx.use_typing_mode_post_typeck_until_borrowck() {
match self.phase {
MirPhase::Built if let Some(def_id) = self.source.def_id().as_local() => {
TypingEnv::new(
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2697,8 +2697,9 @@ impl<'tcx> TyCtxt<'tcx> {
}

#[allow(rustc::bad_opt_access)]
pub fn use_typing_mode_borrowck(self) -> bool {
self.next_trait_solver_globally() || self.sess.opts.unstable_opts.typing_mode_borrowck
pub fn use_typing_mode_post_typeck_until_borrowck(self) -> bool {
self.next_trait_solver_globally()
|| self.sess.opts.unstable_opts.typing_mode_post_typeck_until_borrowck
}

pub fn assumptions_on_binders(self) -> bool {
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,9 +1127,9 @@ impl<'tcx> TypingEnv<'tcx> {
let TypingEnv { typing_mode, param_env } = self;
match typing_mode.0.assert_not_erased() {
TypingMode::Coherence
| TypingMode::Analysis { .. }
| TypingMode::Borrowck { .. }
| TypingMode::PostBorrowckAnalysis { .. } => {}
| TypingMode::Typeck { .. }
| TypingMode::PostTypeckUntilBorrowck { .. }
| TypingMode::PostBorrowck { .. } => {}
TypingMode::PostAnalysis | TypingMode::Codegen => return self,
}

Expand All @@ -1143,9 +1143,9 @@ impl<'tcx> TypingEnv<'tcx> {
let TypingEnv { typing_mode, param_env } = self;
match typing_mode.0.assert_not_erased() {
TypingMode::Coherence
| TypingMode::Analysis { .. }
| TypingMode::Borrowck { .. }
| TypingMode::PostBorrowckAnalysis { .. }
| TypingMode::Typeck { .. }
| TypingMode::PostTypeckUntilBorrowck { .. }
| TypingMode::PostBorrowck { .. }
| TypingMode::PostAnalysis => {}
TypingMode::Codegen => return self,
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_mir_transform/src/elaborate_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,9 +782,9 @@ where
match self.elaborator.typing_env().typing_mode().assert_not_erased() {
ty::TypingMode::PostAnalysis | ty::TypingMode::Codegen => {}
ty::TypingMode::Coherence
| ty::TypingMode::Analysis { .. }
| ty::TypingMode::Borrowck { .. }
| ty::TypingMode::PostBorrowckAnalysis { .. } => {
| ty::TypingMode::Typeck { .. }
| ty::TypingMode::PostTypeckUntilBorrowck { .. }
| ty::TypingMode::PostBorrowck { .. } => {
bug!()
}
}
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,9 @@ where
// See trait-system-refactor-initiative#226 for some ideas here.
let assemble_impls = match self.typing_mode() {
TypingMode::Coherence => true,
TypingMode::Analysis { .. }
| TypingMode::Borrowck { .. }
| TypingMode::PostBorrowckAnalysis { .. }
TypingMode::Typeck { .. }
| TypingMode::PostTypeckUntilBorrowck { .. }
| TypingMode::PostBorrowck { .. }
| TypingMode::PostAnalysis
| TypingMode::Codegen
| TypingMode::ErasedNotCoherence(MayBeErased) => !candidates.iter().any(|c| {
Expand Down Expand Up @@ -1054,10 +1054,10 @@ where
let self_ty = goal.predicate.self_ty();
// We only use this hack during HIR typeck.
let opaque_types = match self.typing_mode() {
TypingMode::Analysis { .. } => self.opaques_with_sub_unified_hidden_type(self_ty),
TypingMode::Typeck { .. } => self.opaques_with_sub_unified_hidden_type(self_ty),
TypingMode::Coherence
| TypingMode::Borrowck { .. }
| TypingMode::PostBorrowckAnalysis { .. }
| TypingMode::PostTypeckUntilBorrowck { .. }
| TypingMode::PostBorrowck { .. }
| TypingMode::PostAnalysis
| TypingMode::Codegen => vec![],
TypingMode::ErasedNotCoherence(MayBeErased) => {
Expand Down
18 changes: 9 additions & 9 deletions compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,20 +777,20 @@ where
) => RerunDecision::Yes,
(
RerunCondition::OpaqueInStorage(defids),
TypingMode::PostBorrowckAnalysis { defined_opaque_types: opaques }
| TypingMode::Analysis { defining_opaque_types_and_generators: opaques }
| TypingMode::Borrowck { defining_opaque_types: opaques },
TypingMode::PostBorrowck { defined_opaque_types: opaques }
| TypingMode::Typeck { defining_opaque_types_and_generators: opaques }
| TypingMode::PostTypeckUntilBorrowck { defining_opaque_types: opaques },
) => opaque_in_storage(opaques, defids),
// =============================
(RerunCondition::AnyOpaqueHasInferAsHidden, TypingMode::Analysis { .. }) => {
(RerunCondition::AnyOpaqueHasInferAsHidden, TypingMode::Typeck { .. }) => {
any_opaque_has_infer_as_hidden()
}
(
RerunCondition::AnyOpaqueHasInferAsHidden,
TypingMode::PostBorrowckAnalysis { .. }
TypingMode::PostBorrowck { .. }
| TypingMode::PostAnalysis
| TypingMode::Codegen
| TypingMode::Borrowck { .. },
| TypingMode::PostTypeckUntilBorrowck { .. },
) => RerunDecision::No,
// =============================
(
Expand All @@ -799,7 +799,7 @@ where
) => RerunDecision::No,
(
RerunCondition::OpaqueInStorageOrAnyOpaqueHasInferAsHidden(defids),
TypingMode::Analysis { defining_opaque_types_and_generators: opaques },
TypingMode::Typeck { defining_opaque_types_and_generators: opaques },
) => {
if let RerunDecision::Yes = any_opaque_has_infer_as_hidden() {
RerunDecision::Yes
Expand All @@ -811,8 +811,8 @@ where
}
(
RerunCondition::OpaqueInStorageOrAnyOpaqueHasInferAsHidden(defids),
TypingMode::PostBorrowckAnalysis { defined_opaque_types: opaques }
| TypingMode::Borrowck { defining_opaque_types: opaques },
TypingMode::PostBorrowck { defined_opaque_types: opaques }
| TypingMode::PostTypeckUntilBorrowck { defining_opaque_types: opaques },
) => opaque_in_storage(opaques, defids),
};

Expand Down
Loading
Loading