1
Fork 0

Use span of impl/trait in len_without_is_empty error message, rather than the span of the len method

This commit is contained in:
Phil Ellison 2017-02-19 15:14:30 +00:00
parent 8a227c7577
commit 2dd45b7317
2 changed files with 37 additions and 20 deletions

View file

@ -107,7 +107,7 @@ fn check_trait_items(cx: &LateContext, item: &Item, trait_items: &[TraitItemRef]
if cx.access_levels.is_exported(i.id.node_id) { if cx.access_levels.is_exported(i.id.node_id) {
span_lint(cx, span_lint(cx,
LEN_WITHOUT_IS_EMPTY, LEN_WITHOUT_IS_EMPTY,
i.span, item.span,
&format!("trait `{}` has a `len` method but no `is_empty` method", item.name)); &format!("trait `{}` has a `len` method but no `is_empty` method", item.name));
} }
} }
@ -146,7 +146,7 @@ fn check_impl_items(cx: &LateContext, item: &Item, impl_items: &[ImplItemRef]) {
span_lint(cx, span_lint(cx,
LEN_WITHOUT_IS_EMPTY, LEN_WITHOUT_IS_EMPTY,
i.span, item.span,
&format!("item `{}` has a public `len` method but {} `is_empty` method", ty, is_empty)); &format!("item `{}` has a public `len` method but {} `is_empty` method", ty, is_empty));
} }
} }

View file

@ -1,11 +1,13 @@
error: item `PubOne` has a public `len` method but no corresponding `is_empty` method 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 { 9 | impl PubOne {
| _____^ starting here... | _^ starting here...
10 | | pub fn len(self: &Self) -> isize {
11 | | 1 11 | | 1
12 | | } 12 | | }
| |_____^ ...ending here 13 | | }
| |_^ ...ending here
| |
note: lint level defined here note: lint level defined here
--> $DIR/len_zero.rs:4:9 --> $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 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 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 { 65 | impl HasIsEmpty {
| _____^ starting here... | _^ starting here...
66 | | pub fn len(self: &Self) -> isize {
67 | | 1 67 | | 1
68 | | } 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 error: item `HasWrongIsEmpty` has a public `len` method but no corresponding `is_empty` method
--> $DIR/len_zero.rs:95:5 --> $DIR/len_zero.rs:94:1
| |
95 | pub fn len(self: &Self) -> isize { 94 | impl HasWrongIsEmpty {
| _____^ starting here... | _^ starting here...
95 | | pub fn len(self: &Self) -> isize {
96 | | 1 96 | | 1
97 | | } 97 | | }
| |_____^ ...ending here 98 | |
99 | | pub fn is_empty(self: &Self, x : u32) -> bool {
100 | | false
101 | | }
102 | | }
| |_^ ...ending here
error: length comparison to zero error: length comparison to zero
--> $DIR/len_zero.rs:106:8 --> $DIR/len_zero.rs:106:8