diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 7b838fdee95..86c345b025c 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -17,7 +17,7 @@ use crate::rustc_errors::Applicability; use crate::syntax::source_map::Span; use crate::utils::paths; use crate::utils::sugg::DiagnosticBuilderExt; -use crate::utils::{get_trait_def_id, implements_trait, return_ty, same_tys, span_lint_and_then}; +use crate::utils::{get_trait_def_id, implements_trait, return_ty, same_tys, span_lint_node_and_then}; use if_chain::if_chain; /// **What it does:** Checks for types with a `fn new() -> Self` method and no @@ -165,9 +165,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault { } if let Some(sp) = can_derive_default(self_ty, cx, default_trait_id) { - span_lint_and_then( + span_lint_node_and_then( cx, NEW_WITHOUT_DEFAULT_DERIVE, + id, impl_item.span, &format!( "you should consider deriving a `Default` implementation for `{}`", @@ -183,9 +184,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault { ); }); } else { - span_lint_and_then( + span_lint_node_and_then( cx, NEW_WITHOUT_DEFAULT, + id, impl_item.span, &format!( "you should consider adding a `Default` implementation for `{}`", diff --git a/clippy_lints/src/partialeq_ne_impl.rs b/clippy_lints/src/partialeq_ne_impl.rs index 70c93c5978b..02935cf773d 100644 --- a/clippy_lints/src/partialeq_ne_impl.rs +++ b/clippy_lints/src/partialeq_ne_impl.rs @@ -10,7 +10,7 @@ use crate::rustc::hir::*; use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use crate::rustc::{declare_tool_lint, lint_array}; -use crate::utils::{is_automatically_derived, span_lint}; +use crate::utils::{is_automatically_derived, span_lint_node}; use if_chain::if_chain; /// **What it does:** Checks for manual re-implementations of `PartialEq::ne`. @@ -56,10 +56,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { then { for impl_item in impl_items { if impl_item.ident.name == "ne" { - span_lint(cx, - PARTIALEQ_NE_IMPL, - impl_item.span, - "re-implementing `PartialEq::ne` is unnecessary") + span_lint_node( + cx, + PARTIALEQ_NE_IMPL, + impl_item.id.node_id, + impl_item.span, + "re-implementing `PartialEq::ne` is unnecessary", + ); } } } diff --git a/tests/ui/new_without_default.rs b/tests/ui/new_without_default.rs index a1818e037a7..2e715a6f8ba 100644 --- a/tests/ui/new_without_default.rs +++ b/tests/ui/new_without_default.rs @@ -139,4 +139,18 @@ impl<'a, T: 'a> OptionRefWrapper<'a, T> { } } +pub struct Allow(Foo); + +impl Allow { + #[allow(clippy::new_without_default)] + pub fn new() -> Self { unimplemented!() } +} + +pub struct AllowDerive; + +impl AllowDerive { + #[allow(clippy::new_without_default_derive)] + pub fn new() -> Self { unimplemented!() } +} + fn main() {} diff --git a/tests/ui/partialeq_ne_impl.rs b/tests/ui/partialeq_ne_impl.rs index 3f9f91c81b1..fabeee24b30 100644 --- a/tests/ui/partialeq_ne_impl.rs +++ b/tests/ui/partialeq_ne_impl.rs @@ -20,4 +20,12 @@ impl PartialEq for Foo { } } +struct Bar; + +impl PartialEq for Bar { + fn eq(&self, _: &Bar) -> bool { true } + #[allow(clippy::partialeq_ne_impl)] + fn ne(&self, _: &Bar) -> bool { false } +} + fn main() {}