Skip to content

Commit 03bee1f

Browse files
Find lowest span out of use + attrs
1 parent 4da6eb2 commit 03bee1f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

compiler/rustc_resolve/src/diagnostics.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -2753,7 +2753,13 @@ fn search_for_any_use_in_items(items: &[P<ast::Item>]) -> Option<Span> {
27532753
for item in items {
27542754
if let ItemKind::Use(..) = item.kind {
27552755
if is_span_suitable_for_use_injection(item.span) {
2756-
return Some(item.span.shrink_to_lo());
2756+
let mut lo = item.span.lo();
2757+
for attr in &item.attrs {
2758+
if attr.span.eq_ctxt(item.span) {
2759+
lo = std::cmp::min(lo, attr.span.lo());
2760+
}
2761+
}
2762+
return Some(Span::new(lo, lo, item.span.ctxt(), item.span.parent()));
27572763
}
27582764
}
27592765
}

tests/ui/resolve/suggest-import-without-clobbering-attrs.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// run-rustfix
22
// compile-flags: --cfg=whatever -Aunused
33

4-
#[cfg(whatever)]
54
use y::z;
5+
#[cfg(whatever)]
66
use y::Whatever;
77

88
mod y {

0 commit comments

Comments
 (0)