diff options
| author | flip1995 <hello@philkrones.com> | 2020-01-08 17:31:06 +0100 |
|---|---|---|
| committer | flip1995 <hello@philkrones.com> | 2020-01-08 17:47:01 +0100 |
| commit | 9ea17d42a7c5f089143e8b4ed37ee9de268a3bbb (patch) | |
| tree | 1a996bad13f4696f7a98d2d9ba735de1160df6e1 | |
| parent | c789caa45490c291f1fa7893b222f0e30e916ff9 (diff) | |
| download | rust-9ea17d42a7c5f089143e8b4ed37ee9de268a3bbb.tar.gz rust-9ea17d42a7c5f089143e8b4ed37ee9de268a3bbb.zip | |
Fix useless attribute suggestion
| -rw-r--r-- | clippy_lints/src/utils/mod.rs | 13 |
1 files 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<T: LintContext>(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`. |
