]> git.lizzy.rs Git - rust.git/commitdiff
Address review comments
authorSeo Sanghyeon <sanxiyn@gmail.com>
Wed, 8 Apr 2015 04:55:18 +0000 (13:55 +0900)
committerSeo Sanghyeon <sanxiyn@gmail.com>
Wed, 8 Apr 2015 06:02:12 +0000 (15:02 +0900)
src/librustc_typeck/check/cast.rs
src/librustc_typeck/check/mod.rs
src/test/compile-fail/fat-ptr-cast.rs

index 045b88e2357cdfab2a38d092d34353e47d2f0a58..3773ff7078e9c33549a104effc70b8adf1b2be38 100644 (file)
@@ -115,12 +115,12 @@ fn cast_through_integer_err<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
     } else if t_1.sty == ty::ty_bool {
         span_err!(fcx.tcx().sess, span, E0054,
                   "cannot cast as `bool`, compare with zero instead");
-    } else if t_e_is_float && (t_1_is_scalar || t_1_is_c_enum) && !(
-        t_1_is_integral || t_1_is_float) {
+    } else if t_e_is_float && (t_1_is_scalar || t_1_is_c_enum) &&
+        !(t_1_is_integral || t_1_is_float) {
         // Casts from float must go through an integer
         cast_through_integer_err(fcx, span, t_1, t_e)
-    } else if t_1_is_float && (t_e_is_scalar || t_e_is_c_enum) && !(
-        t_e_is_integral || t_e_is_float || t_e.sty == ty::ty_bool) {
+    } else if t_1_is_float && (t_e_is_scalar || t_e_is_c_enum) &&
+        !(t_e_is_integral || t_e_is_float || t_e.sty == ty::ty_bool) {
         // Casts to float must go through an integer or boolean
         cast_through_integer_err(fcx, span, t_1, t_e)
     } else if t_e_is_c_enum && t_1_is_trivial {
index cab6f76d0271b3006e96b37a46f4bf7f470b86ec..4ecef2235a911c6b8b2a33da8e362f16fd53443c 100644 (file)
@@ -1560,13 +1560,10 @@ pub fn type_is_known_to_be_sized(&self,
     }
 
     pub fn type_is_fat_ptr(&self, ty: Ty<'tcx>, span: Span) -> bool {
-        match ty.sty {
-            ty::ty_ptr(ty::mt { ty: t, .. }) |
-            ty::ty_rptr(_, ty::mt { ty: t, .. }) => {
-                !self.type_is_known_to_be_sized(t, span)
-            }
-            _ => false
+        if let Some(mt) = ty::deref(ty, true) {
+            return !self.type_is_known_to_be_sized(mt.ty, span);
         }
+        false
     }
 
     pub fn register_builtin_bound(&self,
index 839ebbd279a997bdae6fbf851294b7b24ff80ad2..ac5969410fc0122788afef4f00cf06380f97239d 100644 (file)
 
 fn main() {
     let a: &[i32] = &[1, 2, 3];
-    a as *const [i32] as usize; //~ ERROR cast from fat pointer
+    let b: Box<[i32]> = Box::new([1, 2, 3]);
+    let p = a as *const [i32];
+
+    a as usize; //~ ERROR cast from fat pointer
+    b as usize; //~ ERROR cast from fat pointer
+    p as usize; //~ ERROR cast from fat pointer
 }