Skip to content

Commit 39cf207

Browse files
authored
Rollup merge of rust-lang#73705 - lcnr:skip_binder, r=nikomatsakis
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
2 parents 63621db + acd4818 commit 39cf207

File tree

46 files changed

+237
-298
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+237
-298
lines changed

src/librustc_infer/infer/at.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
8282
where
8383
T: ToTrace<'tcx>,
8484
{
85-
self.trace_exp(a_is_expected, a, b).sub(&a, &b)
85+
self.trace_exp(a_is_expected, a, b).sub(a, b)
8686
}
8787

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

115115
/// Makes `expected <: actual`.
116116
pub fn eq<T>(self, expected: T, actual: T) -> InferResult<'tcx, ()>
117117
where
118118
T: ToTrace<'tcx>,
119119
{
120-
self.trace(expected, actual).eq(&expected, &actual)
120+
self.trace(expected, actual).eq(expected, actual)
121121
}
122122

123123
pub fn relate<T>(self, expected: T, variance: ty::Variance, actual: T) -> InferResult<'tcx, ()>
@@ -147,7 +147,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
147147
where
148148
T: ToTrace<'tcx>,
149149
{
150-
self.trace(expected, actual).lub(&expected, &actual)
150+
self.trace(expected, actual).lub(expected, actual)
151151
}
152152

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

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

204204
/// Makes `a == b`; the expectation is set by the call to
205205
/// `trace()`.
206-
pub fn eq<T>(self, a: &T, b: &T) -> InferResult<'tcx, ()>
206+
pub fn eq<T>(self, a: T, b: T) -> InferResult<'tcx, ()>
207207
where
208208
T: Relate<'tcx>,
209209
{
@@ -218,7 +218,7 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
218218
})
219219
}
220220

221-
pub fn lub<T>(self, a: &T, b: &T) -> InferResult<'tcx, T>
221+
pub fn lub<T>(self, a: T, b: T) -> InferResult<'tcx, T>
222222
where
223223
T: Relate<'tcx>,
224224
{
@@ -233,7 +233,7 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
233233
})
234234
}
235235

236-
pub fn glb<T>(self, a: &T, b: &T) -> InferResult<'tcx, T>
236+
pub fn glb<T>(self, a: T, b: T) -> InferResult<'tcx, T>
237237
where
238238
T: Relate<'tcx>,
239239
{

src/librustc_infer/infer/canonical/query_response.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
271271
},
272272
ty::Variance::Invariant,
273273
)
274-
.relate(&v1, &v2)?;
274+
.relate(v1, v2)?;
275275
}
276276

277277
(GenericArgKind::Const(v1), GenericArgKind::Const(v2)) => {
@@ -285,7 +285,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
285285
},
286286
ty::Variance::Invariant,
287287
)
288-
.relate(&v1, &v2)?;
288+
.relate(v1, v2)?;
289289
}
290290

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

531531
Obligation::new(
532532
cause.clone(),

src/librustc_infer/infer/combine.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,10 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
318318
// to associate causes/spans with each of the relations in
319319
// the stack to get this right.
320320
match dir {
321-
EqTo => self.equate(a_is_expected).relate(&a_ty, &b_ty),
322-
SubtypeOf => self.sub(a_is_expected).relate(&a_ty, &b_ty),
321+
EqTo => self.equate(a_is_expected).relate(a_ty, b_ty),
322+
SubtypeOf => self.sub(a_is_expected).relate(a_ty, b_ty),
323323
SupertypeOf => {
324-
self.sub(a_is_expected).relate_with_variance(ty::Contravariant, &a_ty, &b_ty)
324+
self.sub(a_is_expected).relate_with_variance(ty::Contravariant, a_ty, b_ty)
325325
}
326326
}?;
327327

@@ -379,7 +379,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
379379
param_env: self.param_env,
380380
};
381381

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

