Skip to content

Commit 836ac98

Browse files
committed
Stop using Bubble in coherence and instead emulate it with an intercrate check
1 parent ef32456 commit 836ac98

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

compiler/rustc_infer/src/infer/opaque_types.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ impl<'tcx> InferCtxt<'tcx> {
105105
let process = |a: Ty<'tcx>, b: Ty<'tcx>, a_is_expected| match *a.kind() {
106106
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) if def_id.is_local() => {
107107
let def_id = def_id.expect_local();
108+
if self.intercrate {
109+
// See comment on `insert_hidden_type` for why this is sufficient in coherence
110+
return Some(self.register_hidden_type(
111+
OpaqueTypeKey { def_id, args },
112+
cause.clone(),
113+
param_env,
114+
b,
115+
a_is_expected,
116+
));
117+
}
108118
match self.defining_use_anchor {
109119
DefiningAnchor::Bind(_) => {
110120
// Check that this is `impl Trait` type is
@@ -146,8 +156,10 @@ impl<'tcx> InferCtxt<'tcx> {
146156
}
147157
}
148158
DefiningAnchor::Bubble => {}
149-
DefiningAnchor::Error => return None,
150-
};
159+
DefiningAnchor::Error => {
160+
return None;
161+
}
162+
}
151163
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }) = *b.kind() {
152164
// We could accept this, but there are various ways to handle this situation, and we don't
153165
// want to make a decision on it right now. Likely this case is so super rare anyway, that

compiler/rustc_trait_selection/src/traits/coherence.rs

-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use rustc_infer::traits::{util, TraitEngine, TraitEngineExt};
2626
use rustc_middle::traits::query::NoSolution;
2727
use rustc_middle::traits::solve::{CandidateSource, Certainty, Goal};
2828
use rustc_middle::traits::specialization_graph::OverlapMode;
29-
use rustc_middle::traits::DefiningAnchor;
3029
use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams};
3130
use rustc_middle::ty::visit::{TypeVisitable, TypeVisitableExt};
3231
use rustc_middle::ty::{self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor};
@@ -190,7 +189,6 @@ fn overlap<'tcx>(
190189

191190
let infcx = tcx
192191
.infer_ctxt()
193-
.with_opaque_type_inference(DefiningAnchor::Bubble)
194192
.skip_leak_check(skip_leak_check.is_yes())
195193
.intercrate(true)
196194
.with_next_trait_solver(tcx.next_trait_solver_in_coherence())

0 commit comments

Comments
 (0)