]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/fn_to_numeric_cast.txt
Merge commit 'b52fb5234cd7c11ecfae51897a6f7fa52e8777fc' into clippyup
[rust.git] / src / tools / clippy / 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 ```