]> git.lizzy.rs Git - rust.git/commitdiff
stop taking references in Relate
authorBastian Kauschke <bastian_kauschke@hotmail.de>
Wed, 24 Jun 2020 21:14:18 +0000 (23:14 +0200)
committerBastian Kauschke <bastian_kauschke@hotmail.de>
Tue, 30 Jun 2020 07:13:56 +0000 (09:13 +0200)
15 files changed:
src/librustc_infer/infer/at.rs
src/librustc_infer/infer/canonical/query_response.rs
src/librustc_infer/infer/combine.rs
src/librustc_infer/infer/equate.rs
src/librustc_infer/infer/glb.rs
src/librustc_infer/infer/higher_ranked/mod.rs
src/librustc_infer/infer/lub.rs
src/librustc_infer/infer/nll_relate/mod.rs
src/librustc_infer/infer/sub.rs
src/librustc_middle/ty/_match.rs
src/librustc_middle/ty/relate.rs
src/librustc_mir/borrow_check/type_check/relate_tys.rs
src/librustc_trait_selection/traits/select/mod.rs
src/librustc_typeck/check/coercion.rs
src/librustc_typeck/check/dropck.rs

index d44b8f554143c3f70fa7d7f842fcd2d32947f636..a7749d33b7c1389edcd874c10151ac8403d17da7 100644 (file)
@@ -82,7 +82,7 @@ pub fn sub_exp<T>(self, a_is_expected: bool, a: T, b: T) -> InferResult<'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
@@ -109,7 +109,7 @@ pub fn eq_exp<T>(self, a_is_expected: bool, a: T, b: T) -> InferResult<'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`.
@@ -117,7 +117,7 @@ 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, ()>
@@ -147,7 +147,7 @@ pub fn lub<T>(self, expected: T, actual: T) -> InferResult<'tcx, T>
     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
@@ -157,7 +157,7 @@ pub fn glb<T>(self, expected: T, actual: T) -> InferResult<'tcx, T>
     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
@@ -186,7 +186,7 @@ pub fn trace_exp<T>(self, a_is_expected: bool, a: T, b: T) -> Trace<'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>,
     {
@@ -203,7 +203,7 @@ pub fn sub<T>(self, a: &T, b: &T) -> InferResult<'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>,
     {
@@ -218,7 +218,7 @@ pub fn eq<T>(self, a: &T, b: &T) -> InferResult<'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>,
     {
@@ -233,7 +233,7 @@ pub fn lub<T>(self, a: &T, b: &T) -> InferResult<'tcx, T>
         })
     }
 
-    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>,
     {
index 8af526e3ad31b31171753d27693d72764ac624d1..a6d7b403fe7a97bfb1ac7923f1166ee6b85f7ef0 100644 (file)
@@ -271,7 +271,7 @@ pub fn instantiate_nll_query_response_and_region_obligations<R>(
                         },
                         ty::Variance::Invariant,
                     )
-                    .relate(&v1, &v2)?;
+                    .relate(v1, v2)?;
                 }
 
                 (GenericArgKind::Const(v1), GenericArgKind::Const(v2)) => {
@@ -285,7 +285,7 @@ pub fn instantiate_nll_query_response_and_region_obligations<R>(
                         },
                         ty::Variance::Invariant,
                     )
-                    .relate(&v1, &v2)?;
+                    .relate(v1, v2)?;
                 }
 
                 _ => {
index 4ef4ed47cb11a8b20543d907e80c2c5e3275b0e7..fa54d815055eccda10869fd75983ae6a75470d19 100644 (file)
@@ -318,10 +318,10 @@ pub fn instantiate(
         // 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)
             }
         }?;
 
@@ -379,7 +379,7 @@ fn generalize(
             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);
@@ -490,13 +490,13 @@ fn a_is_expected(&self) -> bool {
 
     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>,
     {
-        Ok(ty::Binder::bind(self.relate(a.skip_binder(), b.skip_binder())?))
+        Ok(ty::Binder::bind(self.relate(*a.skip_binder(), *b.skip_binder())?))
     }
 
     fn relate_item_substs(
@@ -519,8 +519,8 @@ fn relate_item_substs(
     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);
@@ -552,7 +552,7 @@ fn tys(&mut self, t: Ty<'tcx>, t2: Ty<'tcx>) -> RelateResult<'tcx, Ty<'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 {
@@ -655,7 +655,7 @@ fn consts(
                 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)
index e3cafb82719dd4e714dae122c8976b175b03c40f..6826956b38bd8c446bd5bb3596027270820c08fe 100644 (file)
@@ -59,8 +59,8 @@ fn relate_item_substs(
     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)
     }
@@ -124,8 +124,8 @@ fn consts(
 
     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>,
@@ -135,8 +135,8 @@ fn binders<T>(
             self.fields.higher_ranked_sub(b, a, self.a_is_expected)
         } else {
             // Fast path for the common case.
-            self.relate(a.skip_binder(), b.skip_binder())?;
-            Ok(a.clone())
+            self.relate(*a.skip_binder(), *b.skip_binder())?;
+            Ok(a)
         }
     }
 }
index ec219a95b94414aa1ecf401aaacfb787ef08d109..8a0ab52f383065cd72205619ec3232cf0a6ce8a2 100644 (file)
@@ -43,8 +43,8 @@ fn a_is_expected(&self) -> bool {
     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),
@@ -85,8 +85,8 @@ fn consts(
 
     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>,
@@ -112,8 +112,8 @@ fn cause(&self) -> &ObligationCause<'tcx> {
 
     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(())
     }
 }
index b6251e34008a36fe922e63b9cc4dd87cd9280857..ea19dff7db125098ba4b1ad85f765af989cf64aa 100644 (file)
@@ -11,8 +11,8 @@
 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
