Skip to content

Commit da75aaf

Browse files
authored
Rollup merge of #123744 - compiler-errors:redundant-due-to-glob, r=petrochenkov
Silence `unused_imports` for redundant imports Quick fix for #121708 (comment) r? `@petrochenkov` cc `@joshtriplett` I think this is right, would like confirmation. I also think it's weird that we're using `=` to assign to `is_redundant` but using `per_ns` for the actual spans. Seems like this could be weirdly order dependent, but that's unrelated to this change.
2 parents ec91d71 + 0db2a40 commit da75aaf

26 files changed

+43
-275
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

compiler/rustc_resolve/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ enum ImplTraitContext {
177177

178178
/// Used for tracking import use types which will be used for redundant import checking.
179179
/// ### Used::Scope Example
180-
/// ```rust,compile_fail
180+
/// ```rust,ignore (redundant_imports)
181181
/// #![deny(unused_imports)]
182182
/// use std::mem::drop;
183183
/// fn main() {
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

-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.
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

-14
This file was deleted.

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

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

-14
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() {

0 commit comments

Comments
 (0)