File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 1+ //@ run-rustfix
2+
3+ #![deny(function_casts_as_integer)]
4+ #![allow(unused_variables)] // For the rustfix-ed code.
5+
6+ fn foo() {}
7+
8+ fn main() {
9+ let x = foo as fn() as usize; //~ ERROR: function_casts_as_integer
10+ let x = String::len as for<'a> fn(&'a String) -> usize as usize; //~ ERROR: function_casts_as_integer
11+ // Ok.
12+ let x = foo as fn() as usize;
13+ }
Original file line number Diff line number Diff line change 1+ //@ run-rustfix
2+
3+ #![ deny( function_casts_as_integer) ]
4+ #![ allow( unused_variables) ] // For the rustfix-ed code.
5+
6+ fn foo ( ) { }
7+
8+ fn main ( ) {
9+ let x = foo as usize ; //~ ERROR: function_casts_as_integer
10+ let x = String :: len as usize ; //~ ERROR: function_casts_as_integer
11+ // Ok.
12+ let x = foo as fn ( ) as usize ;
13+ }
Original file line number Diff line number Diff line change 1+ error: direct cast of function item into an integer
2+ --> $DIR/function_casts_as_integer.rs:9:17
3+ |
4+ LL | let x = foo as usize;
5+ | ^^^^^^^^
6+ |
7+ note: the lint level is defined here
8+ --> $DIR/function_casts_as_integer.rs:3:9
9+ |
10+ LL | #![deny(function_casts_as_integer)]
11+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
12+ help: first cast to a function pointer `fn()`
13+ |
14+ LL | let x = foo as fn() as usize;
15+ | +++++++
16+
17+ error: direct cast of function item into an integer
18+ --> $DIR/function_casts_as_integer.rs:10:25
19+ |
20+ LL | let x = String::len as usize;
21+ | ^^^^^^^^
22+ |
23+ help: first cast to a function pointer `for<'a> fn(&'a String) -> usize`
24+ |
25+ LL | let x = String::len as for<'a> fn(&'a String) -> usize as usize;
26+ | ++++++++++++++++++++++++++++++++++
27+
28+ error: aborting due to 2 previous errors
29+
You can’t perform that action at this time.
0 commit comments