Skip to content

Commit

Permalink
Find lowest span out of use + attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Sep 7, 2023
1 parent 4da6eb2 commit 03bee1f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2753,7 +2753,13 @@ fn search_for_any_use_in_items(items: &[P<ast::Item>]) -> Option<Span> {
for item in items {
if let ItemKind::Use(..) = item.kind {
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()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// run-rustfix
// compile-flags: --cfg=whatever -Aunused

#[cfg(whatever)]
use y::z;
#[cfg(whatever)]
use y::Whatever;

mod y {
Expand Down

0 comments on commit 03bee1f

Please sign in to comment.