Skip to content

Commit c257f09

Browse files
committed
Auto merge of rust-lang#9115 - Alexendoo:new-with-const-generics, r=llogiq
`new_without_default`: ignore const generics/lifetime params on `fn new` Fixes rust-lang#9113 No longer lints if `fn new` has any params changelog: [`new_without_default`]: no longer lints const generics and lifetime params on `fn new`
2 parents b15f06e + fec4593 commit c257f09

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

clippy_lints/src/new_without_default.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,9 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
8888
// shouldn't be implemented when it is hidden in docs
8989
return;
9090
}
91-
if impl_item
92-
.generics
93-
.params
94-
.iter()
95-
.any(|gen| matches!(gen.kind, hir::GenericParamKind::Type { .. }))
96-
{
97-
// when the result of `new()` depends on a type parameter we should not require
98-
// an
99-
// impl of `Default`
91+
if !impl_item.generics.params.is_empty() {
92+
// when the result of `new()` depends on a parameter we should not require
93+
// an impl of `Default`
10094
return;
10195
}
10296
if_chain! {

tests/ui/new_without_default.rs

+14
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,17 @@ impl DocHidden {
212212
}
213213

214214
fn main() {}
215+
216+
pub struct IgnoreConstGenericNew(usize);
217+
impl IgnoreConstGenericNew {
218+
pub fn new<const N: usize>() -> Self {
219+
Self(N)
220+
}
221+
}
222+
223+
pub struct IgnoreLifetimeNew;
224+
impl IgnoreLifetimeNew {
225+
pub fn new<'a>() -> Self {
226+
Self
227+
}
228+
}

0 commit comments

Comments
 (0)