Skip to content

Commit 19d0226

Browse files
Silence unused_imports lint for redundant imports
1 parent 72fe8a0 commit 19d0226

25 files changed

+42
-274
lines changed

compiler/rustc_resolve/src/imports.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,13 +1391,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13911391
let mut redundant_spans: Vec<_> = redundant_span.present_items().collect();
13921392
redundant_spans.sort();
13931393
redundant_spans.dedup();
1394+
/* FIXME(unused_imports): Add this back as a new lint
13941395
self.lint_buffer.buffer_lint_with_diagnostic(
13951396
UNUSED_IMPORTS,
13961397
id,
13971398
import.span,
13981399
format!("the item `{source}` is imported redundantly"),
13991400
BuiltinLintDiag::RedundantImport(redundant_spans, source),
14001401
);
1402+
*/
14011403
return true;
14021404
}
14031405

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1+
//@ check-pass
12
// Check that we detect imports that are redundant due to the extern prelude
23
// and that we emit a reasonable diagnostic.
34
// issue: rust-lang/rust#121915
4-
//~^^^ NOTE the item `aux_issue_121915` is already defined by the extern prelude
55

66
// See also the discussion in <https://github.com/rust-lang/rust/pull/122954>.
77

88
//@ compile-flags: --extern aux_issue_121915 --edition 2018
99
//@ aux-build: aux-issue-121915.rs
1010

1111
#[deny(unused_imports)]
12-
//~^ NOTE the lint level is defined here
1312
fn main() {
1413
use aux_issue_121915;
15-
//~^ ERROR the item `aux_issue_121915` is imported redundantly
14+
//FIXME(unused_imports): ~^ ERROR the item `aux_issue_121915` is imported redundantly
1615
aux_issue_121915::item();
1716
}

tests/ui/imports/redundant-import-extern-prelude.stderr

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//@ check-pass
12
//@ compile-flags: --extern aux_issue_121915 --edition 2015
23
//@ aux-build: aux-issue-121915.rs
34

@@ -6,6 +7,6 @@ extern crate aux_issue_121915;
67
#[deny(unused_imports)]
78
fn main() {
89
use aux_issue_121915;
9-
//~^ ERROR the item `aux_issue_121915` is imported redundantly
10+
//FIXME(unused_imports): ~^ ERROR the item `aux_issue_121915` is imported redundantly
1011
aux_issue_121915::item();
1112
}

tests/ui/imports/redundant-import-issue-121915-2015.stderr

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
//@ check-pass
12
// Check that we detect imports (of built-in attributes) that are redundant due to
23
// the language prelude and that we emit a reasonable diagnostic.
3-
//~^^ NOTE the item `allow` is already defined by the extern prelude
44

55
// Note that we use the term "extern prelude" in the label even though "language prelude"
66
// would be more correct. However, it's not worth special-casing this.
@@ -10,9 +10,8 @@
1010
//@ edition: 2018
1111

1212
#![deny(unused_imports)]
13-
//~^ NOTE the lint level is defined here
1413

15-
use allow; //~ ERROR the item `allow` is imported redundantly
14+
use allow; //FIXME(unused_imports): ~ ERROR the item `allow` is imported redundantly
1615

1716
#[allow(unused)]
1817
fn main() {}

tests/ui/imports/redundant-import-lang-prelude-attr.stderr

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/ui/imports/redundant-import-lang-prelude.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1+
//@ check-pass
12
// Check that we detect imports that are redundant due to the language prelude
23
// and that we emit a reasonable diagnostic.
3-
//~^^ NOTE the item `u8` is already defined by the extern prelude
44

55
// Note that we use the term "extern prelude" in the label even though "language prelude"
66
// would be more correct. However, it's not worth special-casing this.
77

88
// See also the discussion in <https://github.com/rust-lang/rust/pull/122954>.
99

1010
#![deny(unused_imports)]
11-
//~^ NOTE the lint level is defined here
1211

1312
use std::primitive::u8;
14-
//~^ ERROR the item `u8` is imported redundantly
13+
//FIXME(unused_imports): ~^ ERROR the item `u8` is imported redundantly
1514

1615
const _: u8 = 0;
1716

tests/ui/imports/redundant-import-lang-prelude.stderr

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/ui/imports/suggest-remove-issue-121315.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
//@ compile-flags: --edition 2021
2+
23
#![deny(unused_imports)]
34
#![allow(dead_code)]
45

56
fn test0() {
67
// Test remove FlatUnused
78
use std::convert::TryFrom;
8-
//~^ ERROR the item `TryFrom` is imported redundantly
9+
//FIXME(unused_imports): ~^ ERROR the item `TryFrom` is imported redundantly
910
let _ = u32::try_from(5i32);
1011
}
1112

1213
fn test1() {
1314
// FIXME(yukang) Test remove NestedFullUnused
1415
use std::convert::{TryFrom, TryInto};
15-
//~^ ERROR the item `TryFrom` is imported redundantly
16-
//~| ERROR the item `TryInto` is imported redundantly
16+
//FIXME(unused_imports): ~^ ERROR the item `TryFrom` is imported redundantly
17+
//FIXME(unused_imports): ~| ERROR the item `TryInto` is imported redundantly
1718

1819
let _ = u32::try_from(5i32);
1920
let _a: i32 = u32::try_into(5u32).unwrap();
@@ -23,7 +24,7 @@ fn test2() {
2324
// FIXME(yukang): Test remove both redundant and unused
2425
use std::convert::{AsMut, Into};
2526
//~^ ERROR unused import: `AsMut`
26-
//~| ERROR the item `Into` is imported redundantly
27+
//FIXME(unused_imports): ~| ERROR the item `Into` is imported redundantly
2728

2829
let _a: u32 = (5u8).into();
2930
}

0 commit comments

Comments
 (0)