summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/fn_to_numeric_cast_any.txt
blob: ee3c33d237255999c8332a1722c1a2e2248527d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
### What it does
Checks for casts of a function pointer to any integer type.

### Why is this bad?
Casting a function pointer to an integer can have surprising results and can occur
accidentally if parentheses are omitted from a function call. If you aren't doing anything
low-level with function pointers then you can opt-out of casting functions to integers in
order to avoid mistakes. Alternatively, you can use this lint to audit all uses of function
pointer casts in your code.

### Example
```
// fn1 is cast as `usize`
fn fn1() -> u16 {
    1
};
let _ = fn1 as usize;
```

Use instead:
```
// maybe you intended to call the function?
fn fn2() -> u16 {
    1
};
let _ = fn2() as usize;

// or

// maybe you intended to cast it to a function type?
fn fn3() -> u16 {
    1
}
let _ = fn3 as fn() -> u16;
```