]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/result_large_err.rs
Rollup merge of #105174 - chenyukang:yukang/fix-105028-unused, r=eholk
[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 enum MultipleLargeVariants {
54     _Biggest([u8; 1024]),
55     _AlsoBig([u8; 512]),
56     _Ok(usize),
57 }
58
59 impl MultipleLargeVariants {
60     fn large_enum_error() -> Result<(), Self> {
61         Ok(())
62     }
63 }
64
65 trait TraitForcesLargeError {
66     fn large_error() -> Result<(), [u8; 512]> {
67         Ok(())
68     }
69 }
70
71 struct TraitImpl;
72
73 impl TraitForcesLargeError for TraitImpl {
74     // Should not lint
75     fn large_error() -> Result<(), [u8; 512]> {
76         Ok(())
77     }
78 }
79
80 pub union FullyDefinedUnionError {
81     _maybe: u8,
82     _or_even: [[u8; 16]; 32],
83 }
84
85 pub fn large_union_err() -> Result<(), FullyDefinedUnionError> {
86     Ok(())
87 }
88
89 pub union UnionError<T: Copy> {
90     _maybe: T,
91     _or_perhaps_even: (T, [u8; 512]),
92 }
93
94 pub fn param_large_union<T: Copy>() -> Result<(), UnionError<T>> {
95     Ok(())
96 }
97
98 pub struct ArrayError<T, U> {
99     _large_array: [T; 32],
100     _other_stuff: U,
101 }
102
103 pub fn array_error_subst<U>() -> Result<(), ArrayError<i32, U>> {
104     Ok(())
105 }
106
107 pub fn array_error<T, U>() -> Result<(), ArrayError<(i32, T), U>> {
108     Ok(())
109 }
110
111 // Issue #10005
112 enum Empty {}
113 fn _empty_error() -> Result<(), Empty> {
114     Ok(())
115 }
116
117 fn main() {}