Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sanxiyn committed Apr 8, 2015
1 parent d18b405 commit e2ff188
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/librustc_typeck/check/cast.rs
Expand Up @@ -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 {
Expand Down
9 changes: 3 additions & 6 deletions src/librustc_typeck/check/mod.rs
Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion src/test/compile-fail/fat-ptr-cast.rs
Expand Up @@ -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
}

0 comments on commit e2ff188

Please sign in to comment.