|
1 | 1 | use clippy_utils::diagnostics::span_lint_and_then; |
2 | 2 | use clippy_utils::higher::VecArgs; |
3 | 3 | use clippy_utils::macros::root_macro_call_first_node; |
4 | | -use clippy_utils::source::SpanRangeExt; |
| 4 | +use clippy_utils::source::{SpanRangeExt, snippet_with_context}; |
5 | 5 | use clippy_utils::ty::implements_trait; |
6 | 6 | use clippy_utils::{is_no_std_crate, sym}; |
7 | 7 | use rustc_ast::{LitIntType, LitKind, UintTy}; |
@@ -91,14 +91,17 @@ impl LateLintPass<'_> for SingleRangeInVecInit { |
91 | 91 | }; |
92 | 92 |
|
93 | 93 | if cx.tcx.qpath_is_lang_item(qpath, LangItem::Range) |
| 94 | + && !start.expr.span.eq_ctxt(inner_expr.span) |
94 | 95 | && let ty = cx.typeck_results().expr_ty(start.expr) |
95 | 96 | && let Some(snippet) = span.get_source_text(cx) |
96 | 97 | // `is_from_proc_macro` will skip any `vec![]`. Let's not! |
97 | 98 | && snippet.starts_with(suggested_type.starts_with()) |
98 | 99 | && snippet.ends_with(suggested_type.ends_with()) |
99 | | - && let Some(start_snippet) = start.span.get_source_text(cx) |
100 | | - && let Some(end_snippet) = end.span.get_source_text(cx) |
101 | 100 | { |
| 101 | + let mut applicability = Applicability::MaybeIncorrect; |
| 102 | + let (start_snippet, _) = snippet_with_context(cx, start.expr.span, span.ctxt(), "..", &mut applicability); |
| 103 | + let (end_snippet, _) = snippet_with_context(cx, end.expr.span, span.ctxt(), "..", &mut applicability); |
| 104 | + |
102 | 105 | let should_emit_every_value = if let Some(step_def_id) = cx.tcx.get_diagnostic_item(sym::range_step) |
103 | 106 | && implements_trait(cx, ty, step_def_id, &[]) |
104 | 107 | { |
|
0 commit comments