]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/result_large_err.rs
Rollup merge of #100462 - zohnannor:master, r=thomcc
[rust.git] / src / tools / clippy / tests / ui / result_large_err.rs
1 #![warn(clippy::result_large_err)]
2 #![allow(clippy::large_enum_variant)]
3
4 pub fn small_err() -> Result<(), u128> {
5     Ok(())
6 }
7
8 pub fn large_err() -> Result<(), [u8; 512]> {
9     Ok(())
10 }
11
12 pub struct FullyDefinedLargeError {
13     _foo: u128,
14     _bar: [u8; 100],
15     _foobar: [u8; 120],
16 }
17
18 impl FullyDefinedLargeError {
19     pub fn ret() -> Result<(), Self> {
20         Ok(())
21     }
22 }
23
24 pub fn struct_error() -> Result<(), FullyDefinedLargeError> {
25     Ok(())
26 }
27
28 type Fdlr<T> = std::result::Result<T, FullyDefinedLargeError>;
29 pub fn large_err_via_type_alias<T>(x: T) -> Fdlr<T> {
30     Ok(x)
31 }
32
33 pub fn param_small_error<R>() -> Result<(), (R, u128)> {
34     Ok(())
35 }
36
37 pub fn param_large_error<R>() -> Result<(), (u128, R, FullyDefinedLargeError)> {
38     Ok(())
39 }
40
41 pub enum LargeErrorVariants<T> {
42     _Small(u8),
43     _Omg([u8; 512]),
44     _Param(T),
45 }
46
47 impl LargeErrorVariants<()> {
48     pub fn large_enum_error() -> Result<(), Self> {
49         Ok(())
50     }
51 }
52
53 trait TraitForcesLargeError {
54     fn large_error() -> Result<(), [u8; 512]> {
55         Ok(())
56     }
57 }
58
59 struct TraitImpl;
60
61 impl TraitForcesLargeError for TraitImpl {
62     // Should not lint
63     fn large_error() -> Result<(), [u8; 512]> {
64         Ok(())
65     }
66 }
67
68 pub union FullyDefinedUnionError {
69     _maybe: u8,
70     _or_even: [[u8; 16]; 32],
71 }
72
73 pub fn large_union_err() -> Result<(), FullyDefinedUnionError> {
74     Ok(())
75 }
76
77 pub union UnionError<T: Copy> {
78     _maybe: T,
79     _or_perhaps_even: (T, [u8; 512]),
80 }
81
82 pub fn param_large_union<T: Copy>() -> Result<(), UnionError<T>> {
83     Ok(())
84 }
85
86 pub struct ArrayError<T, U> {
87     _large_array: [T; 32],
88     _other_stuff: U,
89 }
90
91 pub fn array_error_subst<U>() -> Result<(), ArrayError<i32, U>> {
92     Ok(())
93 }
94
95 pub fn array_error<T, U>() -> Result<(), ArrayError<(i32, T), U>> {
96     Ok(())
97 }
98
99 fn main() {}