Skip to content

Commit cbb8e0a

Browse files
authored
Rollup merge of rust-lang#121744 - oli-obk:eager_opaque_checks2, r=lcnr
Stop using Bubble in coherence and instead emulate it with an intercrate check r? ``@compiler-errors`` This change is kinda funny, because all I've done is reimplement `Bubble` behaviour for coherence without using `Bubble` explicitly.
2 parents 15a6822 + c98be32 commit cbb8e0a

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

compiler/rustc_infer/src/infer/opaque_types.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ impl<'tcx> InferCtxt<'tcx> {
101101
let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() {
102102
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) if def_id.is_local() => {
103103
let def_id = def_id.expect_local();
104+
if self.intercrate {
105+
// See comment on `insert_hidden_type` for why this is sufficient in coherence
106+
return Some(self.register_hidden_type(
107+
OpaqueTypeKey { def_id, args },
108+
cause.clone(),
109+
param_env,
110+
b,
111+
));
112+
}
104113
match self.defining_use_anchor {
105114
DefiningAnchor::Bind(_) => {
106115
// Check that this is `impl Trait` type is
@@ -142,8 +151,10 @@ impl<'tcx> InferCtxt<'tcx> {
142151
}
143152
}
144153
DefiningAnchor::Bubble => {}
145-
DefiningAnchor::Error => return None,
146-
};
154+
DefiningAnchor::Error => {
155+
return None;
156+
}
157+
}
147158
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }) = *b.kind() {
148159
// We could accept this, but there are various ways to handle this situation, and we don't
149160
// 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, FulfillmentErrorCode, TraitEngine, TraitEngineEx
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};
@@ -207,7 +206,6 @@ fn overlap<'tcx>(
207206

208207
let infcx = tcx
209208
.infer_ctxt()
210-
.with_opaque_type_inference(DefiningAnchor::Bubble)
211209
.skip_leak_check(skip_leak_check.is_yes())
212210
.intercrate(true)
213211
.with_next_trait_solver(tcx.next_trait_solver_in_coherence())

0 commit comments

Comments
 (0)