@@ -33,20 +33,20 @@ pub fn higher_ranked_sub<T>(
         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);
 
index a0453db2cb4994d7dc7182bb4a15f830c5284b7b..3e2ea3d0f8fbf19856222dcaefbed6e22acfa477 100644 (file)
@@ -43,8 +43,8 @@ fn a_is_expected(&self) -> bool {
     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),
@@ -85,8 +85,8 @@ fn consts(
 
     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>,
@@ -97,7 +97,7 @@ fn binders<T>(
         // 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)
     }
 }
 
@@ -118,8 +118,8 @@ fn cause(&self) -> &ObligationCause<'tcx> {
 
     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(())
     }
 }
index 2350c28dfaaff6afc91da2b4c49c2d413e2bcaee..59e08b85f26e8370bca434c57c0d88f22feda1ff 100644 (file)
@@ -159,6 +159,7 @@ fn ambient_contravariance(&self) -> bool {
         }
     }
 
+    // FIXME: consider taking `ty::Binder` directly, without the reference.
     fn create_scope(
         &mut self,
         value: &ty::Binder<impl TypeFoldable<'tcx>>,
@@ -369,7 +370,7 @@ fn generalize_value<T: Relate<'tcx>>(
             universe,
         };
 
-        generalizer.relate(&value, &value)
+        generalizer.relate(value, value)
     }
 }
 
@@ -495,8 +496,8 @@ fn a_is_expected(&self) -> bool {
     fn relate_with_variance<T: Relate<'tcx>>(
         &mut self,
         variance: ty::Variance,
-        a: &T,
-        b: &T,
+        a: T,
+        b: T,
     ) -> RelateResult<'tcx, T> {
         debug!("relate_with_variance(variance={:?}, a={:?}, b={:?})", variance, a, b);
 
