]> git.lizzy.rs Git - rust.git/blob - src/docs/result_large_err.txt
[Arithmetic] Consider literals
[rust.git] / src / docs / result_large_err.txt
1 ### What it does
2 Checks for functions that return `Result` with an unusually large
3 `Err`-variant.
4
5 ### Why is this bad?
6 A `Result` is at least as large as the `Err`-variant. While we
7 expect that variant to be seldomly used, the compiler needs to reserve
8 and move that much memory every single time.
9
10 ### Known problems
11 The size determined by Clippy is platform-dependent.
12
13 ### Examples
14 ```
15 pub enum ParseError {
16     UnparsedBytes([u8; 512]),
17     UnexpectedEof,
18 }
19
20 // The `Result` has at least 512 bytes, even in the `Ok`-case
21 pub fn parse() -> Result<(), ParseError> {
22     Ok(())
23 }
24 ```
25 should be
26 ```
27 pub enum ParseError {
28     UnparsedBytes(Box<[u8; 512]>),
29     UnexpectedEof,
30 }
31
32 // The `Result` is slightly larger than a pointer
33 pub fn parse() -> Result<(), ParseError> {
34     Ok(())
35 }
36 ```