about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2023-08-01 20:28:10 +0200
committerSamuel Tardieu <sam@rfc1149.net>2023-08-11 21:16:56 +0200
commitf9b22e7b84df2bfef723fbb456349d1d5948d611 (patch)
treebd4f6c084b54eaf5b35baba1bcf486775016b32b
parent621e76d2528e0872926305686041f6a935028db8 (diff)
downloadrust-f9b22e7b84df2bfef723fbb456349d1d5948d611.tar.gz
rust-f9b22e7b84df2bfef723fbb456349d1d5948d611.zip
[new_without_default]: make the suggestion machine-applicable
Now that generics and lifetimes are output as expected, the lint
should be applicable.
-rw-r--r--clippy_lints/src/new_without_default.rs2
-rw-r--r--tests/ui/new_without_default.fixed28
2 files changed, 28 insertions, 2 deletions
diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs
index 6900502e8e1..f7f9dccfbce 100644
--- a/clippy_lints/src/new_without_default.rs
+++ b/clippy_lints/src/new_without_default.rs
@@ -155,7 +155,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
                                                 &generics_sugg,
                                                 &where_clause_sugg
                                             ),
-                                            Applicability::MaybeIncorrect,
+                                            Applicability::MachineApplicable,
                                         );
                                     },
                                 );
diff --git a/tests/ui/new_without_default.fixed b/tests/ui/new_without_default.fixed
index 0c4283ad0c1..56359a4cbc3 100644
--- a/tests/ui/new_without_default.fixed
+++ b/tests/ui/new_without_default.fixed
@@ -102,7 +102,6 @@ impl<'c> LtKo<'c> {
     pub fn new() -> LtKo<'c> {
         unimplemented!()
     }
-    // FIXME: that suggestion is missing lifetimes
 }
 
 struct Private;
@@ -273,3 +272,30 @@ impl IgnoreLifetimeNew {
         Self
     }
 }
+
+// From issue #11267
+
+pub struct MyStruct<K, V>
+where
+    K: std::hash::Hash + Eq + PartialEq,
+{
+    _kv: Option<(K, V)>,
+}
+
+impl<K, V> Default for MyStruct<K, V>
+where
+    K: std::hash::Hash + Eq + PartialEq,
+ {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
+impl<K, V> MyStruct<K, V>
+where
+    K: std::hash::Hash + Eq + PartialEq,
+{
+    pub fn new() -> Self {
+        Self { _kv: None }
+    }
+}