@@ -613,8 +614,8 @@ fn consts(
 
     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>,
@@ -640,11 +641,10 @@ fn binders<T>(
 
         debug!("binders({:?}: {:?}, ambient_variance={:?})", a, b, self.ambient_variance);
 
-        if !a.skip_binder().has_escaping_bound_vars() && !b.skip_binder().has_escaping_bound_vars()
-        {
+        if let (Some(a), Some(b)) = (a.no_bound_vars(), b.no_bound_vars()) {
             // Fast path for the common case.
-            self.relate(a.skip_binder(), b.skip_binder())?;
-            return Ok(a.clone());
+            self.relate(a, b)?;
+            return Ok(ty::Binder::bind(a));
         }
 
         if self.ambient_covariance() {
@@ -654,8 +654,8 @@ fn binders<T>(
             // instantiation of B (i.e., B instantiated with
             // universals).
 
-            let b_scope = self.create_scope(b, UniversallyQuantified(true));
-            let a_scope = self.create_scope(a, UniversallyQuantified(false));
+            let b_scope = self.create_scope(&b, UniversallyQuantified(true));
+            let a_scope = self.create_scope(&a, UniversallyQuantified(false));
 
             debug!("binders: a_scope = {:?} (existential)", a_scope);
             debug!("binders: b_scope = {:?} (universal)", b_scope);
@@ -683,7 +683,7 @@ fn binders<T>(
             //   subtyping (i.e., `&'b u32 <: &{P} u32`).
             let variance = ::std::mem::replace(&mut self.ambient_variance, ty::Variance::Covariant);
 
-            self.relate(a.skip_binder(), b.skip_binder())?;
+            self.relate(*a.skip_binder(), *b.skip_binder())?;
 
             self.ambient_variance = variance;
 
@@ -698,8 +698,8 @@ fn binders<T>(
             // instantiation of B (i.e., B instantiated with
             // existentials). Opposite of above.
 
-            let a_scope = self.create_scope(a, UniversallyQuantified(true));
-            let b_scope = self.create_scope(b, UniversallyQuantified(false));
+            let a_scope = self.create_scope(&a, UniversallyQuantified(true));
+            let b_scope = self.create_scope(&b, UniversallyQuantified(false));
 
             debug!("binders: a_scope = {:?} (universal)", a_scope);
             debug!("binders: b_scope = {:?} (existential)", b_scope);
@@ -712,7 +712,7 @@ fn binders<T>(
             let variance =
                 ::std::mem::replace(&mut self.ambient_variance, ty::Variance::Contravariant);
 
-            self.relate(a.skip_binder(), b.skip_binder())?;
+            self.relate(*a.skip_binder(), *b.skip_binder())?;
 
             self.ambient_variance = variance;
 
@@ -839,8 +839,8 @@ fn a_is_expected(&self) -> bool {
     fn relate_with_variance<T: Relate<'tcx>>(
         &mut self,
         variance: ty::Variance,
-        a: &T,
-        b: &T,
+        a: T,
+        b: T,
     ) -> RelateResult<'tcx, T> {
         debug!(
             "TypeGeneralizer::relate_with_variance(variance={:?}, a={:?}, b={:?})",
@@ -890,7 +890,7 @@ fn tys(&mut self, a: Ty<'tcx>, _: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
                     match variables.probe(vid) {
                         TypeVariableValue::Known { value: u } => {
                             drop(variables);
-                            self.relate(&u, &u)
+                            self.relate(u, u)
                         }
                         TypeVariableValue::Unknown { universe: _universe } => {
                             if self.ambient_variance == ty::Bivariant {
@@ -984,7 +984,7 @@ fn consts(
                 let variable_table = &mut inner.const_unification_table();
                 let var_value = variable_table.probe_value(vid);
                 match var_value.val.known() {
-                    Some(u) => self.relate(&u, &u),
+                    Some(u) => self.relate(u, u),
                     None => {
                         let new_var_id = variable_table.new_key(ConstVarValue {
                             origin: var_value.origin,
@@ -1001,8 +1001,8 @@ fn consts(
 
     fn binders<T>(
         &mut self,
-        a: &ty::Binder<T>,
-        _: &ty::Binder<T>,
+        a: ty::Binder<T>,
+        _: ty::Binder<T>,
     ) -> RelateResult<'tcx, ty::Binder<T>>
     where
         T: Relate<'tcx>,
@@ -1010,7 +1010,7 @@ fn binders<T>(
         debug!("TypeGeneralizer::binders(a={:?})", a);
 
         self.first_free_index.shift_in(1);
-        let result = self.relate(a.skip_binder(), a.skip_binder())?;
+        let result = self.relate(*a.skip_binder(), *a.skip_binder())?;
         self.first_free_index.shift_out(1);
         Ok(ty::Binder::bind(result))
     }
index 90962d210b5b48198f35f9e1391bda8cf16c6aeb..d190f7e434298996252818144e695e96fcc61d75 100644 (file)
@@ -62,8 +62,8 @@ fn with_cause<F, R>(&mut self, cause: Cause, f: F) -> R
     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),
@@ -162,8 +162,8 @@ fn consts(
 
     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>,
index db9229ae3d214b8a49b410908a22acac4e5df86a..55aafc0b42aa457d9ec67e4366bdedfc2f608f98 100644 (file)
@@ -46,8 +46,8 @@ fn a_is_expected(&self) -> bool {
     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)
     }
@@ -112,12 +112,12 @@ fn consts(
 
     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>,
     {
-        Ok(ty::Binder::bind(self.relate(a.skip_binder(), b.skip_binder())?))
+        Ok(ty::Binder::bind(self.relate(*a.skip_binder(), *b.skip_binder())?))
     }
 }
index e9a8b9095bf72d2845da10d211fef979bdf61e73..cee04ce8c6a831f62212f0b73c461acacad8af27 100644 (file)
@@ -13,7 +13,6 @@
 use rustc_span::DUMMY_SP;
 use rustc_target::spec::abi;
 use std::iter;
-use std::rc::Rc;
 
 pub type RelateResult<'tcx, T> = Result<T, TypeError<'tcx>>;
 
@@ -42,7 +41,7 @@ fn with_cause<F, R>(&mut self, _cause: Cause, f: F) -> R
     }
 
     /// Generic relation routine suitable for most anything.
-    fn relate<T: Relate<'tcx>>(&mut self, a: &T, b: &T) -> RelateResult<'tcx, T> {
+    fn relate<T: Relate<'tcx>>(&mut self, a: T, b: T) -> RelateResult<'tcx, T> {
         Relate::relate(self, a, b)
     }
 
@@ -68,8 +67,8 @@ fn relate_item_substs(
     fn relate_with_variance<T: Relate<'tcx>>(
         &mut self,
         variance: ty::Variance,
-        a: &T,
-        b: &T,
+        a: T,
+        b: T,
     ) -> RelateResult<'tcx, T>;
 
     // Overridable relations. You shouldn't typically call these
@@ -94,18 +93,18 @@ fn consts(
 
     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>;
 }
 
-pub trait Relate<'tcx>: TypeFoldable<'tcx> {
+pub trait Relate<'tcx>: TypeFoldable<'tcx> + Copy {
     fn relate<R: TypeRelation<'tcx>>(
         relation: &mut R,
-        a: &Self,
-        b: &Self,
+        a: Self,
+        b: Self,
     ) -> RelateResult<'tcx, Self>;
 }
 
@@ -115,8 +114,8 @@ fn relate<R: TypeRelation<'tcx>>(
 impl<'tcx> Relate<'tcx> for ty::TypeAndMut<'tcx> {
     fn relate<R: TypeRelation<'tcx>>(
         relation: &mut R,
-        a: &ty::TypeAndMut<'tcx>,
-        b: &ty::TypeAndMut<'tcx>,
+        a: ty::TypeAndMut<'tcx>,
+        b: ty::TypeAndMut<'tcx>,
     ) -> RelateResult<'tcx, ty::TypeAndMut<'tcx>> {
         debug!("{}.mts({:?}, {:?})", relation.tag(), a, b);
         if a.mutbl != b.mutbl {
@@ -127,7 +126,7 @@ fn relate<R: TypeRelation<'tcx>>(
                 ast::Mutability::Not => ty::Covariant,
                 ast::Mutability::Mut => ty::Invariant,
             };
-            let ty = relation.relate_with_variance(variance, &a.ty, &b.ty)?;
+            let ty = relation.relate_with_variance(variance, a.ty, b.ty)?;
             Ok(ty::TypeAndMut { ty, mutbl })
         }
     }
@@ -143,7 +142,7 @@ pub fn relate_substs<R: TypeRelation<'tcx>>(
 
     let params = a_subst.iter().zip(b_subst).enumerate().map(|(i, (a, b))| {
         let variance = variances.map_or(ty::Invariant, |v| v[i]);
-        relation.relate_with_variance(variance, &a, &b)
+        relation.relate_with_variance(variance, a, b)
     });
 
     Ok(tcx.mk_substs(params)?)
@@ -152,8 +151,8 @@ pub fn relate_substs<R: TypeRelation<'tcx>>(
 impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> {
     fn relate<R: TypeRelation<'tcx>>(
         relation: &mut R,
-        a: &ty::FnSig<'tcx>,
-        b: &ty::FnSig<'tcx>,
+        a: ty::FnSig<'tcx>,
+        b: ty::FnSig<'tcx>,
     ) -> RelateResult<'tcx, ty::FnSig<'tcx>> {
         let tcx = relation.tcx();
 
@@ -164,8 +163,8 @@ fn relate<R: TypeRelation<'tcx>>(
                 &b.c_variadic,
             )));
         }
-        let unsafety = relation.relate(&a.unsafety, &b.unsafety)?;
-        let abi = relation.relate(&a.abi, &b.abi)?;
+        let unsafety = relation.relate(a.unsafety, b.unsafety)?;
+        let abi = relation.relate(a.abi, b.abi)?;
 
         if a.inputs().len() != b.inputs().len() {
             return Err(TypeError::ArgCount);
@@ -180,9 +179,9 @@ fn relate<R: TypeRelation<'tcx>>(
             .chain(iter::once(((a.output(), b.output()), true)))
             .map(|((a, b), is_output)| {
                 if is_output {
-                    relation.relate(&a, &b)
+                    relation.relate(a, b)
                 } else {
-                    relation.relate_with_variance(ty::Contravariant, &a, &b)
+                    relation.relate_with_variance(ty::Contravariant, a, b)
                 }
             });
         Ok(ty::FnSig {
@@ -197,13 +196,13 @@ fn relate<R: TypeRelation<'tcx>>(
 impl<'tcx> Relate<'tcx> for ast::Unsafety {
     fn relate<R: TypeRelation<'tcx>>(
         relation: &mut R,
-        a: &ast::Unsafety,
-        b: &ast::Unsafety,
+        a: ast::Unsafety,
+        b: ast::Unsafety,
     ) -> RelateResult<'tcx, ast::Unsafety> {
         if a != b {
-            Err(TypeError::UnsafetyMismatch(expected_found(relation, a, b)))
+            Err(TypeError::UnsafetyMismatch(expected_found(relation, &a, &b)))
         } else {
-            Ok(*a)
+            Ok(a)
         }
     }
 }
@@ -211,18 +210,18 @@ fn relate<R: TypeRelation<'tcx>>(
 impl<'tcx> Relate<'tcx> for abi::Abi {
     fn relate<R: TypeRelation<'tcx>>(
         relation: &mut R,
-        a: &abi::Abi,
-        b: &abi::Abi,
+        a: abi::Abi,
+        b: abi::Abi,
     ) -> RelateResult<'tcx, abi::Abi> {
-        if a == b { Ok(*a) } else { Err(TypeError::AbiMismatch(expected_found(relation, a, b))) }
+        if a == b { Ok(a) } else { Err(TypeError::AbiMismatch(expected_found(relation, &a, &b))) }
     }
 }
 
 impl<'tcx> Relate<'tcx> for ty::ProjectionTy<'tcx> {
     fn relate<R: TypeRelation<'tcx>>(
         relation: &mut R,
-        a: &ty::ProjectionTy<'tcx>,
-        b: &ty::ProjectionTy<'tcx>,
+        a: ty::ProjectionTy<'tcx>,
+        b: ty::ProjectionTy<'tcx>,
     ) -> RelateResult<'tcx, ty::ProjectionTy<'tcx>> {
         if a.item_def_id != b.item_def_id {
             Err(TypeError::ProjectionMismatched(expected_found(
@@ -231,7 +230,7 @@ fn relate<R: TypeRelation<'tcx>>(
                 &b.item_def_id,
             )))
         } else {
-            let substs = relation.relate(&a.substs, &b.substs)?;
+            let substs = relation.relate(a.substs, b.substs)?;
             Ok(ty::ProjectionTy { item_def_id: a.item_def_id, substs: &substs })
         }
     }
@@ -240,8 +239,8 @@ fn relate<R: TypeRelation<'tcx>>(
 impl<'tcx> Relate<'tcx> for ty::ExistentialProjection<'tcx> {
     fn relate<R: TypeRelation<'tcx>>(
         relation: &mut R,
-        a: &ty::ExistentialProjection<'tcx>,
-        b: &ty::ExistentialProjection<'tcx>,
+        a: ty::ExistentialProjection<'tcx>,
+        b: ty::ExistentialProjection<'tcx>,
     ) -> RelateResult<'tcx, ty::ExistentialProjection<'tcx>> {
         if a.item_def_id != b.item_def_id {
             Err(TypeError::ProjectionMismatched(expected_found(
@@ -250,37 +249,18 @@ fn relate<R: TypeRelation<'tcx>>(
                 &b.item_def_id,
             )))
         } else {
-            let ty = relation.relate_with_variance(ty::Invariant, &a.ty, &b.ty)?;
-            let substs = relation.relate_with_variance(ty::Invariant, &a.substs, &b.substs)?;
+            let ty = relation.relate_with_variance(ty::Invariant, a.ty, b.ty)?;
+            let substs = relation.relate_with_variance(ty::Invariant, a.substs, b.substs)?;
             Ok(ty::ExistentialProjection { item_def_id: a.item_def_id, substs, ty })
         }
     }
 }
 
-impl<'tcx> Relate<'tcx> for Vec<ty::PolyExistentialProjection<'tcx>> {
-    fn relate<R: TypeRelation<'tcx>>(
-        relation: &mut R,
-        a: &Vec<ty::PolyExistentialProjection<'tcx>>,
-        b: &Vec<ty::PolyExistentialProjection<'tcx>>,
-    ) -> RelateResult<'tcx, Vec<ty::PolyExistentialProjection<'tcx>>> {
-        // To be compatible, `a` and `b` must be for precisely the
-        // same set of traits and item names. We always require that
-        // projection bounds lists are sorted by trait-def-id and item-name,
-        // so we can just iterate through the lists pairwise, so long as they are the
-        // same length.
-        if a.len() != b.len() {
-            Err(TypeError::ProjectionBoundsLength(expected_found(relation, &a.len(), &b.len())))
-        } else {
-            a.iter().zip(b).map(|(a, b)| relation.relate(a, b)).collect()
-        }
-    }
-}
-
 impl<'tcx> Relate<'tcx> for ty::TraitRef<'tcx> {
     fn relate<R: TypeRelation<'tcx>>(
         relation: &mut R,
-        a: &ty::TraitRef<'tcx>,
-        b: &ty::TraitRef<'tcx>,
+        a: ty::TraitRef<'tcx>,
+        b: ty::TraitRef<'tcx>,
     ) -> RelateResult<'tcx, ty::TraitRef<'tcx>> {
         // Different traits cannot be related.
         if a.def_id != b.def_id {
@@ -295,8 +275,8 @@ fn relate<R: TypeRelation<'tcx>>(
 impl<'tcx> Relate<'tcx> for ty::ExistentialTraitRef<'tcx> {
     fn relate<R: TypeRelation<'tcx>>(
         relation: &mut R,
-        a: &ty::ExistentialTraitRef<'tcx>,
-        b: &ty::ExistentialTraitRef<'tcx>,
+        a: ty::ExistentialTraitRef<'tcx>,
+        b: ty::ExistentialTraitRef<'tcx>,
     ) -> RelateResult<'tcx, ty::ExistentialTraitRef<'tcx>> {
         // Different traits cannot be related.
         if a.def_id != b.def_id {
@@ -308,18 +288,18 @@ fn relate<R: TypeRelation<'tcx>>(
     }
 }
 
-#[derive(Debug, Clone, TypeFoldable)]
+#[derive(Copy, Debug, Clone, TypeFoldable)]
 struct GeneratorWitness<'tcx>(&'tcx ty::List<Ty<'tcx>>);
 
 impl<'tcx> Relate<'tcx> for GeneratorWitness<'tcx> {
     fn relate<R: TypeRelation<'tcx>>(
         relation: &mut R,
-        a: &GeneratorWitness<'tcx>,
-        b: &GeneratorWitness<'tcx>,
+        a: GeneratorWitness<'tcx>,
+        b: GeneratorWitness<'tcx>,
     ) -> RelateResult<'tcx, GeneratorWitness<'tcx>> {
         assert_eq!(a.0.len(), b.0.len());
         let tcx = relation.tcx();
-        let types = tcx.mk_type_list(a.0.iter().zip(b.0).map(|(a, b)| relation.relate(&a, &b)))?;
+        let types = tcx.mk_type_list(a.0.iter().zip(b.0).map(|(a, b)| relation.relate(a, b)))?;
         Ok(GeneratorWitness(types))
     }
 }
@@ -327,8 +307,8 @@ fn relate<R: TypeRelation<'tcx>>(
 impl<'tcx> Relate<'tcx> for Ty<'tcx> {
     fn relate<R: TypeRelation<'tcx>>(
         relation: &mut R,
-        a: &Ty<'tcx>,
-        b: &Ty<'tcx>,
+        a: Ty<'tcx>,
+        b: Ty<'tcx>,
     ) -> RelateResult<'tcx, Ty<'tcx>> {
         relation.tys(a, b)
     }
@@ -379,7 +359,7 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
 
         (&ty::Foreign(a_id), &ty::Foreign(b_id)) if a_id == b_id => Ok(tcx.mk_foreign(a_id)),
 
-        (&ty::Dynamic(ref a_obj, ref a_region), &ty::Dynamic(ref b_obj, ref b_region)) => {
+        (&ty::Dynamic(a_obj, a_region), &ty::Dynamic(b_obj, b_region)) => {
             let region_bound = relation.with_cause(Cause::ExistentialRegionBound, |relation| {
                 relation.relate_with_variance(ty::Contravariant, a_region, b_region)
             })?;
@@ -392,7 +372,7 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
             // All Generator types with the same id represent
             // the (anonymous) type of the same generator expression. So
             // all of their regions should be equated.
-            let substs = relation.relate(&a_substs, &b_substs)?;
+            let substs = relation.relate(a_substs, b_substs)?;
             Ok(tcx.mk_generator(a_id, substs, movability))
         }
 
@@ -402,7 +382,7 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
             let a_types = a_types.map_bound(GeneratorWitness);
             let b_types = b_types.map_bound(GeneratorWitness);
             // Then remove the GeneratorWitness for the result
-            let types = relation.relate(&a_types, &b_types)?.map_bound(|witness| witness.0);
+            let types = relation.relate(a_types, b_types)?.map_bound(|witness| witness.0);
             Ok(tcx.mk_generator_witness(types))
         }
 
@@ -410,26 +390,26 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
             // All Closure types with the same id represent
             // the (anonymous) type of the same closure expression. So
             // all of their regions should be equated.
-            let substs = relation.relate(&a_substs, &b_substs)?;
+            let substs = relation.relate(a_substs, b_substs)?;
             Ok(tcx.mk_closure(a_id, &substs))
         }
 
-        (&ty::RawPtr(ref a_mt), &ty::RawPtr(ref b_mt)) => {
+        (&ty::RawPtr(a_mt), &ty::RawPtr(b_mt)) => {
             let mt = relation.relate(a_mt, b_mt)?;
             Ok(tcx.mk_ptr(mt))
         }
 
         (&ty::Ref(a_r, a_ty, a_mutbl), &ty::Ref(b_r, b_ty, b_mutbl)) => {
-            let r = relation.relate_with_variance(ty::Contravariant, &a_r, &b_r)?;
+            let r = relation.relate_with_variance(ty::Contravariant, a_r, b_r)?;
             let a_mt = ty::TypeAndMut { ty: a_ty, mutbl: a_mutbl };
             let b_mt = ty::TypeAndMut { ty: b_ty, mutbl: b_mutbl };
-            let mt = relation.relate(&a_mt, &b_mt)?;
+            let mt = relation.relate(a_mt, b_mt)?;
             Ok(tcx.mk_ref(r, mt))
         }
 
         (&ty::Array(a_t, sz_a), &ty::Array(b_t, sz_b)) => {
-            let t = relation.relate(&a_t, &b_t)?;
-            match relation.relate(&sz_a, &sz_b) {
+            let t = relation.relate(a_t, b_t)?;
+            match relation.relate(sz_a, sz_b) {
                 Ok(sz) => Ok(tcx.mk_ty(ty::Array(t, sz))),
                 // FIXME(#72219) Implement improved diagnostics for mismatched array
                 // length?
@@ -450,16 +430,14 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
         }
 
         (&ty::Slice(a_t), &ty::Slice(b_t)) => {
-            let t = relation.relate(&a_t, &b_t)?;
+            let t = relation.relate(a_t, b_t)?;
             Ok(tcx.mk_slice(t))
         }
 
         (&ty::Tuple(as_), &ty::Tuple(bs)) => {
             if as_.len() == bs.len() {
                 Ok(tcx.mk_tup(
-                    as_.iter()
-                        .zip(bs)
-                        .map(|(a, b)| relation.relate(&a.expect_ty(), &b.expect_ty())),
+                    as_.iter().zip(bs).map(|(a, b)| relation.relate(a.expect_ty(), b.expect_ty())),
                 )?)
             } else if !(as_.is_empty() || bs.is_empty()) {
                 Err(TypeError::TupleSize(expected_found(relation, &as_.len(), &bs.len())))
@@ -476,12 +454,12 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
         }
 
         (&ty::FnPtr(a_fty), &ty::FnPtr(b_fty)) => {
-            let fty = relation.relate(&a_fty, &b_fty)?;
+            let fty = relation.relate(a_fty, b_fty)?;
             Ok(tcx.mk_fn_ptr(fty))
         }
 
         // these two are already handled downstream in case of lazy normalization
-        (ty::Projection(a_data), ty::Projection(b_data)) => {
+        (&ty::Projection(a_data), &ty::Projection(b_data)) => {
             let projection_ty = relation.relate(a_data, b_data)?;
             Ok(tcx.mk_projection(projection_ty.item_def_id, projection_ty.substs))
         }
@@ -603,8 +581,8 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
             ty::ConstKind::Unevaluated(b_def_id, b_substs, b_promoted),
         ) if a_def_id == b_def_id && a_promoted == b_promoted => {
             let substs =
-                relation.relate_with_variance(ty::Variance::Invariant, &a_substs, &b_substs)?;
-            Ok(ty::ConstKind::Unevaluated(a_def_id, &substs, a_promoted))
+                relation.relate_with_variance(ty::Variance::Invariant, a_substs, b_substs)?;
+            Ok(ty::ConstKind::Unevaluated(a_def_id, substs, a_promoted))
         }
         _ => Err(TypeError::ConstMismatch(expected_found(relation, &a, &b))),
     };
@@ -614,8 +592,8 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
 impl<'tcx> Relate<'tcx> for &'tcx ty::List<ty::ExistentialPredicate<'tcx>> {
     fn relate<R: TypeRelation<'tcx>>(
         relation: &mut R,
-        a: &Self,
-        b: &Self,
+        a: Self,
+        b: Self,
     ) -> RelateResult<'tcx, Self> {
         let tcx = relation.tcx();
 
@@ -629,16 +607,16 @@ fn relate<R: TypeRelation<'tcx>>(
         b_v.sort_by(|a, b| a.stable_cmp(tcx, b));
         b_v.dedup();
         if a_v.len() != b_v.len() {
-            return Err(TypeError::ExistentialMismatch(expected_found(relation, a, b)));
+            return Err(TypeError::ExistentialMismatch(expected_found(relation, &a, &b)));
         }
 
         let v = a_v.into_iter().zip(b_v.into_iter()).map(|(ep_a, ep_b)| {
             use crate::ty::ExistentialPredicate::*;
             match (ep_a, ep_b) {
-                (Trait(ref a), Trait(ref b)) => Ok(Trait(relation.relate(a, b)?)),
-                (Projection(ref a), Projection(ref b)) => Ok(Projection(relation.relate(a, b)?)),
-                (AutoTrait(ref a), AutoTrait(ref b)) if a == b => Ok(AutoTrait(*a)),
-                _ => Err(TypeError::ExistentialMismatch(expected_found(relation, a, b))),
+                (Trait(a), Trait(b)) => Ok(Trait(relation.relate(a, b)?)),
+                (Projection(a), Projection(b)) => Ok(Projection(relation.relate(a, b)?)),
+                (AutoTrait(a), AutoTrait(b)) if a == b => Ok(AutoTrait(a)),
+                _ => Err(TypeError::ExistentialMismatch(expected_found(relation, &a, &b))),
             }
         });
         Ok(tcx.mk_existential_predicates(v)?)
@@ -648,8 +626,8 @@ fn relate<R: TypeRelation<'tcx>>(
 impl<'tcx> Relate<'tcx> for ty::ClosureSubsts<'tcx> {
     fn relate<R: TypeRelation<'tcx>>(
         relation: &mut R,
-        a: &ty::ClosureSubsts<'tcx>,
-        b: &ty::ClosureSubsts<'tcx>,
+        a: ty::ClosureSubsts<'tcx>,
+        b: ty::ClosureSubsts<'tcx>,
     ) -> RelateResult<'tcx, ty::ClosureSubsts<'tcx>> {
         let substs = relate_substs(relation, None, a.substs, b.substs)?;
         Ok(ty::ClosureSubsts { substs })
@@ -659,8 +637,8 @@ fn relate<R: TypeRelation<'tcx>>(
 impl<'tcx> Relate<'tcx> for ty::GeneratorSubsts<'tcx> {
     fn relate<R: TypeRelation<'tcx>>(
         relation: &mut R,
-        a: &ty::GeneratorSubsts<'tcx>,
-        b: &ty::GeneratorSubsts<'tcx>,
+        a: ty::GeneratorSubsts<'tcx>,
+        b: ty::GeneratorSubsts<'tcx>,
     ) -> RelateResult<'tcx, ty::GeneratorSubsts<'tcx>> {
         let substs = relate_substs(relation, None, a.substs, b.substs)?;
         Ok(ty::GeneratorSubsts { substs })
@@ -670,8 +648,8 @@ fn relate<R: TypeRelation<'tcx>>(
 impl<'tcx> Relate<'tcx> for SubstsRef<'tcx> {
     fn relate<R: TypeRelation<'tcx>>(
         relation: &mut R,
-        a: &SubstsRef<'tcx>,
-        b: &SubstsRef<'tcx>,
+        a: SubstsRef<'tcx>,
+        b: SubstsRef<'tcx>,
     ) -> RelateResult<'tcx, SubstsRef<'tcx>> {
         relate_substs(relation, None, a, b)
     }
@@ -680,72 +658,48 @@ fn relate<R: TypeRelation<'tcx>>(
 impl<'tcx> Relate<'tcx> for ty::Region<'tcx> {
     fn relate<R: TypeRelation<'tcx>>(
         relation: &mut R,
-        a: &ty::Region<'tcx>,
-        b: &ty::Region<'tcx>,
+        a: ty::Region<'tcx>,
+        b: ty::Region<'tcx>,
     ) -> RelateResult<'tcx, ty::Region<'tcx>> {
-        relation.regions(*a, *b)
+        relation.regions(a, b)
     }
 }
 
 impl<'tcx> Relate<'tcx> for &'tcx ty::Const<'tcx> {
     fn relate<R: TypeRelation<'tcx>>(
         relation: &mut R,
-        a: &&'tcx ty::Const<'tcx>,
-        b: &&'tcx ty::Const<'tcx>,
+        a: &'tcx ty::Const<'tcx>,
+        b: &'tcx ty::Const<'tcx>,
     ) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> {
-        relation.consts(*a, *b)
+        relation.consts(a, b)
     }
 }
 
 impl<'tcx, T: Relate<'tcx>> Relate<'tcx> for ty::Binder<T> {
     fn relate<R: TypeRelation<'tcx>>(
         relation: &mut R,
-        a: &ty::Binder<T>,
-        b: &ty::Binder<T>,
+        a: ty::Binder<T>,
+        b: ty::Binder<T>,
     ) -> RelateResult<'tcx, ty::Binder<T>> {
         relation.binders(a, b)
     }
 }
 
