]> git.lizzy.rs Git - rust.git/commitdiff
expected found `&T` -> `T`
authorBastian Kauschke <bastian_kauschke@hotmail.de>
Sun, 5 Jul 2020 09:38:39 +0000 (11:38 +0200)
committerBastian Kauschke <bastian_kauschke@hotmail.de>
Sun, 5 Jul 2020 09:38:39 +0000 (11:38 +0200)
src/librustc_infer/infer/combine.rs
src/librustc_middle/ty/relate.rs

index c8d4e9f0e14b9e66c916b3cb84b8927ae24c2a72..3b564e03d9a94e91ff1fe11b78e4ff7505147402 100644 (file)
@@ -112,7 +112,7 @@ pub fn super_combine_tys<R>(
 
             // All other cases of inference are errors
             (&ty::Infer(_), _) | (_, &ty::Infer(_)) => {
-                Err(TypeError::Sorts(ty::relate::expected_found(relation, &a, &b)))
+                Err(TypeError::Sorts(ty::relate::expected_found(relation, a, b)))
             }
 
             _ => ty::relate::super_relate_tys(relation, a, b),
@@ -701,7 +701,7 @@ pub fn const_unification_error<'tcx>(
     a_is_expected: bool,
     (a, b): (&'tcx ty::Const<'tcx>, &'tcx ty::Const<'tcx>),
 ) -> TypeError<'tcx> {
-    TypeError::ConstMismatch(ty::relate::expected_found_bool(a_is_expected, &a, &b))
+    TypeError::ConstMismatch(ty::relate::expected_found_bool(a_is_expected, a, b))
 }
 
 fn int_unification_error<'tcx>(
@@ -709,7 +709,7 @@ fn int_unification_error<'tcx>(
     v: (ty::IntVarValue, ty::IntVarValue),
 ) -> TypeError<'tcx> {
     let (a, b) = v;
-    TypeError::IntMismatch(ty::relate::expected_found_bool(a_is_expected, &a, &b))
+    TypeError::IntMismatch(ty::relate::expected_found_bool(a_is_expected, a, b))
 }
 
 fn float_unification_error<'tcx>(
@@ -717,5 +717,5 @@ fn float_unification_error<'tcx>(
     v: (ty::FloatVarValue, ty::FloatVarValue),
 ) -> TypeError<'tcx> {
     let (ty::FloatVarValue(a), ty::FloatVarValue(b)) = v;
-    TypeError::FloatMismatch(ty::relate::expected_found_bool(a_is_expected, &a, &b))
+    TypeError::FloatMismatch(ty::relate::expected_found_bool(a_is_expected, a, b))
 }
index cee04ce8c6a831f62212f0b73c461acacad8af27..7946a27b4d9686759dca28551903c0a7cd4256a9 100644 (file)
@@ -159,8 +159,8 @@ fn relate<R: TypeRelation<'tcx>>(
         if a.c_variadic != b.c_variadic {
             return Err(TypeError::VariadicMismatch(expected_found(
                 relation,
-                &a.c_variadic,
-                &b.c_variadic,
+                a.c_variadic,
+                b.c_variadic,
             )));
         }
         let unsafety = relation.relate(a.unsafety, b.unsafety)?;
@@ -200,7 +200,7 @@ fn relate<R: TypeRelation<'tcx>>(
         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)
         }
@@ -213,7 +213,7 @@ fn relate<R: TypeRelation<'tcx>>(
         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))) }
     }
 }
 
@@ -226,8 +226,8 @@ fn relate<R: TypeRelation<'tcx>>(
         if a.item_def_id != b.item_def_id {
             Err(TypeError::ProjectionMismatched(expected_found(
                 relation,
-                &a.item_def_id,
-                &b.item_def_id,
+                a.item_def_id,
+                b.item_def_id,
             )))
         } else {
             let substs = relation.relate(a.substs, b.substs)?;
@@ -245,8 +245,8 @@ fn relate<R: TypeRelation<'tcx>>(
         if a.item_def_id != b.item_def_id {
             Err(TypeError::ProjectionMismatched(expected_found(
                 relation,
-                &a.item_def_id,
-                &b.item_def_id,
+                a.item_def_id,
+                b.item_def_id,
             )))
         } else {
             let ty = relation.relate_with_variance(ty::Invariant, a.ty, b.ty)?;
@@ -264,7 +264,7 @@ fn relate<R: TypeRelation<'tcx>>(
     ) -> RelateResult<'tcx, ty::TraitRef<'tcx>> {
         // Different traits cannot be related.
         if a.def_id != b.def_id {
-            Err(TypeError::Traits(expected_found(relation, &a.def_id, &b.def_id)))
+            Err(TypeError::Traits(expected_found(relation, a.def_id, b.def_id)))
         } else {
             let substs = relate_substs(relation, None, a.substs, b.substs)?;
             Ok(ty::TraitRef { def_id: a.def_id, substs })
@@ -280,7 +280,7 @@ fn relate<R: TypeRelation<'tcx>>(
     ) -> RelateResult<'tcx, ty::ExistentialTraitRef<'tcx>> {
         // Different traits cannot be related.
         if a.def_id != b.def_id {
-            Err(TypeError::Traits(expected_found(relation, &a.def_id, &b.def_id)))
+            Err(TypeError::Traits(expected_found(relation, a.def_id, b.def_id)))
         } else {
             let substs = relate_substs(relation, None, a.substs, b.substs)?;
             Ok(ty::ExistentialTraitRef { def_id: a.def_id, substs })
@@ -305,6 +305,7 @@ fn relate<R: TypeRelation<'tcx>>(
 }
 
 impl<'tcx> Relate<'tcx> for Ty<'tcx> {
+    #[inline]
     fn relate<R: TypeRelation<'tcx>>(
         relation: &mut R,
         a: Ty<'tcx>,
@@ -421,7 +422,7 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
                     let sz_b = sz_b.try_eval_usize(tcx, relation.param_env());
                     match (sz_a, sz_b) {
                         (Some(sz_a_val), Some(sz_b_val)) => Err(TypeError::FixedArraySize(
-                            expected_found(relation, &sz_a_val, &sz_b_val),
+                            expected_found(relation, sz_a_val, sz_b_val),
                         )),
                         _ => Err(err),
                     }
@@ -440,9 +441,9 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
                     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())))
