summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/result_large_err.txt
blob: e5fab3c5cfcfabfe813d427c01113ec5936b7a34 (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
36
### What it does
Checks for functions that return `Result` with an unusually large
`Err`-variant.

### Why is this bad?
A `Result` is at least as large as the `Err`-variant. While we
expect that variant to be seldomly used, the compiler needs to reserve
and move that much memory every single time.

### Known problems
The size determined by Clippy is platform-dependent.

### Examples
```
pub enum ParseError {
    UnparsedBytes([u8; 512]),
    UnexpectedEof,
}

// The `Result` has at least 512 bytes, even in the `Ok`-case
pub fn parse() -> Result<(), ParseError> {
    Ok(())
}
```
should be
```
pub enum ParseError {
    UnparsedBytes(Box<[u8; 512]>),
    UnexpectedEof,
}

// The `Result` is slightly larger than a pointer
pub fn parse() -> Result<(), ParseError> {
    Ok(())
}
```