This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
librustc/middle/typeck/check Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -1219,6 +1219,13 @@ fn check_cast(fcx: &FnCtxt,
1219
1219
actual,
1220
1220
fcx. infcx( ) . ty_to_string( t_1) )
1221
1221
} , t_e, None ) ;
1222
+ } else if ty:: type_is_unsafe_ptr ( t_e) && t_1_is_float {
1223
+ fcx. type_error_message ( span, |actual| {
1224
+ format ! ( "cannot cast from pointer to float directly: `{}` as `{}`; cast through an \
1225
+ integer first",
1226
+ actual,
1227
+ fcx. infcx( ) . ty_to_string( t_1) )
1228
+ } , t_e, None ) ;
1222
1229
}
1223
1230
1224
1231
fcx. write_ty ( id, t_1) ;
Original file line number Diff line number Diff line change
1
+ // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ fn main ( ) {
12
+ let x : i16 = 22 ;
13
+ ( ( & x) as * const i16 ) as f32 ;
14
+ //~^ ERROR: cannot cast from pointer to float directly: `*const i16` as `f32`
15
+ }
You can’t perform that action at this time.
0 commit comments