Skip to content

Commit ec8dc45

Browse files
Don't erase opaques from typing env for pseudo-canonicalization
1 parent f5cfc52 commit ec8dc45

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc_data_structures::undo_log::{Rollback, UndoLogs};
2020
use rustc_data_structures::unify as ut;
2121
use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed};
2222
use rustc_hir as hir;
23+
use rustc_hir::def::DefKind;
2324
use rustc_hir::def_id::{DefId, LocalDefId};
2425
use rustc_macros::extension;
2526
pub use rustc_macros::{TypeFoldable, TypeVisitable};
@@ -1249,8 +1250,16 @@ impl<'tcx> InferCtxt<'tcx> {
12491250
// to handle them without proper canonicalization. This means we may cause cycle
12501251
// errors and fail to reveal opaques while inside of bodies. We should rename this
12511252
// function and require explicit comments on all use-sites in the future.
1252-
ty::TypingMode::Analysis { defining_opaque_types_and_generators: _ }
1253-
| ty::TypingMode::Borrowck { defining_opaque_types: _ } => {
1253+
ty::TypingMode::Analysis { defining_opaque_types_and_generators } => {
1254+
TypingMode::Analysis {
1255+
defining_opaque_types_and_generators: self.tcx.mk_local_def_ids_from_iter(
1256+
defining_opaque_types_and_generators.iter().filter(|def_id| {
1257+
!matches!(self.tcx.def_kind(*def_id), DefKind::OpaqueTy)
1258+
}),
1259+
),
1260+
}
1261+
}
1262+
ty::TypingMode::Borrowck { defining_opaque_types: _ } => {
12541263
TypingMode::non_body_analysis()
12551264
}
12561265
mode @ (ty::TypingMode::Coherence

compiler/rustc_trait_selection/src/solve/fulfill.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use rustc_infer::traits::{
1010
FromSolverError, PredicateObligation, PredicateObligations, TraitEngine,
1111
};
1212
use rustc_middle::ty::{
13-
self, DelayedSet, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, TypingMode,
13+
self, DelayedSet, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
14+
TypingMode,
1415
};
1516
use rustc_next_trait_solver::delegate::SolverDelegate as _;
1617
use rustc_next_trait_solver::solve::{
@@ -343,9 +344,11 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for StalledOnCoroutines<'tcx> {
343344
&& def_id.as_local().is_some_and(|def_id| self.stalled_coroutines.contains(&def_id))
344345
{
345346
return ControlFlow::Break(());
347+
} else if ty.has_coroutines() {
348+
ty.super_visit_with(self)
349+
} else {
350+
ControlFlow::Continue(())
346351
}
347-
348-
ty.super_visit_with(self)
349352
}
350353
}
351354

compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,8 +1508,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15081508
defining_opaque_types_and_generators: defining_opaque_types,
15091509
}
15101510
| TypingMode::Borrowck { defining_opaque_types } => {
1511-
defining_opaque_types.is_empty()
1512-
|| (!pred.has_opaque_types() && !pred.has_coroutines())
1511+
defining_opaque_types.is_empty() || !pred.has_opaque_types()
15131512
}
15141513
// The hidden types of `defined_opaque_types` is not local to the current
15151514
// inference context, so we can freely move this to the global cache.

0 commit comments

Comments
 (0)