diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 8a2f37e5aa1..f2609dd5743 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -107,7 +107,7 @@ fn is_named_self(cx: &LateContext, item: &TraitItemRef, name: &str) -> bool { if cx.access_levels.is_exported(i.id.node_id) { span_lint(cx, LEN_WITHOUT_IS_EMPTY, - i.span, + item.span, &format!("trait `{}` has a `len` method but no `is_empty` method", item.name)); } } @@ -146,7 +146,7 @@ fn is_named_self(cx: &LateContext, item: &ImplItemRef, name: &str) -> bool { span_lint(cx, LEN_WITHOUT_IS_EMPTY, - i.span, + item.span, &format!("item `{}` has a public `len` method but {} `is_empty` method", ty, is_empty)); } } diff --git a/tests/ui/len_zero.stderr b/tests/ui/len_zero.stderr index 5aaaecf55cb..430cf8575bf 100644 --- a/tests/ui/len_zero.stderr +++ b/tests/ui/len_zero.stderr @@ -1,11 +1,13 @@ error: item `PubOne` has a public `len` method but no corresponding `is_empty` method - --> $DIR/len_zero.rs:10:5 + --> $DIR/len_zero.rs:9:1 | -10 | pub fn len(self: &Self) -> isize { - | _____^ starting here... +9 | impl PubOne { + | _^ starting here... +10 | | pub fn len(self: &Self) -> isize { 11 | | 1 12 | | } - | |_____^ ...ending here +13 | | } + | |_^ ...ending here | note: lint level defined here --> $DIR/len_zero.rs:4:9 @@ -14,28 +16,43 @@ note: lint level defined here | ^^^^^^^^^^^^^^^^^^^^ error: trait `PubTraitsToo` has a `len` method but no `is_empty` method - --> $DIR/len_zero.rs:32:5 + --> $DIR/len_zero.rs:31:1 | -32 | fn len(self: &Self) -> isize; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +31 | pub trait PubTraitsToo { + | _^ starting here... +32 | | fn len(self: &Self) -> isize; +33 | | } + | |_^ ...ending here error: item `HasIsEmpty` has a public `len` method but a private `is_empty` method - --> $DIR/len_zero.rs:66:5 + --> $DIR/len_zero.rs:65:1 | -66 | pub fn len(self: &Self) -> isize { - | _____^ starting here... +65 | impl HasIsEmpty { + | _^ starting here... +66 | | pub fn len(self: &Self) -> isize { 67 | | 1 68 | | } - | |_____^ ...ending here +69 | | +70 | | fn is_empty(self: &Self) -> bool { +71 | | false +72 | | } +73 | | } + | |_^ ...ending here error: item `HasWrongIsEmpty` has a public `len` method but no corresponding `is_empty` method - --> $DIR/len_zero.rs:95:5 - | -95 | pub fn len(self: &Self) -> isize { - | _____^ starting here... -96 | | 1 -97 | | } - | |_____^ ...ending here + --> $DIR/len_zero.rs:94:1 + | +94 | impl HasWrongIsEmpty { + | _^ starting here... +95 | | pub fn len(self: &Self) -> isize { +96 | | 1 +97 | | } +98 | | +99 | | pub fn is_empty(self: &Self, x : u32) -> bool { +100 | | false +101 | | } +102 | | } + | |_^ ...ending here error: length comparison to zero --> $DIR/len_zero.rs:106:8