mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 23:20:39 +00:00
new_without_default: ignore const generics/lifetime params on fn new
This commit is contained in:
parent
b15f06e74f
commit
fec4593082
2 changed files with 17 additions and 9 deletions
|
@ -88,15 +88,9 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
|
||||||
// shouldn't be implemented when it is hidden in docs
|
// shouldn't be implemented when it is hidden in docs
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if impl_item
|
if !impl_item.generics.params.is_empty() {
|
||||||
.generics
|
// when the result of `new()` depends on a parameter we should not require
|
||||||
.params
|
// an impl of `Default`
|
||||||
.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`
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if_chain! {
|
if_chain! {
|
||||||
|
|
|
@ -212,3 +212,17 @@ impl DocHidden {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue