mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-17 05:25:37 +03:00
Auto merge of #9115 - Alexendoo:new-with-const-generics, r=llogiq
`new_without_default`: ignore const generics/lifetime params on `fn new` Fixes #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`
This commit is contained in:
@@ -88,15 +88,9 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
||||
// 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! {
|
||||
|
||||
@@ -212,3 +212,17 @@ pub fn new() -> Self {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user