File tree Expand file tree Collapse file tree 8 files changed +94
-29
lines changed
src/tools/clippy/tests/ui Expand file tree Collapse file tree 8 files changed +94
-29
lines changed Original file line number Diff line number Diff line change 1- #![allow(dead_code)]
1+ #![allow(dead_code, default_could_be_derived )]
22
33use std::collections::HashMap;
44
Original file line number Diff line number Diff line change 1- #![ allow( dead_code) ]
1+ #![ allow( dead_code, default_could_be_derived ) ]
22
33use std:: collections:: HashMap ;
44
Original file line number Diff line number Diff line change @@ -38,19 +38,14 @@ impl Bar {
3838 }
3939}
4040
41- pub struct Ok;
41+ #[derive(Default)] pub struct Ok;
4242
4343impl Ok {
4444 pub fn new() -> Self {
4545 Ok
4646 }
4747}
4848
49- impl Default for Ok {
50- fn default() -> Self {
51- Ok
52- }
53- }
5449
5550pub struct Params;
5651
Original file line number Diff line number Diff line change @@ -166,5 +166,23 @@ LL + }
166166LL + }
167167 |
168168
169- error: aborting due to 9 previous errors
169+ error: `impl Default` that could be derived
170+ --> tests/ui/new_without_default.rs:37:1
171+ |
172+ LL | / impl Default for Ok {
173+ LL | | fn default() -> Self {
174+ LL | | Ok
175+ | | -- this type has no fields, so it's trivially derivable
176+ LL | | }
177+ LL | | }
178+ | |_^
179+ |
180+ = note: `-D default-could-be-derived` implied by `-D warnings`
181+ = help: to override `-D warnings` add `#[allow(default_could_be_derived)]`
182+ help: you don't need to manually `impl Default`, you can derive it
183+ |
184+ LL ~ #[derive(Default)] pub struct Ok;
185+ |
186+
187+ error: aborting due to 10 previous errors
170188
Original file line number Diff line number Diff line change @@ -21,18 +21,14 @@ fn or_fun_call() {
2121 }
2222 }
2323
24- struct FakeDefault;
24+ #[derive(Default)] struct FakeDefault;
2525 impl FakeDefault {
2626 fn default() -> Self {
2727 FakeDefault
2828 }
2929 }
3030
31- impl Default for FakeDefault {
32- fn default() -> Self {
33- FakeDefault
34- }
35- }
31+
3632
3733 enum Enum {
3834 A(i32),
@@ -268,18 +264,14 @@ mod lazy {
268264 }
269265 }
270266
271- struct FakeDefault;
267+ #[derive(Default)] struct FakeDefault;
272268 impl FakeDefault {
273269 fn default() -> Self {
274270 FakeDefault
275271 }
276272 }
277273
278- impl Default for FakeDefault {
279- fn default() -> Self {
280- FakeDefault
281- }
282- }
274+
283275
284276 let with_new = Some(vec![1]);
285277 with_new.unwrap_or_default();
Original file line number Diff line number Diff line change @@ -244,5 +244,47 @@ error: function call inside of `unwrap_or`
244244LL | let _ = opt_foo.unwrap_or(Foo { val: String::default() });
245245 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| Foo { val: String::default() })`
246246
247- error: aborting due to 38 previous errors
247+ error: `impl Default` that could be derived
248+ --> tests/ui/or_fun_call.rs:31:5
249+ |
250+ LL | / impl Default for FakeDefault {
251+ LL | | fn default() -> Self {
252+ LL | | FakeDefault
253+ | | ----------- this type has no fields, so it's trivially derivable
254+ LL | | }
255+ LL | | }
256+ | |_____^
257+ |
258+ = note: `-D default-could-be-derived` implied by `-D warnings`
259+ = help: to override `-D warnings` add `#[allow(default_could_be_derived)]`
260+ help: you don't need to manually `impl Default`, you can derive it
261+ |
262+ LL ~ #[derive(Default)] struct FakeDefault;
263+ LL | impl FakeDefault {
264+ ...
265+ LL |
266+ LL ~
267+ |
268+
269+ error: `impl Default` that could be derived
270+ --> tests/ui/or_fun_call.rs:278:9
271+ |
272+ LL | / impl Default for FakeDefault {
273+ LL | | fn default() -> Self {
274+ LL | | FakeDefault
275+ | | ----------- this type has no fields, so it's trivially derivable
276+ LL | | }
277+ LL | | }
278+ | |_________^
279+ |
280+ help: you don't need to manually `impl Default`, you can derive it
281+ |
282+ LL ~ #[derive(Default)] struct FakeDefault;
283+ LL | impl FakeDefault {
284+ ...
285+ LL |
286+ LL ~
287+ |
288+
289+ error: aborting due to 40 previous errors
248290
Original file line number Diff line number Diff line change @@ -17,19 +17,15 @@ fn unwrap_or_else_default() {
1717 }
1818 }
1919
20- struct HasDefaultAndDuplicate;
20+ #[derive(Default)] struct HasDefaultAndDuplicate;
2121
2222 impl HasDefaultAndDuplicate {
2323 fn default() -> Self {
2424 HasDefaultAndDuplicate
2525 }
2626 }
2727
28- impl Default for HasDefaultAndDuplicate {
29- fn default() -> Self {
30- HasDefaultAndDuplicate
31- }
32- }
28+
3329
3430 enum Enum {
3531 A(),
Original file line number Diff line number Diff line change @@ -97,5 +97,27 @@ error: use of `or_insert_with` to construct default value
9797LL | let _ = inner_map.entry(0).or_insert_with(Default::default);
9898 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()`
9999
100- error: aborting due to 16 previous errors
100+ error: `impl Default` that could be derived
101+ --> tests/ui/unwrap_or_else_default.rs:28:5
102+ |
103+ LL | / impl Default for HasDefaultAndDuplicate {
104+ LL | | fn default() -> Self {
105+ LL | | HasDefaultAndDuplicate
106+ | | ---------------------- this type has no fields, so it's trivially derivable
107+ LL | | }
108+ LL | | }
109+ | |_____^
110+ |
111+ = note: `-D default-could-be-derived` implied by `-D warnings`
112+ = help: to override `-D warnings` add `#[allow(default_could_be_derived)]`
113+ help: you don't need to manually `impl Default`, you can derive it
114+ |
115+ LL ~ #[derive(Default)] struct HasDefaultAndDuplicate;
116+ LL |
117+ ...
118+ LL |
119+ LL ~
120+ |
121+
122+ error: aborting due to 17 previous errors
101123
You can’t perform that action at this time.
0 commit comments