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