+                Err(TypeError::TupleSize(expected_found(relation, as_.len(), bs.len())))
             } else {
-                Err(TypeError::Sorts(expected_found(relation, &a, &b)))
+                Err(TypeError::Sorts(expected_found(relation, a, b)))
             }
         }
 
@@ -471,7 +472,7 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
             Ok(tcx.mk_opaque(a_def_id, substs))
         }
 
-        _ => Err(TypeError::Sorts(expected_found(relation, &a, &b))),
+        _ => Err(TypeError::Sorts(expected_found(relation, a, b))),
     }
 }
 
@@ -521,10 +522,10 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
                         if a_instance == b_instance {
                             Ok(ConstValue::Scalar(a_val))
                         } else {
-                            Err(TypeError::ConstMismatch(expected_found(relation, &a, &b)))
+                            Err(TypeError::ConstMismatch(expected_found(relation, a, b)))
                         }
                     } else {
-                        Err(TypeError::ConstMismatch(expected_found(relation, &a, &b)))
+                        Err(TypeError::ConstMismatch(expected_found(relation, a, b)))
                     }
                 }
 
@@ -534,7 +535,7 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
                     if a_bytes == b_bytes {
                         Ok(a_val)
                     } else {
-                        Err(TypeError::ConstMismatch(expected_found(relation, &a, &b)))
+                        Err(TypeError::ConstMismatch(expected_found(relation, a, b)))
                     }
                 }
 
@@ -554,7 +555,7 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
 
                                 Ok(a_val)
                             } else {
-                                Err(TypeError::ConstMismatch(expected_found(relation, &a, &b)))
+                                Err(TypeError::ConstMismatch(expected_found(relation, a, b)))
                             }
                         }
                         // FIXME(const_generics): There are probably some `TyKind`s
@@ -564,12 +565,12 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
                                 DUMMY_SP,
                                 &format!("unexpected consts: a: {:?}, b: {:?}", a, b),
                             );
-                            Err(TypeError::ConstMismatch(expected_found(relation, &a, &b)))
+                            Err(TypeError::ConstMismatch(expected_found(relation, a, b)))
                         }
                     }
                 }
 
-                _ => Err(TypeError::ConstMismatch(expected_found(relation, &a, &b))),
+                _ => Err(TypeError::ConstMismatch(expected_found(relation, a, b))),
             };
 
             new_val.map(ty::ConstKind::Value)
@@ -584,7 +585,7 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
                 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))),
+        _ => Err(TypeError::ConstMismatch(expected_found(relation, a, b))),
     };
     new_const_val.map(|val| tcx.mk_const(ty::Const { val, ty: a.ty }))
 }
@@ -607,7 +608,7 @@ 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)| {
@@ -616,7 +617,7 @@ fn relate<R: TypeRelation<'tcx>>(
                 (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))),
+                _ => Err(TypeError::ExistentialMismatch(expected_found(relation, a, b))),
             }
         });
         Ok(tcx.mk_existential_predicates(v)?)
@@ -740,20 +741,14 @@ fn relate<R: TypeRelation<'tcx>>(
 ///////////////////////////////////////////////////////////////////////////
 // Error handling
 
-pub fn expected_found<R, T>(relation: &mut R, a: &T, b: &T) -> ExpectedFound<T>
+pub fn expected_found<R, T>(relation: &mut R, a: T, b: T) -> ExpectedFound<T>
 where
     R: TypeRelation<'tcx>,
-    T: Clone,
 {
     expected_found_bool(relation.a_is_expected(), a, b)
 }
 
-pub fn expected_found_bool<T>(a_is_expected: bool, a: &T, b: &T) -> ExpectedFound<T>
-where
-    T: Clone,
-{
-    let a = a.clone();
-    let b = b.clone();
+pub fn expected_found_bool<T>(a_is_expected: bool, a: T, b: T) -> ExpectedFound<T> {
     if a_is_expected {
         ExpectedFound { expected: a, found: b }
     } else {