]> git.lizzy.rs Git - rust.git/blob - src/docs/fn_to_numeric_cast.txt
1f587f6d7176891c2999504b86bc80923eddf3ae
[rust.git] / src / docs / fn_to_numeric_cast.txt
1 ### What it does
2 Checks for casts of function pointers to something other than usize
3
4 ### Why is this bad?
5 Casting a function pointer to anything other than usize/isize is not portable across
6 architectures, because you end up losing bits if the target type is too small or end up with a
7 bunch of extra bits that waste space and add more instructions to the final binary than
8 strictly necessary for the problem
9
10 Casting to isize also doesn't make sense since there are no signed addresses.
11
12 ### Example
13 ```
14 fn fun() -> i32 { 1 }
15 let _ = fun as i64;
16 ```
17
18 Use instead:
19 ```
20 let _ = fun as usize;
21 ```