@@ -3229,12 +3229,24 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
32293229 let t_1_is_scalar = type_is_scalar ( fcx, expr. span , t_1) ;
32303230 let t_1_is_char = type_is_char ( fcx, expr. span , t_1) ;
32313231 let t_1_is_bare_fn = type_is_bare_fn ( fcx, expr. span , t_1) ;
3232+ let t_1_is_float = type_is_floating_point ( fcx,
3233+ expr. span ,
3234+ t_1) ;
32323235
32333236 // casts to scalars other than `char` and `bare fn` are trivial
32343237 let t_1_is_trivial = t_1_is_scalar &&
32353238 !t_1_is_char && !t_1_is_bare_fn;
32363239
3237- if type_is_c_like_enum ( fcx, expr. span , t_e) && t_1_is_trivial {
3240+ if type_is_c_like_enum ( fcx, expr. span , t_e) &&
3241+ t_1_is_trivial {
3242+ if t_1_is_float {
3243+ fcx. type_error_message ( expr. span , |actual| {
3244+ format ! ( "illegal cast; cast through an \
3245+ integer first: `{}` as `{}`",
3246+ actual,
3247+ fcx. infcx( ) . ty_to_str( t_1) )
3248+ } , t_e, None ) ;
3249+ }
32383250 // casts from C-like enums are allowed
32393251 } else if t_1_is_char {
32403252 let te = fcx. infcx ( ) . resolve_type_vars_if_possible ( te) ;
@@ -4205,6 +4217,11 @@ pub fn type_is_bare_fn(fcx: &FnCtxt, sp: Span, typ: ty::t) -> bool {
42054217 return ty:: type_is_bare_fn ( typ_s) ;
42064218}
42074219
4220+ pub fn type_is_floating_point ( fcx : & FnCtxt , sp : Span , typ : ty:: t ) -> bool {
4221+ let typ_s = structurally_resolved_type ( fcx, sp, typ) ;
4222+ return ty:: type_is_floating_point ( typ_s) ;
4223+ }
4224+
42084225pub fn type_is_unsafe_ptr ( fcx : & FnCtxt , sp : Span , typ : ty:: t ) -> bool {
42094226 let typ_s = structurally_resolved_type ( fcx, sp, typ) ;
42104227 return ty:: type_is_unsafe_ptr ( typ_s) ;
0 commit comments