Find lowest span out of use + attrs

This commit is contained in:
Michael Goulet 2023-09-07 05:13:52 +00:00
parent 4da6eb2ec6
commit 03bee1f53d
2 changed files with 8 additions and 2 deletions

View File

@ -2753,7 +2753,13 @@ fn search_for_any_use_in_items(items: &[P<ast::Item>]) -> Option<Span> {
for item in items { for item in items {
if let ItemKind::Use(..) = item.kind { if let ItemKind::Use(..) = item.kind {
if is_span_suitable_for_use_injection(item.span) { if is_span_suitable_for_use_injection(item.span) {
return Some(item.span.shrink_to_lo()); let mut lo = item.span.lo();
for attr in &item.attrs {
if attr.span.eq_ctxt(item.span) {
lo = std::cmp::min(lo, attr.span.lo());
}
}
return Some(Span::new(lo, lo, item.span.ctxt(), item.span.parent()));
} }
} }
} }

View File

@ -1,8 +1,8 @@
// run-rustfix // run-rustfix
// compile-flags: --cfg=whatever -Aunused // compile-flags: --cfg=whatever -Aunused
#[cfg(whatever)]
use y::z; use y::z;
#[cfg(whatever)]
use y::Whatever; use y::Whatever;
mod y { mod y {