about summary refs log tree commit diff
diff options
context:
space:
mode:
authornsunderland1 <sunderland.nicholas@protonmail.com>2022-02-13 17:07:14 -0800
committernsunderland1 <sunderland.nicholas@protonmail.com>2022-02-13 17:07:14 -0800
commit78c2e0bfe98bc0490bd97a319104e2bd811c3c91 (patch)
tree236e4922c775da0cac5ff9639c4bc2b452f97c13
parentc37d6eed067eb6fb4c126b4ac3c09499483071ec (diff)
downloadrust-78c2e0bfe98bc0490bd97a319104e2bd811c3c91.tar.gz
rust-78c2e0bfe98bc0490bd97a319104e2bd811c3c91.zip
Document `pub` requirement for `new_without_default` lint
-rw-r--r--clippy_lints/src/new_without_default.rs10
-rw-r--r--tests/ui/new_without_default.rs16
-rw-r--r--tests/ui/new_without_default.stderr8
3 files changed, 25 insertions, 9 deletions
diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs
index f86af7a7bb6..47121ad84f2 100644
--- a/clippy_lints/src/new_without_default.rs
+++ b/clippy_lints/src/new_without_default.rs
@@ -13,7 +13,7 @@ use rustc_span::sym;
 
 declare_clippy_lint! {
     /// ### What it does
-    /// Checks for types with a `fn new() -> Self` method and no
+    /// Checks for public types with a `pub fn new() -> Self` method and no
     /// implementation of
     /// [`Default`](https://doc.rust-lang.org/std/default/trait.Default.html).
     ///
@@ -24,10 +24,10 @@ declare_clippy_lint! {
     ///
     /// ### Example
     /// ```ignore
-    /// struct Foo(Bar);
+    /// pub struct Foo(Bar);
     ///
     /// impl Foo {
-    ///     fn new() -> Self {
+    ///     pub fn new() -> Self {
     ///         Foo(Bar::new())
     ///     }
     /// }
@@ -36,7 +36,7 @@ declare_clippy_lint! {
     /// To fix the lint, add a `Default` implementation that delegates to `new`:
     ///
     /// ```ignore
-    /// struct Foo(Bar);
+    /// pub struct Foo(Bar);
     ///
     /// impl Default for Foo {
     ///     fn default() -> Self {
@@ -47,7 +47,7 @@ declare_clippy_lint! {
     #[clippy::version = "pre 1.29.0"]
     pub NEW_WITHOUT_DEFAULT,
     style,
-    "`fn new() -> Self` method without `Default` implementation"
+    "`pub fn new() -> Self` method without `Default` implementation"
 }
 
 #[derive(Clone, Default)]
diff --git a/tests/ui/new_without_default.rs b/tests/ui/new_without_default.rs
index 4b2e7444dcf..c76e3b42438 100644
--- a/tests/ui/new_without_default.rs
+++ b/tests/ui/new_without_default.rs
@@ -90,6 +90,22 @@ impl Private {
     } // We don't lint private items
 }
 
+struct PrivateStruct;
+
+impl PrivateStruct {
+    pub fn new() -> PrivateStruct {
+        unimplemented!()
+    } // We don't lint public items on private structs
+}
+
+pub struct PrivateItem;
+
+impl PrivateItem {
+    fn new() -> PrivateItem {
+        unimplemented!()
+    } // We don't lint private items on public structs
+}
+
 struct Const;
 
 impl Const {
diff --git a/tests/ui/new_without_default.stderr b/tests/ui/new_without_default.stderr
index 14ddb66f232..19572dfe8b0 100644
--- a/tests/ui/new_without_default.stderr
+++ b/tests/ui/new_without_default.stderr
@@ -51,7 +51,7 @@ LL + }
    |
 
 error: you should consider adding a `Default` implementation for `NewNotEqualToDerive`
-  --> $DIR/new_without_default.rs:156:5
+  --> $DIR/new_without_default.rs:172:5
    |
 LL | /     pub fn new() -> Self {
 LL | |         NewNotEqualToDerive { foo: 1 }
@@ -68,7 +68,7 @@ LL + }
    |
 
 error: you should consider adding a `Default` implementation for `FooGenerics<T>`
-  --> $DIR/new_without_default.rs:164:5
+  --> $DIR/new_without_default.rs:180:5
    |
 LL | /     pub fn new() -> Self {
 LL | |         Self(Default::default())
@@ -85,7 +85,7 @@ LL + }
    |
 
 error: you should consider adding a `Default` implementation for `BarGenerics<T>`
-  --> $DIR/new_without_default.rs:171:5
+  --> $DIR/new_without_default.rs:187:5
    |
 LL | /     pub fn new() -> Self {
 LL | |         Self(Default::default())
@@ -102,7 +102,7 @@ LL + }
    |
 
 error: you should consider adding a `Default` implementation for `Foo<T>`
-  --> $DIR/new_without_default.rs:182:9
+  --> $DIR/new_without_default.rs:198:9
    |
 LL | /         pub fn new() -> Self {
 LL | |             todo!()