From d5b73c184b31f90ae0ef299e109d87225f139d5e Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Wed, 29 Nov 2017 17:10:53 +0100 Subject: [PATCH] Fix placement of new_without_default suggestion --- clippy_lints/src/new_without_default.rs | 15 +++++---------- tests/ui/new_without_default.stderr | 13 ++++++------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index b037ef6c42b..b281fd3060e 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -98,23 +98,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault { } if let hir::ImplItemKind::Method(ref sig, _) = impl_item.node { let name = impl_item.name; - let span = impl_item.span; let id = impl_item.id; - let decl = &sig.decl; if sig.constness == hir::Constness::Const { // can't be implemented by default return; } - if !impl_item.generics - .ty_params - .is_empty() - { + if !impl_item.generics.ty_params.is_empty() { // when the result of `new()` depends on a type parameter we should not require // an // impl of `Default` return; } - if decl.inputs.is_empty() && name == "new" && cx.access_levels.is_reachable(id) { + if sig.decl.inputs.is_empty() && name == "new" && cx.access_levels.is_reachable(id) { let self_ty = cx.tcx .type_of(cx.tcx.hir.local_def_id(cx.tcx.hir.get_parent(id))); if_chain! { @@ -126,7 +121,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault { span_lint_and_then( cx, NEW_WITHOUT_DEFAULT_DERIVE, - span, + impl_item.span, &format!("you should consider deriving a `Default` implementation for `{}`", self_ty), |db| { db.suggest_item_with_attr(cx, sp, "try this", "#[derive(Default)]"); @@ -135,12 +130,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault { span_lint_and_then( cx, NEW_WITHOUT_DEFAULT, - span, + impl_item.span, &format!("you should consider adding a `Default` implementation for `{}`", self_ty), |db| { db.suggest_prepend_item( cx, - span, + item.span, "try this", &create_new_without_default_suggest_msg(self_ty), ); diff --git a/tests/ui/new_without_default.stderr b/tests/ui/new_without_default.stderr index 1f14b13306f..c12c10b9ae0 100644 --- a/tests/ui/new_without_default.stderr +++ b/tests/ui/new_without_default.stderr @@ -29,11 +29,10 @@ error: you should consider adding a `Default` implementation for `LtKo<'c>` = note: `-D new-without-default` implied by `-D warnings` help: try this | -64 | impl Default for LtKo<'c> { -65 | fn default() -> Self { -66 | Self::new() -67 | } -68 | } -69 | - ... +63 | impl Default for LtKo<'c> { +64 | fn default() -> Self { +65 | Self::new() +66 | } +67 | } + |