From 9ea17d42a7c5f089143e8b4ed37ee9de268a3bbb Mon Sep 17 00:00:00 2001 From: flip1995 Date: Wed, 8 Jan 2020 17:31:06 +0100 Subject: [PATCH] Fix useless attribute suggestion --- clippy_lints/src/utils/mod.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 1e6a57c6dfc..e304d980098 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -42,8 +42,8 @@ use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::Node; use rustc_hir::*; use rustc_span::hygiene::ExpnKind; -use rustc_span::source_map::{Span, DUMMY_SP}; use rustc_span::symbol::{kw, Symbol}; +use rustc_span::{BytePos, Pos, Span, DUMMY_SP}; use smallvec::SmallVec; use syntax::ast::{self, Attribute, LitKind}; use syntax::attr; @@ -554,7 +554,16 @@ pub fn last_line_of_span(cx: &T, span: Span) -> Span { let source_map_and_line = cx.sess().source_map().lookup_line(span.lo()).unwrap(); let line_no = source_map_and_line.line; let line_start = &source_map_and_line.sf.lines[line_no]; - Span::new(*line_start, span.hi(), span.ctxt()) + let span = Span::new(*line_start, span.hi(), span.ctxt()); + if_chain! { + if let Some(snip) = snippet_opt(cx, span); + if let Some(first_ch_pos) = snip.find(|c: char| !c.is_whitespace()); + then { + span.with_lo(span.lo() + BytePos::from_usize(first_ch_pos)) + } else { + span + } + } } /// Like `snippet_block`, but add braces if the expr is not an `ExprKind::Block`.