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;
1313
1414declare_clippy_lint ! {
1515 /// ### 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
1717 /// implementation of
1818 /// [`Default`](https://doc.rust-lang.org/std/default/trait.Default.html).
1919 ///
@@ -24,10 +24,10 @@ declare_clippy_lint! {
2424 ///
2525 /// ### Example
2626 /// ```ignore
27- /// struct Foo(Bar);
27+ /// pub struct Foo(Bar);
2828 ///
2929 /// impl Foo {
30- /// fn new() -> Self {
30+ /// pub fn new() -> Self {
3131 /// Foo(Bar::new())
3232 /// }
3333 /// }
@@ -36,7 +36,7 @@ declare_clippy_lint! {
3636 /// To fix the lint, add a `Default` implementation that delegates to `new`:
3737 ///
3838 /// ```ignore
39- /// struct Foo(Bar);
39+ /// pub struct Foo(Bar);
4040 ///
4141 /// impl Default for Foo {
4242 /// fn default() -> Self {
@@ -47,7 +47,7 @@ declare_clippy_lint! {
4747 #[ clippy:: version = "pre 1.29.0" ]
4848 pub NEW_WITHOUT_DEFAULT ,
4949 style,
50- "`fn new() -> Self` method without `Default` implementation"
50+ "`pub fn new() -> Self` method without `Default` implementation"
5151}
5252
5353#[ derive( Clone , Default ) ]
Original file line number Diff line number Diff line change @@ -90,6 +90,22 @@ impl Private {
9090 } // We don't lint private items
9191}
9292
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+
93109struct Const ;
94110
95111impl Const {
Original file line number Diff line number Diff line change 5151 |
5252
5353error: 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
5555 |
5656LL | / pub fn new() -> Self {
5757LL | | NewNotEqualToDerive { foo: 1 }
6868 |
6969
7070error: 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
7272 |
7373LL | / pub fn new() -> Self {
7474LL | | Self(Default::default())
8585 |
8686
8787error: 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
8989 |
9090LL | / pub fn new() -> Self {
9191LL | | Self(Default::default())
@@ -102,7 +102,7 @@ LL + }
102102 |
103103
104104error: 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
106106 |
107107LL | / pub fn new() -> Self {
108108LL | | todo!()
You can’t perform that action at this time.
0 commit comments