-impl<'tcx, T: Relate<'tcx>> Relate<'tcx> for Rc<T> {
-    fn relate<R: TypeRelation<'tcx>>(
-        relation: &mut R,
-        a: &Rc<T>,
-        b: &Rc<T>,
-    ) -> RelateResult<'tcx, Rc<T>> {
-        let a: &T = a;
-        let b: &T = b;
-        Ok(Rc::new(relation.relate(a, b)?))
-    }
-}
-
-impl<'tcx, T: Relate<'tcx>> Relate<'tcx> for Box<T> {
-    fn relate<R: TypeRelation<'tcx>>(
-        relation: &mut R,
-        a: &Box<T>,
-        b: &Box<T>,
-    ) -> RelateResult<'tcx, Box<T>> {
-        let a: &T = a;
-        let b: &T = b;
-        Ok(Box::new(relation.relate(a, b)?))
-    }
-}
-
 impl<'tcx> Relate<'tcx> for GenericArg<'tcx> {
     fn relate<R: TypeRelation<'tcx>>(
         relation: &mut R,
-        a: &GenericArg<'tcx>,
-        b: &GenericArg<'tcx>,
+        a: GenericArg<'tcx>,
+        b: GenericArg<'tcx>,
     ) -> RelateResult<'tcx, GenericArg<'tcx>> {
         match (a.unpack(), b.unpack()) {
             (GenericArgKind::Lifetime(a_lt), GenericArgKind::Lifetime(b_lt)) => {
-                Ok(relation.relate(&a_lt, &b_lt)?.into())
+                Ok(relation.relate(a_lt, b_lt)?.into())
             }
             (GenericArgKind::Type(a_ty), GenericArgKind::Type(b_ty)) => {
-                Ok(relation.relate(&a_ty, &b_ty)?.into())
+                Ok(relation.relate(a_ty, b_ty)?.into())
             }
             (GenericArgKind::Const(a_ct), GenericArgKind::Const(b_ct)) => {
-                Ok(relation.relate(&a_ct, &b_ct)?.into())
+                Ok(relation.relate(a_ct, b_ct)?.into())
             }
             (GenericArgKind::Lifetime(unpacked), x) => {
                 bug!("impossible case reached: can't relate: {:?} with {:?}", unpacked, x)
@@ -763,22 +717,22 @@ fn relate<R: TypeRelation<'tcx>>(
 impl<'tcx> Relate<'tcx> for ty::TraitPredicate<'tcx> {
     fn relate<R: TypeRelation<'tcx>>(
         relation: &mut R,
-        a: &ty::TraitPredicate<'tcx>,
-        b: &ty::TraitPredicate<'tcx>,
+        a: ty::TraitPredicate<'tcx>,
+        b: ty::TraitPredicate<'tcx>,
     ) -> RelateResult<'tcx, ty::TraitPredicate<'tcx>> {
-        Ok(ty::TraitPredicate { trait_ref: relation.relate(&a.trait_ref, &b.trait_ref)? })
+        Ok(ty::TraitPredicate { trait_ref: relation.relate(a.trait_ref, b.trait_ref)? })
     }
 }
 
 impl<'tcx> Relate<'tcx> for ty::ProjectionPredicate<'tcx> {
     fn relate<R: TypeRelation<'tcx>>(
         relation: &mut R,
-        a: &ty::ProjectionPredicate<'tcx>,
-        b: &ty::ProjectionPredicate<'tcx>,
+        a: ty::ProjectionPredicate<'tcx>,
+        b: ty::ProjectionPredicate<'tcx>,
     ) -> RelateResult<'tcx, ty::ProjectionPredicate<'tcx>> {
         Ok(ty::ProjectionPredicate {
-            projection_ty: relation.relate(&a.projection_ty, &b.projection_ty)?,
-            ty: relation.relate(&a.ty, &b.ty)?,
+            projection_ty: relation.relate(a.projection_ty, b.projection_ty)?,
+            ty: relation.relate(a.ty, b.ty)?,
         })
     }
 }
