Skip to content

Commit

Permalink
Rollup merge of rust-lang#73705 - lcnr:skip_binder, r=nikomatsakis
Browse files Browse the repository at this point in the history
stop taking references in Relate

Adds a `Copy` bound to `Relate` and changes the type signatures to `T` from `&T`. While the `Copy` bound is not strictly necessary (i.e. the `Clone` bound of `TypeRelation` would be good enough), we don't need non `Copy` types and it simplifies the implementation.

Removes the afaict unused impls for `Vec<ty::PolyExistentialProjection<'tcx>>`, `Rc<T>` and `Box<T>`. If they end up being relevant again the bound of `Relate` can be reduced to `T: Clone`.

This also changes signature of `Binder::skip_binder` to `fn skip_binder(self) -> T`.

`TypeError::ProjectionBoundsLength` was never used and is also removed in this PR.

r? @nikomatsakis maybe 🤔 feel free to reassign
  • Loading branch information
Manishearth authored Jul 1, 2020
2 parents 4be8326 + 69e4990 commit 05d9a21
Show file tree
Hide file tree
Showing 47 changed files with 242 additions and 303 deletions.
18 changes: 9 additions & 9 deletions src/librustc_infer/infer/at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
where
T: ToTrace<'tcx>,
{
self.trace_exp(a_is_expected, a, b).sub(&a, &b)
self.trace_exp(a_is_expected, a, b).sub(a, b)
}

/// Makes `actual <: expected`. For example, if type-checking a
Expand All @@ -109,15 +109,15 @@ impl<'a, 'tcx> At<'a, 'tcx> {
where
T: ToTrace<'tcx>,
{
self.trace_exp(a_is_expected, a, b).eq(&a, &b)
self.trace_exp(a_is_expected, a, b).eq(a, b)
}

/// Makes `expected <: actual`.
pub fn eq<T>(self, expected: T, actual: T) -> InferResult<'tcx, ()>
where
T: ToTrace<'tcx>,
{
self.trace(expected, actual).eq(&expected, &actual)
self.trace(expected, actual).eq(expected, actual)
}

pub fn relate<T>(self, expected: T, variance: ty::Variance, actual: T) -> InferResult<'tcx, ()>
Expand Down Expand Up @@ -147,7 +147,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
where
T: ToTrace<'tcx>,
{
self.trace(expected, actual).lub(&expected, &actual)
self.trace(expected, actual).lub(expected, actual)
}

/// Computes the greatest-lower-bound, or mutual subtype, of two
Expand All @@ -157,7 +157,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
where
T: ToTrace<'tcx>,
{
self.trace(expected, actual).glb(&expected, &actual)
self.trace(expected, actual).glb(expected, actual)
}

/// Sets the "trace" values that will be used for
Expand Down Expand Up @@ -186,7 +186,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
impl<'a, 'tcx> Trace<'a, 'tcx> {
/// Makes `a <: b` where `a` may or may not be expected (if
/// `a_is_expected` is true, then `a` is expected).
pub fn sub<T>(self, a: &T, b: &T) -> InferResult<'tcx, ()>
pub fn sub<T>(self, a: T, b: T) -> InferResult<'tcx, ()>
where
T: Relate<'tcx>,
{
Expand All @@ -203,7 +203,7 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {

/// Makes `a == b`; the expectation is set by the call to
/// `trace()`.
pub fn eq<T>(self, a: &T, b: &T) -> InferResult<'tcx, ()>
pub fn eq<T>(self, a: T, b: T) -> InferResult<'tcx, ()>
where
T: Relate<'tcx>,
{
Expand All @@ -218,7 +218,7 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
})
}

pub fn lub<T>(self, a: &T, b: &T) -> InferResult<'tcx, T>
pub fn lub<T>(self, a: T, b: T) -> InferResult<'tcx, T>
where
T: Relate<'tcx>,
{
Expand All @@ -233,7 +233,7 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
})
}

pub fn glb<T>(self, a: &T, b: &T) -> InferResult<'tcx, T>
pub fn glb<T>(self, a: T, b: T) -> InferResult<'tcx, T>
where
T: Relate<'tcx>,
{
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_infer/infer/canonical/query_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
},
ty::Variance::Invariant,
)
.relate(&v1, &v2)?;
.relate(v1, v2)?;
}

(GenericArgKind::Const(v1), GenericArgKind::Const(v2)) => {
Expand All @@ -285,7 +285,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
},
ty::Variance::Invariant,
)
.relate(&v1, &v2)?;
.relate(v1, v2)?;
}

