]>
Commit | Line | Data |
---|---|---|
f20569fa XL |
1 | #![feature(const_fn)] |
2 | #![allow(dead_code, clippy::missing_safety_doc)] | |
3 | #![warn(clippy::new_without_default)] | |
4 | ||
5 | pub struct Foo; | |
6 | ||
7 | impl Foo { | |
8 | pub fn new() -> Foo { | |
9 | Foo | |
10 | } | |
11 | } | |
12 | ||
13 | pub struct Bar; | |
14 | ||
15 | impl Bar { | |
16 | pub fn new() -> Self { | |
17 | Bar | |
18 | } | |
19 | } | |
20 | ||
21 | pub struct Ok; | |
22 | ||
23 | impl Ok { | |
24 | pub fn new() -> Self { | |
25 | Ok | |
26 | } | |
27 | } | |
28 | ||
29 | impl Default for Ok { | |
30 | fn default() -> Self { | |
31 | Ok | |
32 | } | |
33 | } | |
34 | ||
35 | pub struct Params; | |
36 | ||
37 | impl Params { | |
38 | pub fn new(_: u32) -> Self { | |
39 | Params | |
40 | } | |
41 | } | |
42 | ||
43 | pub struct GenericsOk<T> { | |
44 | bar: T, | |
45 | } | |
46 | ||
47 | impl<U> Default for GenericsOk<U> { | |
48 | fn default() -> Self { | |
49 | unimplemented!(); | |
50 | } | |
51 | } | |
52 | ||
53 | impl<'c, V> GenericsOk<V> { | |
54 | pub fn new() -> GenericsOk<V> { | |
55 | unimplemented!() | |
56 | } | |
57 | } | |
58 | ||
59 | pub struct LtOk<'a> { | |
60 | foo: &'a bool, | |
61 | } | |
62 | ||
63 | impl<'b> Default for LtOk<'b> { | |
64 | fn default() -> Self { | |
65 | unimplemented!(); | |
66 | } | |
67 | } | |
68 | ||
69 | impl<'c> LtOk<'c> { | |
70 | pub fn new() -> LtOk<'c> { | |
71 | unimplemented!() | |
72 | } | |
73 | } | |
74 | ||
75 | pub struct LtKo<'a> { | |
76 | foo: &'a bool, | |
77 | } | |
78 | ||
79 | impl<'c> LtKo<'c> { | |
80 | pub fn new() -> LtKo<'c> { | |
81 | unimplemented!() | |
82 | } | |
83 | // FIXME: that suggestion is missing lifetimes | |
84 | } | |
85 | ||
86 | struct Private; | |
87 | ||
88 | impl Private { | |
89 | fn new() -> Private { | |
90 | unimplemented!() | |
91 | } // We don't lint private items | |
92 | } | |
93 | ||
94 | struct Const; | |
95 | ||
96 | impl Const { | |
97 | pub const fn new() -> Const { | |
98 | Const | |
99 | } // const fns can't be implemented via Default | |
100 | } | |
101 | ||
102 | pub struct IgnoreGenericNew; | |
103 | ||
104 | impl IgnoreGenericNew { | |
105 | pub fn new<T>() -> Self { | |
106 | IgnoreGenericNew | |
107 | } // the derived Default does not make sense here as the result depends on T | |
108 | } | |
109 | ||
110 | pub trait TraitWithNew: Sized { | |
111 | fn new() -> Self { | |
112 | panic!() | |
113 | } | |
114 | } | |
115 | ||
116 | pub struct IgnoreUnsafeNew; | |
117 | ||
118 | impl IgnoreUnsafeNew { | |
119 | pub unsafe fn new() -> Self { | |
120 | IgnoreUnsafeNew | |
121 | } | |
122 | } | |
123 | ||
124 | #[derive(Default)] | |
125 | pub struct OptionRefWrapper<'a, T>(Option<&'a T>); | |
126 | ||
127 | impl<'a, T> OptionRefWrapper<'a, T> { | |
128 | pub fn new() -> Self { | |
129 | OptionRefWrapper(None) | |
130 | } | |
131 | } | |
132 | ||
133 | pub struct Allow(Foo); | |
134 | ||
135 | impl Allow { | |
136 | #[allow(clippy::new_without_default)] | |
137 | pub fn new() -> Self { | |
138 | unimplemented!() | |
139 | } | |
140 | } | |
141 | ||
142 | pub struct AllowDerive; | |
143 | ||
144 | impl AllowDerive { | |
145 | #[allow(clippy::new_without_default)] | |
146 | pub fn new() -> Self { | |
147 | unimplemented!() | |
148 | } | |
149 | } | |
150 | ||
151 | pub struct NewNotEqualToDerive { | |
152 | foo: i32, | |
153 | } | |
154 | ||
155 | impl NewNotEqualToDerive { | |
156 | // This `new` implementation is not equal to a derived `Default`, so do not suggest deriving. | |
157 | pub fn new() -> Self { | |
158 | NewNotEqualToDerive { foo: 1 } | |
159 | } | |
160 | } | |
161 | ||
162 | fn main() {} |