about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2018-12-29 10:54:32 -0800
committerEsteban Küber <esteban@kuber.com.ar>2018-12-29 10:54:32 -0800
commit0ecc128ccb43d0302288011a6919989e91da3bb8 (patch)
tree3ac30256df4861632ac486bd4e97dc70112f9b4f
parent8da6727e961915c153a782cd06b56bfbd796d8fe (diff)
downloadrust-0ecc128ccb43d0302288011a6919989e91da3bb8.tar.gz
rust-0ecc128ccb43d0302288011a6919989e91da3bb8.zip
Use `same_type` instead of duplicating logic
-rw-r--r--src/librustc/infer/error_reporting/mod.rs31
-rw-r--r--src/librustc/ty/util.rs28
2 files changed, 26 insertions, 33 deletions
diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs
index c9fc896b1b2..e34bb9f4f7b 100644
--- a/src/librustc/infer/error_reporting/mod.rs
+++ b/src/librustc/infer/error_reporting/mod.rs
@@ -1005,26 +1005,19 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
                         {
                             let mut show_suggestion = true;
                             for (exp_ty, found_ty) in exp_substs.types().zip(found_substs.types()) {
-                                if let TyKind::Ref(_, exp_ty, _) = exp_ty.sty {
-                                    match (&exp_ty.sty, &found_ty.sty) {
-                                        (TyKind::Adt(exp_did, _), TyKind::Adt(found_did, _))
-                                        if exp_did == found_did => {}
-                                        (TyKind::Bool, TyKind::Bool) |
-                                        (TyKind::Char, TyKind::Char) |
-                                        (TyKind::Str, TyKind::Str) |
-                                        (_, TyKind::Param(_)) |
-                                        (_, TyKind::Infer(_)) |
-                                        (TyKind::Param(_), _) |
-                                        (TyKind::Infer(_), _) => {}
-                                        (TyKind::Int(x), TyKind::Int(y)) if x == y => {}
-                                        (TyKind::Uint(x), TyKind::Uint(y)) if x == y => {}
-                                        (TyKind::Int(x), TyKind::Int(y)) if x == y => {}
-                                        (TyKind::Uint(x), TyKind::Uint(y)) if x == y => {}
-                                        (TyKind::Float(x), TyKind::Float(y)) if x == y => {}
-                                        _ => show_suggestion = false,
+                                match exp_ty.sty {
+                                    TyKind::Ref(_, exp_ty, _) => {
+                                        match (&exp_ty.sty, &found_ty.sty) {
+                                            (_, TyKind::Param(_)) |
+                                            (_, TyKind::Infer(_)) |
+                                            (TyKind::Param(_), _) |
+                                            (TyKind::Infer(_), _) => {}
+                                            _ if ty::TyS::same_type(exp_ty, found_ty) => {}
+                                            _ => show_suggestion = false,
+                                        };
                                     }
-                                } else {
-                                    show_suggestion = false;
+                                    TyKind::Param(_) | TyKind::Infer(_) => {}
+                                    _ => show_suggestion = false,
                                 }
                             }
                             if let (Ok(snippet), true) = (
diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs
index b2e2955619e..1d30ccb87b5 100644
--- a/src/librustc/ty/util.rs
+++ b/src/librustc/ty/util.rs
@@ -658,6 +658,19 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
         tcx.needs_drop_raw(param_env.and(self))
     }
 
+    pub fn same_type(a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
+        match (&a.sty, &b.sty) {
+            (&Adt(did_a, substs_a), &Adt(did_b, substs_b)) => {
+                if did_a != did_b {
+                    return false;
+                }
+
+                substs_a.types().zip(substs_b.types()).all(|(a, b)| Self::same_type(a, b))
+            }
+            _ => a == b,
+        }
+    }
+
     /// Check whether a type is representable. This means it cannot contain unboxed
     /// structural recursion. This check is needed for structs and enums.
     pub fn is_representable(&'tcx self,
@@ -730,19 +743,6 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
             }
         }
 
-        fn same_type<'tcx>(a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
-            match (&a.sty, &b.sty) {
-                (&Adt(did_a, substs_a), &Adt(did_b, substs_b)) => {
-                    if did_a != did_b {
-                        return false;
-                    }
-
-                    substs_a.types().zip(substs_b.types()).all(|(a, b)| same_type(a, b))
-                }
-                _ => a == b,
-            }
-        }
-
         // Does the type `ty` directly (without indirection through a pointer)
         // contain any types on stack `seen`?
         fn is_type_structurally_recursive<'a, 'tcx>(
@@ -807,7 +807,7 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
                         // struct Foo { Option<Option<Foo>> }
 
                         for &seen_type in iter {
-                            if same_type(ty, seen_type) {
+                            if ty::TyS::same_type(ty, seen_type) {
                                 debug!("ContainsRecursive: {:?} contains {:?}",
                                        seen_type,
                                        ty);