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