Skip to content

Commit

Permalink
Auto merge of rust-lang#9115 - Alexendoo:new-with-const-generics, r=l…
Browse files Browse the repository at this point in the history
…logiq

`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`
  • Loading branch information
bors committed Jul 4, 2022
2 parents b15f06e + fec4593 commit c257f09
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
12 changes: 3 additions & 9 deletions clippy_lints/src/new_without_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,9 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
// shouldn't be implemented when it is hidden in docs
return;
}
if impl_item
.generics
.params
.iter()
.any(|gen| matches!(gen.kind, hir::GenericParamKind::Type { .. }))
{
// when the result of `new()` depends on a type parameter we should not require
// an
// impl of `Default`
if !impl_item.generics.params.is_empty() {
// when the result of `new()` depends on a parameter we should not require
// an impl of `Default`
return;
}
if_chain! {
Expand Down
14 changes: 14 additions & 0 deletions tests/ui/new_without_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,17 @@ impl DocHidden {
}

fn main() {}

pub struct IgnoreConstGenericNew(usize);
impl IgnoreConstGenericNew {
pub fn new<const N: usize>() -> Self {
Self(N)
}
}

pub struct IgnoreLifetimeNew;
impl IgnoreLifetimeNew {
pub fn new<'a>() -> Self {
Self
}
}

0 comments on commit c257f09

Please sign in to comment.