This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +25
-9
lines changed Expand file tree Collapse file tree 3 files changed +25
-9
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ use rustc_span::sym;
13
13
14
14
declare_clippy_lint ! {
15
15
/// ### What it does
16
- /// Checks for types with a `fn new() -> Self` method and no
16
+ /// Checks for public types with a `pub fn new() -> Self` method and no
17
17
/// implementation of
18
18
/// [`Default`](https://doc.rust-lang.org/std/default/trait.Default.html).
19
19
///
@@ -24,10 +24,10 @@ declare_clippy_lint! {
24
24
///
25
25
/// ### Example
26
26
/// ```ignore
27
- /// struct Foo(Bar);
27
+ /// pub struct Foo(Bar);
28
28
///
29
29
/// impl Foo {
30
- /// fn new() -> Self {
30
+ /// pub fn new() -> Self {
31
31
/// Foo(Bar::new())
32
32
/// }
33
33
/// }
@@ -36,7 +36,7 @@ declare_clippy_lint! {
36
36
/// To fix the lint, add a `Default` implementation that delegates to `new`:
37
37
///
38
38
/// ```ignore
39
- /// struct Foo(Bar);
39
+ /// pub struct Foo(Bar);
40
40
///
41
41
/// impl Default for Foo {
42
42
/// fn default() -> Self {
@@ -47,7 +47,7 @@ declare_clippy_lint! {
47
47
#[ clippy:: version = "pre 1.29.0" ]
48
48
pub NEW_WITHOUT_DEFAULT ,
49
49
style,
50
- "`fn new() -> Self` method without `Default` implementation"
50
+ "`pub fn new() -> Self` method without `Default` implementation"
51
51
}
52
52
53
53
#[ derive( Clone , Default ) ]
Original file line number Diff line number Diff line change @@ -90,6 +90,22 @@ impl Private {
90
90
} // We don't lint private items
91
91
}
92
92
93
+ struct PrivateStruct ;
94
+
95
+ impl PrivateStruct {
96
+ pub fn new ( ) -> PrivateStruct {
97
+ unimplemented ! ( )
98
+ } // We don't lint public items on private structs
99
+ }
100
+
101
+ pub struct PrivateItem ;
102
+
103
+ impl PrivateItem {
104
+ fn new ( ) -> PrivateItem {
105
+ unimplemented ! ( )
106
+ } // We don't lint private items on public structs
107
+ }
108
+
93
109
struct Const ;
94
110
95
111
impl Const {
Original file line number Diff line number Diff line change 51
51
|
52
52
53
53
error: you should consider adding a `Default` implementation for `NewNotEqualToDerive`
54
- --> $DIR/new_without_default.rs:156 :5
54
+ --> $DIR/new_without_default.rs:172 :5
55
55
|
56
56
LL | / pub fn new() -> Self {
57
57
LL | | NewNotEqualToDerive { foo: 1 }
68
68
|
69
69
70
70
error: you should consider adding a `Default` implementation for `FooGenerics<T>`
71
- --> $DIR/new_without_default.rs:164 :5
71
+ --> $DIR/new_without_default.rs:180 :5
72
72
|
73
73
LL | / pub fn new() -> Self {
74
74
LL | | Self(Default::default())
85
85
|
86
86
87
87
error: you should consider adding a `Default` implementation for `BarGenerics<T>`
88
- --> $DIR/new_without_default.rs:171 :5
88
+ --> $DIR/new_without_default.rs:187 :5
89
89
|
90
90
LL | / pub fn new() -> Self {
91
91
LL | | Self(Default::default())
@@ -102,7 +102,7 @@ LL + }
102
102
|
103
103
104
104
error: you should consider adding a `Default` implementation for `Foo<T>`
105
- --> $DIR/new_without_default.rs:182 :9
105
+ --> $DIR/new_without_default.rs:198 :9
106
106
|
107
107
LL | / pub fn new() -> Self {
108
108
LL | | todo!()
You can’t perform that action at this time.
0 commit comments