Auto merge of #87975 - m-ou-se:unused-import-attributes, r=nagisa
Include attributes in removal span for unused imports. Fixes https://github.com/rust-lang/rust/issues/87973
This commit is contained in:
commit
dfe5fd0902
4 changed files with 34 additions and 1 deletions
|
@ -98,7 +98,7 @@ impl<'a, 'b> UnusedImportCheckVisitor<'a, 'b> {
|
||||||
|
|
||||||
impl<'a, 'b> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b> {
|
impl<'a, 'b> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b> {
|
||||||
fn visit_item(&mut self, item: &'a ast::Item) {
|
fn visit_item(&mut self, item: &'a ast::Item) {
|
||||||
self.item_span = item.span;
|
self.item_span = item.span_with_attributes();
|
||||||
|
|
||||||
// Ignore is_public import statements because there's no way to be sure
|
// Ignore is_public import statements because there's no way to be sure
|
||||||
// whether they're used or not. Also ignore imports with a dummy span
|
// whether they're used or not. Also ignore imports with a dummy span
|
||||||
|
|
8
src/test/ui/imports/unused-import-issue-87973.fixed
Normal file
8
src/test/ui/imports/unused-import-issue-87973.fixed
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
// run-rustfix
|
||||||
|
#![deny(unused_imports)]
|
||||||
|
|
||||||
|
// Check that attributes get removed too. See #87973.
|
||||||
|
|
||||||
|
//~^ ERROR unused import
|
||||||
|
|
||||||
|
fn main() {}
|
11
src/test/ui/imports/unused-import-issue-87973.rs
Normal file
11
src/test/ui/imports/unused-import-issue-87973.rs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
// run-rustfix
|
||||||
|
#![deny(unused_imports)]
|
||||||
|
|
||||||
|
// Check that attributes get removed too. See #87973.
|
||||||
|
#[deprecated]
|
||||||
|
#[allow(unsafe_code)]
|
||||||
|
#[cfg(not(foo))]
|
||||||
|
use std::fs;
|
||||||
|
//~^ ERROR unused import
|
||||||
|
|
||||||
|
fn main() {}
|
14
src/test/ui/imports/unused-import-issue-87973.stderr
Normal file
14
src/test/ui/imports/unused-import-issue-87973.stderr
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
error: unused import: `std::fs`
|
||||||
|
--> $DIR/unused-import-issue-87973.rs:8:5
|
||||||
|
|
|
||||||
|
LL | use std::fs;
|
||||||
|
| ^^^^^^^
|
||||||
|
|
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/unused-import-issue-87973.rs:2:9
|
||||||
|
|
|
||||||
|
LL | #![deny(unused_imports)]
|
||||||
|
| ^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue