diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 653b1a8a05f6..d3ec14962f8e 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -76,10 +76,6 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { if let hir::ImplItemKind::Fn(ref sig, _) = impl_item.kind { let name = impl_item.ident.name; let id = impl_item.owner_id; - if sig.header.constness == hir::Constness::Const { - // can't be implemented by default - return; - } if sig.header.unsafety == hir::Unsafety::Unsafe { // can't be implemented for unsafe new return; diff --git a/tests/ui/new_without_default.rs b/tests/ui/new_without_default.rs index 7803418cb047..f9501711a96f 100644 --- a/tests/ui/new_without_default.rs +++ b/tests/ui/new_without_default.rs @@ -111,12 +111,12 @@ impl PrivateItem { } // We don't lint private items on public structs } -struct Const; +pub struct Const; impl Const { pub const fn new() -> Const { Const - } // const fns can't be implemented via Default + } // While Default is not const, it can still call const functions, so we should lint this } pub struct IgnoreGenericNew; diff --git a/tests/ui/new_without_default.stderr b/tests/ui/new_without_default.stderr index 583dd327d6a5..b1acce88b1d7 100644 --- a/tests/ui/new_without_default.stderr +++ b/tests/ui/new_without_default.stderr @@ -50,6 +50,23 @@ LL + } LL + } | +error: you should consider adding a `Default` implementation for `Const` + --> $DIR/new_without_default.rs:117:5 + | +LL | / pub const fn new() -> Const { +LL | | Const +LL | | } // While Default is not const, it can still call const functions, so we should lint this + | |_____^ + | +help: try adding this + | +LL + impl Default for Const { +LL + fn default() -> Self { +LL + Self::new() +LL + } +LL + } + | + error: you should consider adding a `Default` implementation for `NewNotEqualToDerive` --> $DIR/new_without_default.rs:177:5 | @@ -120,5 +137,5 @@ LL + LL ~ impl Foo { | -error: aborting due to 7 previous errors +error: aborting due to 8 previous errors