diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_typeck/check/cast.rs | 6 | ||||
| -rw-r--r-- | src/test/compile-fail/unsupported-cast.rs | 5 |
2 files changed, 9 insertions, 2 deletions
diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index b35e3c800fc..b7aebff9ac0 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -94,9 +94,11 @@ pub fn check_cast<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, cast: &CastCheck<'tcx>) { let t_e_is_c_enum = ty::type_is_c_like_enum(fcx.tcx(), t_e); let t_1_is_scalar = ty::type_is_scalar(t_1); + let t_1_is_integral = ty::type_is_integral(t_1); let t_1_is_char = ty::type_is_char(t_1); let t_1_is_bare_fn = ty::type_is_bare_fn(t_1); let t_1_is_float = ty::type_is_floating_point(t_1); + let t_1_is_c_enum = ty::type_is_c_like_enum(fcx.tcx(), t_1); // casts to scalars other than `char` and `bare fn` are trivial let t_1_is_trivial = t_1_is_scalar && !t_1_is_char && !t_1_is_bare_fn; @@ -113,6 +115,10 @@ 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) { + // 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) { // Casts to float must go through an integer or boolean diff --git a/src/test/compile-fail/unsupported-cast.rs b/src/test/compile-fail/unsupported-cast.rs index ca17c898ec3..b4246f2ed87 100644 --- a/src/test/compile-fail/unsupported-cast.rs +++ b/src/test/compile-fail/unsupported-cast.rs @@ -8,8 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// ignore-test FIXME: #13993 -// error-pattern:unsupported cast +// error-pattern:illegal cast + +#![feature(libc)] extern crate libc; |
