Skip to content

Commit dfe5fd0

Browse files
committed
Auto merge of #87975 - m-ou-se:unused-import-attributes, r=nagisa
Include attributes in removal span for unused imports. Fixes #87973
2 parents 40db258 + 8dc8649 commit dfe5fd0

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

compiler/rustc_resolve/src/check_unused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<'a, 'b> UnusedImportCheckVisitor<'a, 'b> {
9898

9999
impl<'a, 'b> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b> {
100100
fn visit_item(&mut self, item: &'a ast::Item) {
101-
self.item_span = item.span;
101+
self.item_span = item.span_with_attributes();
102102

103103
// Ignore is_public import statements because there's no way to be sure
104104
// whether they're used or not. Also ignore imports with a dummy span
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// run-rustfix
2+
#![deny(unused_imports)]
3+
4+
// Check that attributes get removed too. See #87973.
5+
6+
//~^ ERROR unused import
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// run-rustfix
2+
#![deny(unused_imports)]
3+
4+
// Check that attributes get removed too. See #87973.
5+
#[deprecated]
6+
#[allow(unsafe_code)]
7+
#[cfg(not(foo))]
8+
use std::fs;
9+
//~^ ERROR unused import
10+
11+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: unused import: `std::fs`
2+
--> $DIR/unused-import-issue-87973.rs:8:5
3+
|
4+
LL | use std::fs;
5+
| ^^^^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/unused-import-issue-87973.rs:2:9
9+
|
10+
LL | #![deny(unused_imports)]
11+
| ^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+

0 commit comments

Comments
 (0)