]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/fn_to_numeric_cast_with_truncation.txt
Auto merge of #101615 - compiler-errors:rpitit-perf, r=oli-obk
[rust.git] / src / tools / clippy / src / docs / fn_to_numeric_cast_with_truncation.txt
1 ### What it does
2 Checks for casts of a function pointer to a numeric type not wide enough to
3 store address.
4
5 ### Why is this bad?
6 Such a cast discards some bits of the function's address. If this is intended, it would be more
7 clearly expressed by casting to usize first, then casting the usize to the intended type (with
8 a comment) to perform the truncation.
9
10 ### Example
11 ```
12 fn fn1() -> i16 {
13     1
14 };
15 let _ = fn1 as i32;
16 ```
17
18 Use instead:
19 ```
20 // Cast to usize first, then comment with the reason for the truncation
21 fn fn1() -> i16 {
22     1
23 };
24 let fn_ptr = fn1 as usize;
25 let fn_ptr_truncated = fn_ptr as i32;
26 ```