diff options
| author | Alex Macleod <alex@macleod.io> | 2022-07-04 14:03:11 +0000 |
|---|---|---|
| committer | Alex Macleod <alex@macleod.io> | 2022-07-04 14:03:11 +0000 |
| commit | fec45930823c77acd91bfeec153b323bacfab099 (patch) | |
| tree | d4629ea57a4589ff017c40c3a9c751541ddafe6a | |
| parent | b15f06e74f1195228d8dbb3f38d3e085b6c9ccc1 (diff) | |
| download | rust-fec45930823c77acd91bfeec153b323bacfab099.tar.gz rust-fec45930823c77acd91bfeec153b323bacfab099.zip | |
new_without_default: ignore const generics/lifetime params on fn new
| -rw-r--r-- | clippy_lints/src/new_without_default.rs | 12 | ||||
| -rw-r--r-- | tests/ui/new_without_default.rs | 14 |
2 files changed, 17 insertions, 9 deletions
diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 093ec389335..5c45ee6d94a 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -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! { diff --git a/tests/ui/new_without_default.rs b/tests/ui/new_without_default.rs index 538927b1805..65809023f8d 100644 --- a/tests/ui/new_without_default.rs +++ b/tests/ui/new_without_default.rs @@ -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 + } +} |
