[use_self] fix FP when trait impl defined in macro

Found when working on `lintcheck --fix`
This commit is contained in:
kraktus 2022-10-24 18:25:59 +02:00
parent 628a79d6b6
commit e86e810889
3 changed files with 53 additions and 0 deletions

View File

@ -103,6 +103,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
if parameters.as_ref().map_or(true, |params| { if parameters.as_ref().map_or(true, |params| {
!params.parenthesized && !params.args.iter().any(|arg| matches!(arg, GenericArg::Lifetime(_))) !params.parenthesized && !params.args.iter().any(|arg| matches!(arg, GenericArg::Lifetime(_)))
}); });
if !item.span.from_expansion();
if !is_from_proc_macro(cx, item); // expensive, should be last check if !is_from_proc_macro(cx, item); // expensive, should be last check
then { then {
StackItem::Check { StackItem::Check {

View File

@ -112,4 +112,30 @@ impl NameTrait for u8 {
} }
} }
mod impl_in_macro {
macro_rules! parse_ip_impl {
// minimized from serde=1.0.118
($ty:ty) => {
impl FooTrait for $ty {
fn new() -> Self {
<$ty>::bar()
}
}
};
}
struct Foo;
trait FooTrait {
fn new() -> Self;
}
impl Foo {
fn bar() -> Self {
Self
}
}
parse_ip_impl!(Foo); // Should not lint
}
fn main() {} fn main() {}

View File

@ -112,4 +112,30 @@ impl NameTrait for u8 {
} }
} }
mod impl_in_macro {
macro_rules! parse_ip_impl {
// minimized from serde=1.0.118
($ty:ty) => {
impl FooTrait for $ty {
fn new() -> Self {
<$ty>::bar()
}
}
};
}
struct Foo;
trait FooTrait {
fn new() -> Self;
}
impl Foo {
fn bar() -> Self {
Self
}
}
parse_ip_impl!(Foo); // Should not lint
}
fn main() {} fn main() {}