1
Fork 0

Remove intercrate and mark_ambiguous from Relation

This commit is contained in:
Michael Goulet 2023-04-04 00:08:32 +00:00
parent 48829ea74b
commit a368316905
12 changed files with 22 additions and 133 deletions

View file

@ -137,6 +137,18 @@ impl<'tcx> InferCtxt<'tcx> {
Err(TypeError::Sorts(ty::relate::expected_found(relation, a, b)))
}
// During coherence, opaque types should be treated as *possibly*
// equal to each other, even if their generic params differ, as
// they could resolve to the same hidden type, even for different
// generic params.
(
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, .. }),
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }),
) if self.intercrate && a_def_id == b_def_id => {
relation.register_predicates([ty::Binder::dummy(ty::PredicateKind::Ambiguous)]);
Ok(a)
}
_ => ty::relate::super_relate_tys(relation, a, b),
}
}
@ -505,10 +517,6 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
Obligation::new(self.infcx.tcx, self.trace.cause.clone(), self.param_env, to_pred)
}))
}
pub fn mark_ambiguous(&mut self) {
self.register_predicates([ty::Binder::dummy(ty::PredicateKind::Ambiguous)]);
}
}
struct Generalizer<'cx, 'tcx> {
@ -581,10 +589,6 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
self.infcx.tcx
}
fn intercrate(&self) -> bool {
self.infcx.intercrate
}
fn param_env(&self) -> ty::ParamEnv<'tcx> {
self.param_env
}
@ -597,10 +601,6 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
true
}
fn mark_ambiguous(&mut self) {
span_bug!(self.cause.span, "opaque types are handled in `tys`");
}
fn binders<T>(
&mut self,
a: ty::Binder<'tcx, T>,

View file

@ -35,10 +35,6 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> {
self.fields.tcx()
}
fn intercrate(&self) -> bool {
self.fields.infcx.intercrate
}
fn param_env(&self) -> ty::ParamEnv<'tcx> {
self.fields.param_env
}
@ -47,10 +43,6 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> {
self.a_is_expected
}
fn mark_ambiguous(&mut self) {
self.fields.mark_ambiguous();
}
fn relate_item_substs(
&mut self,
_item_def_id: DefId,

View file

@ -2697,11 +2697,6 @@ impl<'tcx> TypeRelation<'tcx> for SameTypeModuloInfer<'_, 'tcx> {
self.0.tcx
}
fn intercrate(&self) -> bool {
assert!(!self.0.intercrate);
false
}
fn param_env(&self) -> ty::ParamEnv<'tcx> {
// Unused, only for consts which we treat as always equal
ty::ParamEnv::empty()
@ -2715,10 +2710,6 @@ impl<'tcx> TypeRelation<'tcx> for SameTypeModuloInfer<'_, 'tcx> {
true
}
fn mark_ambiguous(&mut self) {
bug!()
}
fn relate_with_variance<T: relate::Relate<'tcx>>(
&mut self,
_variance: ty::Variance,

View file

@ -29,11 +29,6 @@ impl<'tcx> TypeRelation<'tcx> for Glb<'_, '_, 'tcx> {
"Glb"
}
fn intercrate(&self) -> bool {
assert!(!self.fields.infcx.intercrate);
false
}
fn tcx(&self) -> TyCtxt<'tcx> {
self.fields.tcx()
}
@ -46,10 +41,6 @@ impl<'tcx> TypeRelation<'tcx> for Glb<'_, '_, 'tcx> {
self.a_is_expected
}
fn mark_ambiguous(&mut self) {
bug!("mark_ambiguous used outside of coherence");
}
fn relate_with_variance<T: Relate<'tcx>>(
&mut self,
variance: ty::Variance,

View file

@ -29,11 +29,6 @@ impl<'tcx> TypeRelation<'tcx> for Lub<'_, '_, 'tcx> {
"Lub"
}
fn intercrate(&self) -> bool {
assert!(!self.fields.infcx.intercrate);
false
}
fn tcx(&self) -> TyCtxt<'tcx> {
self.fields.tcx()
}
@ -46,10 +41,6 @@ impl<'tcx> TypeRelation<'tcx> for Lub<'_, '_, 'tcx> {
self.a_is_expected
}
fn mark_ambiguous(&mut self) {
bug!("mark_ambiguous used outside of coherence");
}
fn relate_with_variance<T: Relate<'tcx>>(
&mut self,
variance: ty::Variance,

View file

@ -443,10 +443,6 @@ where
self.infcx.tcx
}
fn intercrate(&self) -> bool {
self.infcx.intercrate
}
fn param_env(&self) -> ty::ParamEnv<'tcx> {
self.delegate.param_env()
}
@ -459,17 +455,6 @@ where
true
}
fn mark_ambiguous(&mut self) {
let cause = ObligationCause::dummy_with_span(self.delegate.span());
let param_env = self.delegate.param_env();
self.delegate.register_obligations(vec![Obligation::new(
self.tcx(),
cause,
param_env,
ty::Binder::dummy(ty::PredicateKind::Ambiguous),
)]);
}
#[instrument(skip(self, info), level = "trace", ret)]
fn relate_with_variance<T: Relate<'tcx>>(
&mut self,
@ -834,11 +819,6 @@ where
self.infcx.tcx
}
fn intercrate(&self) -> bool {
assert!(!self.infcx.intercrate);
false
}
fn param_env(&self) -> ty::ParamEnv<'tcx> {
self.delegate.param_env()
}
@ -851,10 +831,6 @@ where
true
}
fn mark_ambiguous(&mut self) {
bug!()
}
fn relate_with_variance<T: Relate<'tcx>>(
&mut self,
variance: ty::Variance,

View file

@ -137,10 +137,6 @@ impl<'tcx> TypeRelation<'tcx> for Match<'tcx> {
"Match"
}
fn intercrate(&self) -> bool {
false
}
fn tcx(&self) -> TyCtxt<'tcx> {
self.tcx
}
@ -151,10 +147,6 @@ impl<'tcx> TypeRelation<'tcx> for Match<'tcx> {
true
} // irrelevant
fn mark_ambiguous(&mut self) {
bug!()
}
#[instrument(level = "trace", skip(self))]
fn relate_with_variance<T: Relate<'tcx>>(
&mut self,

View file

@ -35,10 +35,6 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> {
"Sub"
}
fn intercrate(&self) -> bool {
self.fields.infcx.intercrate
}
fn tcx(&self) -> TyCtxt<'tcx> {
self.fields.infcx.tcx
}
@ -51,10 +47,6 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> {
self.a_is_expected
}
fn mark_ambiguous(&mut self) {
self.fields.mark_ambiguous()
}
fn with_cause<F, R>(&mut self, cause: Cause, f: F) -> R
where
F: FnOnce(&mut Self) -> R,