Skip to content

Commit a1b6923

Browse files
committed
Address review comments
1 parent d18b405 commit a1b6923

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
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

+2-1
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15621562
pub fn type_is_fat_ptr(&self, ty: Ty<'tcx>, span: Span) -> bool {
15631563
match ty.sty {
15641564
ty::ty_ptr(ty::mt { ty: t, .. }) |
1565-
ty::ty_rptr(_, ty::mt { ty: t, .. }) => {
1565+
ty::ty_rptr(_, ty::mt { ty: t, .. }) |
1566+
ty::ty_uniq(t) => {
15661567
!self.type_is_known_to_be_sized(t, span)
15671568
}
15681569
_ => false

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)