index 285d9ed64691a555e190f134a375f2fbf9059bcf..91b1a1fbd97059492a75221f2ed13ebe3d9f46d2 100644 (file)
@@ -31,7 +31,7 @@ pub(super) fn relate_types<'tcx>(
         NllTypeRelatingDelegate::new(infcx, borrowck_context, locations, category),
         v,
     )
-    .relate(&a, &b)?;
+    .relate(a, b)?;
     Ok(())
 }
 
index cff5efbfd0fd169ec6e9c1e514b2df761681a6dd..c41a27c6f431f4e840f8953ef912f5415bb315b8 100644 (file)
@@ -748,8 +748,8 @@ fn evaluate_stack<'o>(
             && stack.iter().skip(1).any(|prev| {
                 stack.obligation.param_env == prev.obligation.param_env
                     && self.match_fresh_trait_refs(
-                        &stack.fresh_trait_ref,
-                        &prev.fresh_trait_ref,
+                        stack.fresh_trait_ref,
+                        prev.fresh_trait_ref,
                         prev.obligation.param_env,
                     )
             })
@@ -1944,8 +1944,8 @@ fn match_poly_trait_ref(
 
     fn match_fresh_trait_refs(
         &self,
-        previous: &ty::PolyTraitRef<'tcx>,
-        current: &ty::PolyTraitRef<'tcx>,
+        previous: ty::PolyTraitRef<'tcx>,
+        current: ty::PolyTraitRef<'tcx>,
         param_env: ty::ParamEnv<'tcx>,
     ) -> bool {
         let mut matcher = ty::_match::Match::new(self.tcx(), param_env);
index b6cd8da236260f9e06fc34b30cfbd3f61642230c..e6b3224050e9bc755fd70a299060f86fe99fb834 100644 (file)
@@ -964,7 +964,7 @@ fn try_find_coercion_lub<E>(
             let sig = self
                 .at(cause, self.param_env)
                 .trace(prev_ty, new_ty)
-                .lub(&a_sig, &b_sig)
+                .lub(a_sig, b_sig)
                 .map(|ok| self.register_infer_ok_obligations(ok))?;
 
             // Reify both sides and return the reified fn pointer type.
index e27c2e45039102a15017eb6554b46df2731e94fd..f2696f27ffd53fb98ab8cb658bb0fcbec5e872a8 100644 (file)
@@ -227,10 +227,10 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
         let predicate_matches_closure = |p: Predicate<'tcx>| {
             let mut relator: SimpleEqRelation<'tcx> = SimpleEqRelation::new(tcx, self_param_env);
             match (predicate.kind(), p.kind()) {
-                (ty::PredicateKind::Trait(a, _), ty::PredicateKind::Trait(b, _)) => {
+                (&ty::PredicateKind::Trait(a, _), &ty::PredicateKind::Trait(b, _)) => {
                     relator.relate(a, b).is_ok()
                 }
-                (ty::PredicateKind::Projection(a), ty::PredicateKind::Projection(b)) => {
+                (&ty::PredicateKind::Projection(a), &ty::PredicateKind::Projection(b)) => {
                     relator.relate(a, b).is_ok()
                 }
                 _ => predicate == p,
@@ -310,8 +310,8 @@ fn a_is_expected(&self) -> bool {
     fn relate_with_variance<T: Relate<'tcx>>(
         &mut self,
         _: ty::Variance,
-        a: &T,
-        b: &T,
+        a: T,
+        b: T,
     ) -> RelateResult<'tcx, T> {
         // Here we ignore variance because we require drop impl's types
         // to be *exactly* the same as to the ones in the struct definition.
@@ -354,8 +354,8 @@ fn consts(
 
     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>,
@@ -364,9 +364,9 @@ fn binders<T>(
 
         // Anonymizing the LBRs is necessary to solve (Issue #59497).
         // After we do so, it should be totally fine to skip the binders.
-        let anon_a = self.tcx.anonymize_late_bound_regions(a);
-        let anon_b = self.tcx.anonymize_late_bound_regions(b);
-        self.relate(anon_a.skip_binder(), anon_b.skip_binder())?;
+        let anon_a = self.tcx.anonymize_late_bound_regions(&a);
+        let anon_b = self.tcx.anonymize_late_bound_regions(&b);
+        self.relate(*anon_a.skip_binder(), *anon_b.skip_binder())?;
 
         Ok(a.clone())
     }