Skip to content

Commit 9ea17d4

Browse files
committed
Fix useless attribute suggestion
1 parent c789caa commit 9ea17d4

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

clippy_lints/src/utils/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
4242
use rustc_hir::Node;
4343
use rustc_hir::*;
4444
use rustc_span::hygiene::ExpnKind;
45-
use rustc_span::source_map::{Span, DUMMY_SP};
4645
use rustc_span::symbol::{kw, Symbol};
46+
use rustc_span::{BytePos, Pos, Span, DUMMY_SP};
4747
use smallvec::SmallVec;
4848
use syntax::ast::{self, Attribute, LitKind};
4949
use syntax::attr;
@@ -554,7 +554,16 @@ pub fn last_line_of_span<T: LintContext>(cx: &T, span: Span) -> Span {
554554
let source_map_and_line = cx.sess().source_map().lookup_line(span.lo()).unwrap();
555555
let line_no = source_map_and_line.line;
556556
let line_start = &source_map_and_line.sf.lines[line_no];
557-
Span::new(*line_start, span.hi(), span.ctxt())
557+
let span = Span::new(*line_start, span.hi(), span.ctxt());
558+
if_chain! {
559+
if let Some(snip) = snippet_opt(cx, span);
560+
if let Some(first_ch_pos) = snip.find(|c: char| !c.is_whitespace());
561+
then {
562+
span.with_lo(span.lo() + BytePos::from_usize(first_ch_pos))
563+
} else {
564+
span
565+
}
566+
}
558567
}
559568

560569
/// Like `snippet_block`, but add braces if the expr is not an `ExprKind::Block`.

0 commit comments

Comments
 (0)