Auto merge of #9704 - kraktus:fix_use_self, r=giraffate

[`use_self`] fix FP when trait impl defined in macro

changelog: [`use_self`] fix FP when trait impl defined in macro
This commit is contained in:
bors 2022-10-25 00:29:03 +00:00
commit 6f16596b6a
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| {
!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
then {
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() {}

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() {}