From f9b22e7b84df2bfef723fbb456349d1d5948d611 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Tue, 1 Aug 2023 20:28:10 +0200 Subject: [PATCH] [new_without_default]: make the suggestion machine-applicable Now that generics and lifetimes are output as expected, the lint should be applicable. --- clippy_lints/src/new_without_default.rs | 2 +- tests/ui/new_without_default.fixed | 28 ++++++++++++++++++++++++- 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 6900502e8e11..f7f9dccfbceb 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 0c4283ad0c12..56359a4cbc3c 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 +where + K: std::hash::Hash + Eq + PartialEq, +{ + _kv: Option<(K, V)>, +} + +impl Default for MyStruct +where + K: std::hash::Hash + Eq + PartialEq, + { + fn default() -> Self { + Self::new() + } +} + +impl MyStruct +where + K: std::hash::Hash + Eq + PartialEq, +{ + pub fn new() -> Self { + Self { _kv: None } + } +}