Remove intercrate and mark_ambiguous from Relation
This commit is contained in:
parent
48829ea74b
commit
a368316905
12 changed files with 22 additions and 133 deletions
|
@ -253,10 +253,6 @@ impl<'tcx> TypeRelation<'tcx> for SimpleEqRelation<'tcx> {
|
||||||
self.tcx
|
self.tcx
|
||||||
}
|
}
|
||||||
|
|
||||||
fn intercrate(&self) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn param_env(&self) -> ty::ParamEnv<'tcx> {
|
fn param_env(&self) -> ty::ParamEnv<'tcx> {
|
||||||
self.param_env
|
self.param_env
|
||||||
}
|
}
|
||||||
|
@ -269,10 +265,6 @@ impl<'tcx> TypeRelation<'tcx> for SimpleEqRelation<'tcx> {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mark_ambiguous(&mut self) {
|
|
||||||
bug!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn relate_with_variance<T: Relate<'tcx>>(
|
fn relate_with_variance<T: Relate<'tcx>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
_: ty::Variance,
|
_: ty::Variance,
|
||||||
|
|
|
@ -137,6 +137,18 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
Err(TypeError::Sorts(ty::relate::expected_found(relation, a, b)))
|
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),
|
_ => 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)
|
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> {
|
struct Generalizer<'cx, 'tcx> {
|
||||||
|
@ -581,10 +589,6 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
|
||||||
self.infcx.tcx
|
self.infcx.tcx
|
||||||
}
|
}
|
||||||
|
|
||||||
fn intercrate(&self) -> bool {
|
|
||||||
self.infcx.intercrate
|
|
||||||
}
|
|
||||||
|
|
||||||
fn param_env(&self) -> ty::ParamEnv<'tcx> {
|
fn param_env(&self) -> ty::ParamEnv<'tcx> {
|
||||||
self.param_env
|
self.param_env
|
||||||
}
|
}
|
||||||
|
@ -597,10 +601,6 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mark_ambiguous(&mut self) {
|
|
||||||
span_bug!(self.cause.span, "opaque types are handled in `tys`");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn binders<T>(
|
fn binders<T>(
|
||||||
&mut self,
|
&mut self,
|
||||||
a: ty::Binder<'tcx, T>,
|
a: ty::Binder<'tcx, T>,
|
||||||
|
|
|
@ -35,10 +35,6 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> {
|
||||||
self.fields.tcx()
|
self.fields.tcx()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn intercrate(&self) -> bool {
|
|
||||||
self.fields.infcx.intercrate
|
|
||||||
}
|
|
||||||
|
|
||||||
fn param_env(&self) -> ty::ParamEnv<'tcx> {
|
fn param_env(&self) -> ty::ParamEnv<'tcx> {
|
||||||
self.fields.param_env
|
self.fields.param_env
|
||||||
}
|
}
|
||||||
|
@ -47,10 +43,6 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> {
|
||||||
self.a_is_expected
|
self.a_is_expected
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mark_ambiguous(&mut self) {
|
|
||||||
self.fields.mark_ambiguous();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn relate_item_substs(
|
fn relate_item_substs(
|
||||||
&mut self,
|
&mut self,
|
||||||
_item_def_id: DefId,
|
_item_def_id: DefId,
|
||||||
|
|
|
@ -2697,11 +2697,6 @@ impl<'tcx> TypeRelation<'tcx> for SameTypeModuloInfer<'_, 'tcx> {
|
||||||
self.0.tcx
|
self.0.tcx
|
||||||
}
|
}
|
||||||
|
|
||||||
fn intercrate(&self) -> bool {
|
|
||||||
assert!(!self.0.intercrate);
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn param_env(&self) -> ty::ParamEnv<'tcx> {
|
fn param_env(&self) -> ty::ParamEnv<'tcx> {
|
||||||
// Unused, only for consts which we treat as always equal
|
// Unused, only for consts which we treat as always equal
|
||||||
ty::ParamEnv::empty()
|
ty::ParamEnv::empty()
|
||||||
|
@ -2715,10 +2710,6 @@ impl<'tcx> TypeRelation<'tcx> for SameTypeModuloInfer<'_, 'tcx> {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mark_ambiguous(&mut self) {
|
|
||||||
bug!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn relate_with_variance<T: relate::Relate<'tcx>>(
|
fn relate_with_variance<T: relate::Relate<'tcx>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
_variance: ty::Variance,
|
_variance: ty::Variance,
|
||||||
|
|
|
@ -29,11 +29,6 @@ impl<'tcx> TypeRelation<'tcx> for Glb<'_, '_, 'tcx> {
|
||||||
"Glb"
|
"Glb"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn intercrate(&self) -> bool {
|
|
||||||
assert!(!self.fields.infcx.intercrate);
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn tcx(&self) -> TyCtxt<'tcx> {
|
fn tcx(&self) -> TyCtxt<'tcx> {
|
||||||
self.fields.tcx()
|
self.fields.tcx()
|
||||||
}
|
}
|
||||||
|
@ -46,10 +41,6 @@ impl<'tcx> TypeRelation<'tcx> for Glb<'_, '_, 'tcx> {
|
||||||
self.a_is_expected
|
self.a_is_expected
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mark_ambiguous(&mut self) {
|
|
||||||
bug!("mark_ambiguous used outside of coherence");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn relate_with_variance<T: Relate<'tcx>>(
|
fn relate_with_variance<T: Relate<'tcx>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
variance: ty::Variance,
|
variance: ty::Variance,
|
||||||
|
|
|
@ -29,11 +29,6 @@ impl<'tcx> TypeRelation<'tcx> for Lub<'_, '_, 'tcx> {
|
||||||
"Lub"
|
"Lub"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn intercrate(&self) -> bool {
|
|
||||||
assert!(!self.fields.infcx.intercrate);
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn tcx(&self) -> TyCtxt<'tcx> {
|
fn tcx(&self) -> TyCtxt<'tcx> {
|
||||||
self.fields.tcx()
|
self.fields.tcx()
|
||||||
}
|
}
|
||||||
|
@ -46,10 +41,6 @@ impl<'tcx> TypeRelation<'tcx> for Lub<'_, '_, 'tcx> {
|
||||||
self.a_is_expected
|
self.a_is_expected
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mark_ambiguous(&mut self) {
|
|
||||||
bug!("mark_ambiguous used outside of coherence");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn relate_with_variance<T: Relate<'tcx>>(
|
fn relate_with_variance<T: Relate<'tcx>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
variance: ty::Variance,
|
variance: ty::Variance,
|
||||||
|
|
|
@ -443,10 +443,6 @@ where
|
||||||
self.infcx.tcx
|
self.infcx.tcx
|
||||||
}
|
}
|
||||||
|
|
||||||
fn intercrate(&self) -> bool {
|
|
||||||
self.infcx.intercrate
|
|
||||||
}
|
|
||||||
|
|
||||||
fn param_env(&self) -> ty::ParamEnv<'tcx> {
|
fn param_env(&self) -> ty::ParamEnv<'tcx> {
|
||||||
self.delegate.param_env()
|
self.delegate.param_env()
|
||||||
}
|
}
|
||||||
|
@ -459,17 +455,6 @@ where
|
||||||
true
|
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)]
|
#[instrument(skip(self, info), level = "trace", ret)]
|
||||||
fn relate_with_variance<T: Relate<'tcx>>(
|
fn relate_with_variance<T: Relate<'tcx>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -834,11 +819,6 @@ where
|
||||||
self.infcx.tcx
|
self.infcx.tcx
|
||||||
}
|
}
|
||||||
|
|
||||||
fn intercrate(&self) -> bool {
|
|
||||||
assert!(!self.infcx.intercrate);
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn param_env(&self) -> ty::ParamEnv<'tcx> {
|
fn param_env(&self) -> ty::ParamEnv<'tcx> {
|
||||||
self.delegate.param_env()
|
self.delegate.param_env()
|
||||||
}
|
}
|
||||||
|
@ -851,10 +831,6 @@ where
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mark_ambiguous(&mut self) {
|
|
||||||
bug!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn relate_with_variance<T: Relate<'tcx>>(
|
fn relate_with_variance<T: Relate<'tcx>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
variance: ty::Variance,
|
variance: ty::Variance,
|
||||||
|
|
|
@ -137,10 +137,6 @@ impl<'tcx> TypeRelation<'tcx> for Match<'tcx> {
|
||||||
"Match"
|
"Match"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn intercrate(&self) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn tcx(&self) -> TyCtxt<'tcx> {
|
fn tcx(&self) -> TyCtxt<'tcx> {
|
||||||
self.tcx
|
self.tcx
|
||||||
}
|
}
|
||||||
|
@ -151,10 +147,6 @@ impl<'tcx> TypeRelation<'tcx> for Match<'tcx> {
|
||||||
true
|
true
|
||||||
} // irrelevant
|
} // irrelevant
|
||||||
|
|
||||||
fn mark_ambiguous(&mut self) {
|
|
||||||
bug!()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[instrument(level = "trace", skip(self))]
|
#[instrument(level = "trace", skip(self))]
|
||||||
fn relate_with_variance<T: Relate<'tcx>>(
|
fn relate_with_variance<T: Relate<'tcx>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|
|
@ -35,10 +35,6 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> {
|
||||||
"Sub"
|
"Sub"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn intercrate(&self) -> bool {
|
|
||||||
self.fields.infcx.intercrate
|
|
||||||
}
|
|
||||||
|
|
||||||
fn tcx(&self) -> TyCtxt<'tcx> {
|
fn tcx(&self) -> TyCtxt<'tcx> {
|
||||||
self.fields.infcx.tcx
|
self.fields.infcx.tcx
|
||||||
}
|
}
|
||||||
|
@ -51,10 +47,6 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> {
|
||||||
self.a_is_expected
|
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
|
fn with_cause<F, R>(&mut self, cause: Cause, f: F) -> R
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut Self) -> R,
|
F: FnOnce(&mut Self) -> R,
|
||||||
|
|
|
@ -37,10 +37,6 @@ impl<'tcx> TypeRelation<'tcx> for Match<'tcx> {
|
||||||
self.tcx
|
self.tcx
|
||||||
}
|
}
|
||||||
|
|
||||||
fn intercrate(&self) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn param_env(&self) -> ty::ParamEnv<'tcx> {
|
fn param_env(&self) -> ty::ParamEnv<'tcx> {
|
||||||
self.param_env
|
self.param_env
|
||||||
}
|
}
|
||||||
|
@ -48,10 +44,6 @@ impl<'tcx> TypeRelation<'tcx> for Match<'tcx> {
|
||||||
true
|
true
|
||||||
} // irrelevant
|
} // irrelevant
|
||||||
|
|
||||||
fn mark_ambiguous(&mut self) {
|
|
||||||
bug!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn relate_with_variance<T: Relate<'tcx>>(
|
fn relate_with_variance<T: Relate<'tcx>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
_: ty::Variance,
|
_: ty::Variance,
|
||||||
|
|
|
@ -22,8 +22,6 @@ pub enum Cause {
|
||||||
pub trait TypeRelation<'tcx>: Sized {
|
pub trait TypeRelation<'tcx>: Sized {
|
||||||
fn tcx(&self) -> TyCtxt<'tcx>;
|
fn tcx(&self) -> TyCtxt<'tcx>;
|
||||||
|
|
||||||
fn intercrate(&self) -> bool;
|
|
||||||
|
|
||||||
fn param_env(&self) -> ty::ParamEnv<'tcx>;
|
fn param_env(&self) -> ty::ParamEnv<'tcx>;
|
||||||
|
|
||||||
/// Returns a static string we can use for printouts.
|
/// Returns a static string we can use for printouts.
|
||||||
|
@ -33,9 +31,6 @@ pub trait TypeRelation<'tcx>: Sized {
|
||||||
/// relation. Just affects error messages.
|
/// relation. Just affects error messages.
|
||||||
fn a_is_expected(&self) -> bool;
|
fn a_is_expected(&self) -> bool;
|
||||||
|
|
||||||
/// Used during coherence. If called, must emit an always-ambiguous obligation.
|
|
||||||
fn mark_ambiguous(&mut self);
|
|
||||||
|
|
||||||
fn with_cause<F, R>(&mut self, _cause: Cause, f: F) -> R
|
fn with_cause<F, R>(&mut self, _cause: Cause, f: F) -> R
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut Self) -> R,
|
F: FnOnce(&mut Self) -> R,
|
||||||
|
@ -559,23 +554,16 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>(
|
||||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: a_substs, .. }),
|
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: a_substs, .. }),
|
||||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: b_substs, .. }),
|
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: b_substs, .. }),
|
||||||
) if a_def_id == b_def_id => {
|
) if a_def_id == b_def_id => {
|
||||||
if relation.intercrate() {
|
let opt_variances = tcx.variances_of(a_def_id);
|
||||||
// During coherence, opaque types should be treated as equal to each other, even if their generic params
|
let substs = relate_substs_with_variances(
|
||||||
// differ, as they could resolve to the same hidden type, even for different generic params.
|
relation,
|
||||||
relation.mark_ambiguous();
|
a_def_id,
|
||||||
Ok(a)
|
opt_variances,
|
||||||
} else {
|
a_substs,
|
||||||
let opt_variances = tcx.variances_of(a_def_id);
|
b_substs,
|
||||||
let substs = relate_substs_with_variances(
|
false, // do not fetch `type_of(a_def_id)`, as it will cause a cycle
|
||||||
relation,
|
)?;
|
||||||
a_def_id,
|
Ok(tcx.mk_opaque(a_def_id, substs))
|
||||||
opt_variances,
|
|
||||||
a_substs,
|
|
||||||
b_substs,
|
|
||||||
false, // do not fetch `type_of(a_def_id)`, as it will cause a cycle
|
|
||||||
)?;
|
|
||||||
Ok(tcx.mk_opaque(a_def_id, substs))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => Err(TypeError::Sorts(expected_found(relation, a, b))),
|
_ => Err(TypeError::Sorts(expected_found(relation, a, b))),
|
||||||
|
|
|
@ -21,10 +21,6 @@ impl<'a, 'tcx> TypeRelation<'tcx> for CollectAllMismatches<'a, 'tcx> {
|
||||||
self.infcx.tcx
|
self.infcx.tcx
|
||||||
}
|
}
|
||||||
|
|
||||||
fn intercrate(&self) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn param_env(&self) -> ty::ParamEnv<'tcx> {
|
fn param_env(&self) -> ty::ParamEnv<'tcx> {
|
||||||
self.param_env
|
self.param_env
|
||||||
}
|
}
|
||||||
|
@ -33,10 +29,6 @@ impl<'a, 'tcx> TypeRelation<'tcx> for CollectAllMismatches<'a, 'tcx> {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mark_ambiguous(&mut self) {
|
|
||||||
bug!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn relate_with_variance<T: Relate<'tcx>>(
|
fn relate_with_variance<T: Relate<'tcx>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
_: ty::Variance,
|
_: ty::Variance,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue