Skip to content

Commit fe920eb

Browse files
committed
Auto merge of #4593 - james9909:fix-multiple-inherent-impls, r=llogiq
Fix false positive in `multiple_inherent_impl` changelog: Fix false positive in `multiple_inherent_impl` by ignoring impls derived from macros. Closes #4578.
2 parents 5f058d8 + 189eaa5 commit fe920eb

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

clippy_lints/src/inherent_impl.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! lint on inherent implementations
22
3-
use crate::utils::span_lint_and_then;
3+
use crate::utils::{in_macro, span_lint_and_then};
44
use rustc::hir::*;
55
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
66
use rustc::{declare_tool_lint, impl_lint_pass};
@@ -52,7 +52,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MultipleInherentImpl {
5252
if let ItemKind::Impl(_, _, _, ref generics, None, _, _) = item.kind {
5353
// Remember for each inherent implementation encoutered its span and generics
5454
// but filter out implementations that have generic params (type or lifetime)
55-
if generics.params.len() == 0 {
55+
// or are derived from a macro
56+
if !in_macro(item.span) && generics.params.len() == 0 {
5657
self.impls.insert(item.hir_id.owner_def_id(), item.span);
5758
}
5859
}

tests/ui/crashes/inherent_impl.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#![deny(clippy::multiple_inherent_impl)]
2+
3+
/// Test for https://github.com/rust-lang/rust-clippy/issues/4578
4+
5+
macro_rules! impl_foo {
6+
($struct:ident) => {
7+
impl $struct {
8+
fn foo() {}
9+
}
10+
};
11+
}
12+
13+
macro_rules! impl_bar {
14+
($struct:ident) => {
15+
impl $struct {
16+
fn bar() {}
17+
}
18+
};
19+
}
20+
21+
struct MyStruct;
22+
23+
impl_foo!(MyStruct);
24+
impl_bar!(MyStruct);
25+
26+
fn main() {}

0 commit comments

Comments
 (0)