about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSeo Sanghyeon <sanxiyn@gmail.com>2015-04-08 13:55:18 +0900
committerSeo Sanghyeon <sanxiyn@gmail.com>2015-04-08 15:02:12 +0900
commite2ff1881b2c892aab0ed721a1ecdb4309053dcab (patch)
tree0ee9c27364373f243b3223f7adc8307b59fcec19
parentd18b405faf09514febc4163d96e85e57e137df81 (diff)
downloadrust-e2ff1881b2c892aab0ed721a1ecdb4309053dcab.tar.gz
rust-e2ff1881b2c892aab0ed721a1ecdb4309053dcab.zip
Address review comments
-rw-r--r--src/librustc_typeck/check/cast.rs8
-rw-r--r--src/librustc_typeck/check/mod.rs9
-rw-r--r--src/test/compile-fail/fat-ptr-cast.rs7
3 files changed, 13 insertions, 11 deletions
diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs
index 045b88e2357..3773ff7078e 100644
--- a/src/librustc_typeck/check/cast.rs
+++ b/src/librustc_typeck/check/cast.rs
@@ -115,12 +115,12 @@ pub fn check_cast<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, cast: &CastCheck<'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 {
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index cab6f76d027..4ecef2235a9 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -1560,13 +1560,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
     }
 
     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,
diff --git a/src/test/compile-fail/fat-ptr-cast.rs b/src/test/compile-fail/fat-ptr-cast.rs
index 839ebbd279a..ac5969410fc 100644
--- a/src/test/compile-fail/fat-ptr-cast.rs
+++ b/src/test/compile-fail/fat-ptr-cast.rs
@@ -10,5 +10,10 @@
 
 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
 }