491491
fn binders<T>(
492492
&mut self,
493-
a: &ty::Binder<T>,
494-
b: &ty::Binder<T>,
493+
a: ty::Binder<T>,
494+
b: ty::Binder<T>,
495495
) -> RelateResult<'tcx, ty::Binder<T>>
496496
where
497497
T: Relate<'tcx>,
@@ -519,8 +519,8 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
519519
fn relate_with_variance<T: Relate<'tcx>>(
520520
&mut self,
521521
variance: ty::Variance,
522-
a: &T,
523-
b: &T,
522+
a: T,
523+
b: T,
524524
) -> RelateResult<'tcx, T> {
525525
let old_ambient_variance = self.ambient_variance;
526526
self.ambient_variance = self.ambient_variance.xform(variance);
@@ -552,7 +552,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
552552
match probe {
553553
TypeVariableValue::Known { value: u } => {
554554
debug!("generalize: known value {:?}", u);
555-
self.relate(&u, &u)
555+
self.relate(u, u)
556556
}
557557
TypeVariableValue::Unknown { universe } => {
558558
match self.ambient_variance {
@@ -655,7 +655,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
655655
let variable_table = &mut inner.const_unification_table();
656656
let var_value = variable_table.probe_value(vid);
657657
match var_value.val {
658-
ConstVariableValue::Known { value: u } => self.relate(&u, &u),
658+
ConstVariableValue::Known { value: u } => self.relate(u, u),
659659
ConstVariableValue::Unknown { universe } => {
660660
if self.for_universe.can_name(universe) {
661661
Ok(c)

src/librustc_infer/infer/equate.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ impl TypeRelation<'tcx> for Equate<'combine, 'infcx, 'tcx> {
5959
fn relate_with_variance<T: Relate<'tcx>>(
6060
&mut self,
6161
_: ty::Variance,
62-
a: &T,
63-
b: &T,
62+
a: T,
63+
b: T,
6464
) -> RelateResult<'tcx, T> {
6565
self.relate(a, b)
6666
}
@@ -124,8 +124,8 @@ impl TypeRelation<'tcx> for Equate<'combine, 'infcx, 'tcx> {
124124

125125
fn binders<T>(
126126
&mut self,
127-
a: &ty::Binder<T>,
128-
b: &ty::Binder<T>,
127+
a: ty::Binder<T>,
128+
b: ty::Binder<T>,
129129
) -> RelateResult<'tcx, ty::Binder<T>>
130130
where
131131
T: Relate<'tcx>,
@@ -136,7 +136,7 @@ impl TypeRelation<'tcx> for Equate<'combine, 'infcx, 'tcx> {
136136
} else {
137137
// Fast path for the common case.
138138
self.relate(a.skip_binder(), b.skip_binder())?;
139-
Ok(a.clone())
139+
Ok(a)
140140
}
141141
}
142142
}

src/librustc_infer/infer/glb.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ impl TypeRelation<'tcx> for Glb<'combine, 'infcx, 'tcx> {
4343
fn relate_with_variance<T: Relate<'tcx>>(
4444
&mut self,
4545
variance: ty::Variance,
46-
a: &T,
47-
b: &T,
46+
a: T,
47+
b: T,
4848
) -> RelateResult<'tcx, T> {
4949
match variance {
5050
ty::Invariant => self.fields.equate(self.a_is_expected).relate(a, b),
@@ -85,8 +85,8 @@ impl TypeRelation<'tcx> for Glb<'combine, 'infcx, 'tcx> {
8585

8686
fn binders<T>(
8787
&mut self,
88-
a: &ty::Binder<T>,
89-
b: &ty::Binder<T>,
88+
a: ty::Binder<T>,
89+
b: ty::Binder<T>,
9090
) -> RelateResult<'tcx, ty::Binder<T>>
9191
where
9292
T: Relate<'tcx>,
@@ -112,8 +112,8 @@ impl<'combine, 'infcx, 'tcx> LatticeDir<'infcx, 'tcx> for Glb<'combine, 'infcx,
112112

113113
fn relate_bound(&mut self, v: Ty<'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, ()> {
114114
let mut sub = self.fields.sub(self.a_is_expected);
115-
sub.relate(&v, &a)?;
116-
sub.relate(&v, &b)?;
115+
sub.relate(v, a)?;
116+
sub.relate(v, b)?;
117117
Ok(())
118118
}
119119
}

src/librustc_infer/infer/higher_ranked/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use rustc_middle::ty::{self, Binder, TypeFoldable};
1111
impl<'a, 'tcx> CombineFields<'a, 'tcx> {
1212
pub fn higher_ranked_sub<T>(
1313
&mut self,
14-
a: &Binder<T>,
15-
b: &Binder<T>,
14+
a: Binder<T>,
15+
b: Binder<T>,
1616
a_is_expected: bool,
1717
) -> RelateResult<'tcx, Binder<T>>
1818
where
@@ -33,20 +33,20 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
3333
self.infcx.commit_if_ok(|_| {
3434
// First, we instantiate each bound region in the supertype with a
3535
// fresh placeholder region.
36-
let (b_prime, _) = self.infcx.replace_bound_vars_with_placeholders(b);
36+
let (b_prime, _) = self.infcx.replace_bound_vars_with_placeholders(&b);
3737

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

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

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

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

src/librustc_infer/infer/lub.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ impl TypeRelation<'tcx> for Lub<'combine, 'infcx, 'tcx> {
4343
fn relate_with_variance<T: Relate<'tcx>>(
4444
&mut self,
4545
variance: ty::Variance,
46-
a: &T,
47-
b: &T,
46+
a: T,
47+
b: T,
4848
) -> RelateResult<'tcx, T> {
4949
match variance {
5050
ty::Invariant => self.fields.equate(self.a_is_expected).relate(a, b),
@@ -85,8 +85,8 @@ impl TypeRelation<'tcx> for Lub<'combine, 'infcx, 'tcx> {
8585

8686
fn binders<T>(
8787
&mut self,
88-
a: &ty::Binder<T>,
89-
b: &ty::Binder<T>,
88+
a: ty::Binder<T>,
89+
b: ty::Binder<T>,
9090
) -> RelateResult<'tcx, ty::Binder<T>>
9191
where
9292
T: Relate<'tcx>,
@@ -97,7 +97,7 @@ impl TypeRelation<'tcx> for Lub<'combine, 'infcx, 'tcx> {
9797
// very challenging, switch to invariance. This is obviously
9898
// overly conservative but works ok in practice.
9999
self.relate_with_variance(ty::Variance::Invariant, a, b)?;
100-
Ok(a.clone())
100+
Ok(a)
101101
}
102102
}
103103

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

119119
fn relate_bound(&mut self, v: Ty<'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, ()> {
120120
let mut sub = self.fields.sub(self.a_is_expected);
121-
sub.relate(&a, &v)?;
122-
sub.relate(&b, &v)?;
121+
sub.relate(a, v)?;
122+
sub.relate(b, v)?;
123123
Ok(())
124124
}
125125
}

0 commit comments

Comments
 (0)