_ => {
Expand All @@ -302,7 +302,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
// Screen out `'a: 'a` cases -- we skip the binder here but
// only compare the inner values to one another, so they are still at
// consistent binding levels.
let &ty::OutlivesPredicate(k1, r2) = r_c.skip_binder();
let ty::OutlivesPredicate(k1, r2) = r_c.skip_binder();
if k1 != r2.into() { Some(r_c) } else { None }
}),
);
Expand Down Expand Up @@ -526,7 +526,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
) -> impl Iterator<Item = PredicateObligation<'tcx>> + 'a + Captures<'tcx> {
unsubstituted_region_constraints.iter().map(move |constraint| {
let constraint = substitute_value(self.tcx, result_subst, constraint);
let &ty::OutlivesPredicate(k1, r2) = constraint.skip_binder(); // restored below
let ty::OutlivesPredicate(k1, r2) = constraint.skip_binder(); // restored below

Obligation::new(
cause.clone(),
Expand Down
20 changes: 10 additions & 10 deletions src/librustc_infer/infer/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,10 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
// to associate causes/spans with each of the relations in
// the stack to get this right.
match dir {
EqTo => self.equate(a_is_expected).relate(&a_ty, &b_ty),
SubtypeOf => self.sub(a_is_expected).relate(&a_ty, &b_ty),
EqTo => self.equate(a_is_expected).relate(a_ty, b_ty),
SubtypeOf => self.sub(a_is_expected).relate(a_ty, b_ty),
SupertypeOf => {
self.sub(a_is_expected).relate_with_variance(ty::Contravariant, &a_ty, &b_ty)
self.sub(a_is_expected).relate_with_variance(ty::Contravariant, a_ty, b_ty)
}
}?;

Expand Down Expand Up @@ -379,7 +379,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
param_env: self.param_env,
};

let ty = match generalize.relate(&ty, &ty) {
let ty = match generalize.relate(ty, ty) {
Ok(ty) => ty,
Err(e) => {
debug!("generalize: failure {:?}", e);
Expand Down Expand Up @@ -490,8 +490,8 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {

fn binders<T>(
&mut self,
a: &ty::Binder<T>,
b: &ty::Binder<T>,
a: ty::Binder<T>,
b: ty::Binder<T>,
) -> RelateResult<'tcx, ty::Binder<T>>
where
T: Relate<'tcx>,
Expand Down Expand Up @@ -519,8 +519,8 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
fn relate_with_variance<T: Relate<'tcx>>(
&mut self,
variance: ty::Variance,
a: &T,
b: &T,
a: T,
b: T,
) -> RelateResult<'tcx, T> {
let old_ambient_variance = self.ambient_variance;
self.ambient_variance = self.ambient_variance.xform(variance);
Expand Down Expand Up @@ -552,7 +552,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
match probe {
TypeVariableValue::Known { value: u } => {
debug!("generalize: known value {:?}", u);
self.relate(&u, &u)
self.relate(u, u)
}
TypeVariableValue::Unknown { universe } => {
match self.ambient_variance {
Expand Down Expand Up @@ -655,7 +655,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
let variable_table = &mut inner.const_unification_table();
let var_value = variable_table.probe_value(vid);
match var_value.val {
ConstVariableValue::Known { value: u } => self.relate(&u, &u),
ConstVariableValue::Known { value: u } => self.relate(u, u),
ConstVariableValue::Unknown { universe } => {
if self.for_universe.can_name(universe) {
Ok(c)
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_infer/infer/equate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ impl TypeRelation<'tcx> for Equate<'combine, 'infcx, 'tcx> {
fn relate_with_variance<T: Relate<'tcx>>(
&mut self,
_: ty::Variance,
a: &T,
b: &T,
a: T,
b: T,
) -> RelateResult<'tcx, T> {
self.relate(a, b)
}
Expand Down Expand Up @@ -124,8 +124,8 @@ impl TypeRelation<'tcx> for Equate<'combine, 'infcx, 'tcx> {

fn binders<T>(
&mut self,
a: &ty::Binder<T>,
b: &ty::Binder<T>,
a: ty::Binder<T>,
b: ty::Binder<T>,
) -> RelateResult<'tcx, ty::Binder<T>>
where
T: Relate<'tcx>,
Expand All @@ -136,7 +136,7 @@ impl TypeRelation<'tcx> for Equate<'combine, 'infcx, 'tcx> {
} else {
// Fast path for the common case.
self.relate(a.skip_binder(), b.skip_binder())?;
Ok(a.clone())
Ok(a)
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_infer/infer/glb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ impl TypeRelation<'tcx> for Glb<'combine, 'infcx, 'tcx> {
fn relate_with_variance<T: Relate<'tcx>>(
&mut self,
variance: ty::Variance,
a: &T,
b: &T,
a: T,
b: T,
) -> RelateResult<'tcx, T> {
match variance {
ty::Invariant => self.fields.equate(self.a_is_expected).relate(a, b),
Expand Down Expand Up @@ -85,8 +85,8 @@ impl TypeRelation<'tcx> for Glb<'combine, 'infcx, 'tcx> {

fn binders<T>(
&mut self,
a: &ty::Binder<T>,
b: &ty::Binder<T>,
a: ty::Binder<T>,
b: ty::Binder<T>,
) -> RelateResult<'tcx, ty::Binder<T>>
where
T: Relate<'tcx>,
Expand All @@ -112,8 +112,8 @@ impl<'combine, 'infcx, 'tcx> LatticeDir<'infcx, 'tcx> for Glb<'combine, 'infcx,

fn relate_bound(&mut self, v: Ty<'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, ()> {
let mut sub = self.fields.sub(self.a_is_expected);
sub.relate(&v, &a)?;
sub.relate(&v, &b)?;
sub.relate(v, a)?;
sub.relate(v, b)?;
Ok(())
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_infer/infer/higher_ranked/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use rustc_middle::ty::{self, Binder, TypeFoldable};
impl<'a, 'tcx> CombineFields<'a, 'tcx> {
pub fn higher_ranked_sub<T>(
&mut self,
a: &Binder<T>,
b: &Binder<T>,
a: Binder<T>,
b: Binder<T>,
a_is_expected: bool,
) -> RelateResult<'tcx, Binder<T>>
where
Expand All @@ -33,20 +33,20 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
self.infcx.commit_if_ok(|_| {
// First, we instantiate each bound region in the supertype with a
// fresh placeholder region.
let (b_prime, _) = self.infcx.replace_bound_vars_with_placeholders(b);
let (b_prime, _) = self.infcx.replace_bound_vars_with_placeholders(&b);

// Next, we instantiate each bound region in the subtype
// with a fresh region variable. These region variables --
// but no other pre-existing region variables -- can name
// the placeholders.
let (a_prime, _) =
self.infcx.replace_bound_vars_with_fresh_vars(span, HigherRankedType, a);
self.infcx.replace_bound_vars_with_fresh_vars(span, HigherRankedType, &a);

debug!("a_prime={:?}", a_prime);
debug!("b_prime={:?}", b_prime);

// Compare types now that bound regions have been replaced.
let result = self.sub(a_is_expected).relate(&a_prime, &b_prime)?;
let result = self.sub(a_is_expected).relate(a_prime, b_prime)?;

debug!("higher_ranked_sub: OK result={:?}", result);

Expand Down
14 changes: 7 additions & 7 deletions src/librustc_infer/infer/lub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ impl TypeRelation<'tcx> for Lub<'combine, 'infcx, 'tcx> {
fn relate_with_variance<T: Relate<'tcx>>(
&mut self,
variance: ty::Variance,
a: &T,
b: &T,
a: T,
b: T,
) -> RelateResult<'tcx, T> {
match variance {
ty::Invariant => self.fields.equate(self.a_is_expected).relate(a, b),
Expand Down Expand Up @@ -85,8 +85,8 @@ impl TypeRelation<'tcx> for Lub<'combine, 'infcx, 'tcx> {

fn binders<T>(
&mut self,
a: &ty::Binder<T>,
b: &ty::Binder<T>,
a: ty::Binder<T>,
b: ty::Binder<T>,
) -> RelateResult<'tcx, ty::Binder<T>>
where
T: Relate<'tcx>,
Expand All @@ -97,7 +97,7 @@ impl TypeRelation<'tcx> for Lub<'combine, 'infcx, 'tcx> {
// very challenging, switch to invariance. This is obviously
// overly conservative but works ok in practice.
self.relate_with_variance(ty::Variance::Invariant, a, b)?;
Ok(a.clone())
Ok(a)
}
}

Expand All @@ -118,8 +118,8 @@ impl<'combine, 'infcx, 'tcx> LatticeDir<'infcx, 'tcx> for Lub<'combine, 'infcx,

fn relate_bound(&mut self, v: Ty<'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, ()> {
let mut sub = self.fields.sub(self.a_is_expected);
sub.relate(&a, &v)?;
sub.relate(&b, &v)?;
sub.relate(a, v)?;
sub.relate(b, v)?;
Ok(())
}
}
Loading

0 comments on commit 05d9a21

Please sign in to comment.