Skip to content

Commit e2ff188

Browse files
committed
Address review comments
1 parent d18b405 commit e2ff188

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

src/librustc_typeck/check/cast.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ pub fn check_cast<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, cast: &CastCheck<'tcx>) {
115115
} else if t_1.sty == ty::ty_bool {
116116
span_err!(fcx.tcx().sess, span, E0054,
117117
"cannot cast as `bool`, compare with zero instead");
118-
} else if t_e_is_float && (t_1_is_scalar || t_1_is_c_enum) && !(
119-
t_1_is_integral || t_1_is_float) {
118+
} else if t_e_is_float && (t_1_is_scalar || t_1_is_c_enum) &&
119+
!(t_1_is_integral || t_1_is_float) {
120120
// Casts from float must go through an integer
121121
cast_through_integer_err(fcx, span, t_1, t_e)
122-
} else if t_1_is_float && (t_e_is_scalar || t_e_is_c_enum) && !(
123-
t_e_is_integral || t_e_is_float || t_e.sty == ty::ty_bool) {
122+
} else if t_1_is_float && (t_e_is_scalar || t_e_is_c_enum) &&
123+
!(t_e_is_integral || t_e_is_float || t_e.sty == ty::ty_bool) {
124124
// Casts to float must go through an integer or boolean
125125
cast_through_integer_err(fcx, span, t_1, t_e)
126126
} else if t_e_is_c_enum && t_1_is_trivial {

src/librustc_typeck/check/mod.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1560,13 +1560,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15601560
}
15611561

15621562
pub fn type_is_fat_ptr(&self, ty: Ty<'tcx>, span: Span) -> bool {
1563-
match ty.sty {
1564-
ty::ty_ptr(ty::mt { ty: t, .. }) |
1565-
ty::ty_rptr(_, ty::mt { ty: t, .. }) => {
1566-
!self.type_is_known_to_be_sized(t, span)
1567-
}
1568-
_ => false
1563+
if let Some(mt) = ty::deref(ty, true) {
1564+
return !self.type_is_known_to_be_sized(mt.ty, span);
15691565
}
1566+
false
15701567
}
15711568

15721569
pub fn register_builtin_bound(&self,

src/test/compile-fail/fat-ptr-cast.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,10 @@
1010

1111
fn main() {
1212
let a: &[i32] = &[1, 2, 3];
13-
a as *const [i32] as usize; //~ ERROR cast from fat pointer
13+
let b: Box<[i32]> = Box::new([1, 2, 3]);
14+
let p = a as *const [i32];
15+
16+
a as usize; //~ ERROR cast from fat pointer
17+
b as usize; //~ ERROR cast from fat pointer
18+
p as usize; //~ ERROR cast from fat pointer
1419
}

0 commit comments

Comments
 (0)