Skip to content

Commit c40029e

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

20 files changed

+36
-237
lines changed

compiler/rustc_resolve/src/imports.rs

+2
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

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

-14
This file was deleted.
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

-17
This file was deleted.

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

+5-4
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
}
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,20 @@
1-
error: the item `TryFrom` is imported redundantly
2-
--> $DIR/suggest-remove-issue-121315.rs:7:9
3-
|
4-
LL | use std::convert::TryFrom;
5-
| ^^^^^^^^^^^^^^^^^^^^^
6-
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
7-
|
8-
= note: the item `TryFrom` is already defined here
9-
|
10-
note: the lint level is defined here
11-
--> $DIR/suggest-remove-issue-121315.rs:2:9
12-
|
13-
LL | #![deny(unused_imports)]
14-
| ^^^^^^^^^^^^^^
15-
16-
error: the item `TryFrom` is imported redundantly
17-
--> $DIR/suggest-remove-issue-121315.rs:14:24
18-
|
19-
LL | use std::convert::{TryFrom, TryInto};
20-
| ^^^^^^^
21-
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
22-
|
23-
= note: the item `TryFrom` is already defined here
24-
25-
error: the item `TryInto` is imported redundantly
26-
--> $DIR/suggest-remove-issue-121315.rs:14:33
27-
|
28-
LL | use std::convert::{TryFrom, TryInto};
29-
| ^^^^^^^
30-
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
31-
|
32-
= note: the item `TryInto` is already defined here
33-
341
error: unused import: `AsMut`
35-
--> $DIR/suggest-remove-issue-121315.rs:24:24
2+
--> $DIR/suggest-remove-issue-121315.rs:25:24
363
|
374
LL | use std::convert::{AsMut, Into};
385
| ^^^^^
39-
40-
error: the item `Into` is imported redundantly
41-
--> $DIR/suggest-remove-issue-121315.rs:24:31
426
|
43-
LL | use std::convert::{AsMut, Into};
44-
| ^^^^
45-
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
7+
note: the lint level is defined here
8+
--> $DIR/suggest-remove-issue-121315.rs:3:9
469
|
47-
= note: the item `Into` is already defined here
10+
LL | #![deny(unused_imports)]
11+
| ^^^^^^^^^^^^^^
4812

4913
error: unused import: `From`
50-
--> $DIR/suggest-remove-issue-121315.rs:33:24
14+
--> $DIR/suggest-remove-issue-121315.rs:34:24
5115
|
5216
LL | use std::convert::{From, Infallible};
5317
| ^^^^
5418

55-
error: aborting due to 6 previous errors
19+
error: aborting due to 2 previous errors
5620

tests/ui/lint/unused/issue-59896.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
//@ check-pass
12
#![deny(unused_imports)]
23

34
struct S;
45

56
fn main() {
6-
use S; //~ ERROR the item `S` is imported redundantly
7+
use S; //FIXME(unused_imports): ~ ERROR the item `S` is imported redundantly
78

89
let _s = S;
910
}

tests/ui/lint/unused/issue-59896.stderr

-17
This file was deleted.

tests/ui/lint/use-redundant/use-redundant-glob-parent.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub mod bar {
99
use bar::*;
1010

1111
pub fn warning() -> Foo {
12-
use bar::Foo; //~ WARNING imported redundantly
12+
use bar::Foo; //FIXME(unused_imports): ~ WARNING imported redundantly
1313
Foo(Bar('a'))
1414
}
1515

tests/ui/lint/use-redundant/use-redundant-glob-parent.stderr

-17
This file was deleted.

tests/ui/lint/use-redundant/use-redundant-glob.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub mod bar {
88

99
pub fn warning() -> bar::Foo {
1010
use bar::*;
11-
use bar::Foo; //~ WARNING imported redundantly
11+
use bar::Foo; //FIXME(unused_imports): ~ WARNING imported redundantly
1212
Foo(Bar('a'))
1313
}
1414

tests/ui/lint/use-redundant/use-redundant-glob.stderr

-16
This file was deleted.

tests/ui/lint/use-redundant/use-redundant-issue-71450.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ mod foo {
2323
fn main() {
2424

2525
{
26-
use std::string::String; //~ WARNING the item `String` is imported redundantly
26+
use std::string::String;
27+
//FIXME(unused_imports): ~^ WARNING the item `String` is imported redundantly
2728
// 'String' from 'std::string::String'.
2829
let s = String::new();
2930
println!("{}", s);

tests/ui/lint/use-redundant/use-redundant-issue-71450.stderr

-17
This file was deleted.

tests/ui/lint/use-redundant/use-redundant-prelude-rust-2015.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
#![warn(unused_imports)]
33

44

5-
use std::option::Option::Some;//~ WARNING the item `Some` is imported redundantly
6-
use std::option::Option::None; //~ WARNING the item `None` is imported redundantly
5+
use std::option::Option::Some;
6+
//FIXME(unused_imports): ~^ WARNING the item `Some` is imported redundantly
7+
use std::option::Option::None;
8+
//FIXME(unused_imports): ~ WARNING the item `None` is imported redundantly
79

8-
use std::result::Result::Ok;//~ WARNING the item `Ok` is imported redundantly
9-
use std::result::Result::Err;//~ WARNING the item `Err` is imported redundantly
10+
use std::result::Result::Ok;
11+
//FIXME(unused_imports): ~^ WARNING the item `Ok` is imported redundantly
12+
use std::result::Result::Err;
13+
//FIXME(unused_imports): ~^ WARNING the item `Err` is imported redundantly
1014
use std::convert::{TryFrom, TryInto};
1115

1216
fn main() {

tests/ui/lint/use-redundant/use-redundant-prelude-rust-2015.stderr

-44
This file was deleted.

tests/ui/lint/use-redundant/use-redundant-prelude-rust-2021.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
//@ edition:2021
33
#![warn(unused_imports)]
44

5-
use std::convert::TryFrom;//~ WARNING the item `TryFrom` is imported redundantly
6-
use std::convert::TryInto;//~ WARNING the item `TryInto` is imported redundantly
5+
use std::convert::TryFrom;
6+
//FIXME(unused_imports): ~^ WARNING the item `TryFrom` is imported redundantly
7+
use std::convert::TryInto;
8+
//FIXME(unused_imports): ~^ WARNING the item `TryInto` is imported redundantly
79

810
fn main() {
911
let _e: Result<i32, _> = 8u8.try_into();

tests/ui/lint/use-redundant/use-redundant-prelude-rust-2021.stderr

-26
This file was deleted.

tests/ui/lint/use-redundant/use-redundant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use m1::*; //~ WARNING unused import
1818
use m2::*; //~ WARNING unused import
1919

2020
fn main() {
21-
use crate::foo::Bar; //~ WARNING imported redundantly
21+
use crate::foo::Bar; //FIXME(unused_imports): ~ WARNING imported redundantly
2222
let _a: Bar = 3;
2323
baz();
2424

tests/ui/lint/use-redundant/use-redundant.stderr

+1-10
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,5 @@ warning: unused import: `m2::*`
1616
LL | use m2::*;
1717
| ^^^^^
1818

19-
warning: the item `Bar` is imported redundantly
20-
--> $DIR/use-redundant.rs:21:9
21-
|
22-
LL | use crate::foo::Bar;
23-
| --------------- the item `Bar` is already imported here
24-
...
25-
LL | use crate::foo::Bar;
26-
| ^^^^^^^^^^^^^^^
27-
28-
warning: 3 warnings emitted
19+
warning: 2 warnings emitted
2920

0 commit comments

Comments
 (0)