Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix false positive in multiple_inherent_impl #4593

Merged
merged 1 commit into from
Sep 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions clippy_lints/src/inherent_impl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! lint on inherent implementations

use crate::utils::span_lint_and_then;
use crate::utils::{in_macro, span_lint_and_then};
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, impl_lint_pass};
Expand Down Expand Up @@ -52,7 +52,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MultipleInherentImpl {
if let ItemKind::Impl(_, _, _, ref generics, None, _, _) = item.kind {
// Remember for each inherent implementation encoutered its span and generics
// but filter out implementations that have generic params (type or lifetime)
if generics.params.len() == 0 {
// or are derived from a macro
if !in_macro(item.span) && generics.params.len() == 0 {
self.impls.insert(item.hir_id.owner_def_id(), item.span);
}
}
Expand Down
26 changes: 26 additions & 0 deletions tests/ui/crashes/inherent_impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#![deny(clippy::multiple_inherent_impl)]

/// Test for https://github.com/rust-lang/rust-clippy/issues/4578

macro_rules! impl_foo {
($struct:ident) => {
impl $struct {
fn foo() {}
}
};
}

macro_rules! impl_bar {
($struct:ident) => {
impl $struct {
fn bar() {}
}
};
}

struct MyStruct;

impl_foo!(MyStruct);
impl_bar!(MyStruct);

fn main() {}