]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/src/docs/fn_to_numeric_cast_any.txt
New upstream version 1.66.0+dfsg1
[rustc.git] / src / tools / clippy / src / docs / fn_to_numeric_cast_any.txt
CommitLineData
f2b60f7d
FG
1### What it does
2Checks for casts of a function pointer to any integer type.
3
4### Why is this bad?
5Casting a function pointer to an integer can have surprising results and can occur
6accidentally if parentheses are omitted from a function call. If you aren't doing anything
7low-level with function pointers then you can opt-out of casting functions to integers in
8order to avoid mistakes. Alternatively, you can use this lint to audit all uses of function
9pointer casts in your code.
10
11### Example
12```
13// fn1 is cast as `usize`
14fn fn1() -> u16 {
15 1
16};
17let _ = fn1 as usize;
18```
19
20Use instead:
21```
22// maybe you intended to call the function?
23fn fn2() -> u16 {
24 1
25};
26let _ = fn2() as usize;
27
28// or
29
30// maybe you intended to cast it to a function type?
31fn fn3() -> u16 {
32 1
33}
34let _ = fn3 as fn() -> u16;
35```