Skip to content

Commit aaae638

Browse files
Use help span option
1 parent d7e7a2e commit aaae638

2 files changed

Lines changed: 16 additions & 20 deletions

File tree

clippy_lints/src/iter_missing_exact_size.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use clippy_utils::diagnostics::span_lint_and_help;
22
use clippy_utils::paths::{PathNS, lookup_path_str};
33
use clippy_utils::sym;
44
use clippy_utils::ty::{get_field_by_name, implements_trait, ty_from_hir_ty};
5-
use rustc_errors::MultiSpan;
65
use rustc_hir::{Body, ExprKind, Impl, ImplItemKind, Item, ItemKind, OwnerId, OwnerNode, QPath};
76
use rustc_lint::{LateContext, LateLintPass};
87
use rustc_session::impl_lint_pass;
@@ -184,18 +183,13 @@ impl<'tcx> LateLintPass<'tcx> for IterMissingExactSize {
184183
return;
185184
}
186185
}
187-
let mut lint_span = MultiSpan::from_span(item.span);
188-
lint_span.push_span_label(
189-
trailing_expr.span,
190-
"This size_hint() implementation delegates to the size_hint() of an ExactSizeIterator",
191-
);
192186
span_lint_and_help(
193187
cx,
194188
ITER_MISSING_EXACT_SIZE,
195-
lint_span,
196-
"iterator can implement ExactSizeIterator",
197-
None,
198-
"since size_hint() delegates to an ExactSizeIterator, the overall iterator is likely to have an exact size",
189+
item.span,
190+
"iterator can implement `ExactSizeIterator`",
191+
Some(trailing_expr.span),
192+
"this `size_hint()` implementation delegates to to the `size_hint()` of an `ExactSizeIterator`, so the overall iterator is likely to have an exact size",
199193
);
200194
}
201195
}
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
1-
error: iterator can implement ExactSizeIterator
1+
error: iterator can implement `ExactSizeIterator`
22
--> tests/ui/iter_missing_exact_size.rs:11:1
33
|
44
LL | / impl Iterator for StringRepeater1 {
55
LL | |
66
LL | | type Item = String;
77
LL | | fn next(&mut self) -> Option<Self::Item> {
88
... |
9-
LL | | self.range.size_hint()
10-
| | ---------------------- This size_hint() implementation delegates to the size_hint() of an ExactSizeIterator
11-
LL | | }
129
LL | | }
1310
| |_^
1411
|
15-
= help: since size_hint() delegates to an ExactSizeIterator, the overall iterator is likely to have an exact size
12+
help: this `size_hint()` implementation delegates to to the `size_hint()` of an `ExactSizeIterator`, so the overall iterator is likely to have an exact size
13+
--> tests/ui/iter_missing_exact_size.rs:18:9
14+
|
15+
LL | self.range.size_hint()
16+
| ^^^^^^^^^^^^^^^^^^^^^^
1617
= note: `-D clippy::iter-missing-exact-size` implied by `-D warnings`
1718
= help: to override `-D warnings` add `#[allow(clippy::iter_missing_exact_size)]`
1819

19-
error: iterator can implement ExactSizeIterator
20+
error: iterator can implement `ExactSizeIterator`
2021
--> tests/ui/iter_missing_exact_size.rs:25:1
2122
|
2223
LL | / impl Iterator for StringRepeater2 {
2324
LL | |
2425
LL | | type Item = String;
2526
LL | | fn next(&mut self) -> Option<Self::Item> {
2627
... |
27-
LL | | self.1.size_hint()
28-
| | ------------------ This size_hint() implementation delegates to the size_hint() of an ExactSizeIterator
29-
LL | | }
3028
LL | | }
3129
| |_^
3230
|
33-
= help: since size_hint() delegates to an ExactSizeIterator, the overall iterator is likely to have an exact size
31+
help: this `size_hint()` implementation delegates to to the `size_hint()` of an `ExactSizeIterator`, so the overall iterator is likely to have an exact size
32+
--> tests/ui/iter_missing_exact_size.rs:32:9
33+
|
34+
LL | self.1.size_hint()
35+
| ^^^^^^^^^^^^^^^^^^
3436

3537
error: aborting due to 2 previous errors
3638

0 commit comments

Comments
 (0)