forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#123813 - compiler-errors:redundant-lint, r=…
…petrochenkov Add `REDUNDANT_IMPORTS` lint for new redundant import detection Defaults to Allow for now. Stacked on rust-lang#123744 to avoid merge conflict, but much easier to review all as one. r? petrochenkov
- Loading branch information
Showing
28 changed files
with
332 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
//@ check-pass | ||
// Check that we detect imports that are redundant due to the extern prelude | ||
// and that we emit a reasonable diagnostic. | ||
// issue: rust-lang/rust#121915 | ||
//~^^^ NOTE the item `aux_issue_121915` is already defined by the extern prelude | ||
|
||
// See also the discussion in <https://github.com/rust-lang/rust/pull/122954>. | ||
|
||
//@ compile-flags: --extern aux_issue_121915 --edition 2018 | ||
//@ aux-build: aux-issue-121915.rs | ||
|
||
#[deny(unused_imports)] | ||
#[deny(redundant_imports)] | ||
//~^ NOTE the lint level is defined here | ||
fn main() { | ||
use aux_issue_121915; | ||
//FIXME(unused_imports): ~^ ERROR the item `aux_issue_121915` is imported redundantly | ||
//~^ ERROR the item `aux_issue_121915` is imported redundantly | ||
aux_issue_121915::item(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error: the item `aux_issue_121915` is imported redundantly | ||
--> $DIR/redundant-import-extern-prelude.rs:14:9 | ||
| | ||
LL | use aux_issue_121915; | ||
| ^^^^^^^^^^^^^^^^ the item `aux_issue_121915` is already defined by the extern prelude | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/redundant-import-extern-prelude.rs:11:8 | ||
| | ||
LL | #[deny(redundant_imports)] | ||
| ^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
//@ check-pass | ||
//@ compile-flags: --extern aux_issue_121915 --edition 2015 | ||
//@ aux-build: aux-issue-121915.rs | ||
|
||
extern crate aux_issue_121915; | ||
|
||
#[deny(unused_imports)] | ||
#[deny(redundant_imports)] | ||
fn main() { | ||
use aux_issue_121915; | ||
//FIXME(unused_imports): ~^ ERROR the item `aux_issue_121915` is imported redundantly | ||
//~^ ERROR the item `aux_issue_121915` is imported redundantly | ||
aux_issue_121915::item(); | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/ui/imports/redundant-import-issue-121915-2015.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
error: the item `aux_issue_121915` is imported redundantly | ||
--> $DIR/redundant-import-issue-121915-2015.rs:8:9 | ||
| | ||
LL | extern crate aux_issue_121915; | ||
| ------------------------------ the item `aux_issue_121915` is already imported here | ||
... | ||
LL | use aux_issue_121915; | ||
| ^^^^^^^^^^^^^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/redundant-import-issue-121915-2015.rs:6:8 | ||
| | ||
LL | #[deny(redundant_imports)] | ||
| ^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
tests/ui/imports/redundant-import-lang-prelude-attr.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error: the item `allow` is imported redundantly | ||
--> $DIR/redundant-import-lang-prelude-attr.rs:15:5 | ||
| | ||
LL | use allow; | ||
| ^^^^^ the item `allow` is already defined by the extern prelude | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/redundant-import-lang-prelude-attr.rs:12:9 | ||
| | ||
LL | #![deny(redundant_imports)] | ||
| ^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error: the item `u8` is imported redundantly | ||
--> $DIR/redundant-import-lang-prelude.rs:13:5 | ||
| | ||
LL | use std::primitive::u8; | ||
| ^^^^^^^^^^^^^^^^^^ the item `u8` is already defined by the extern prelude | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/redundant-import-lang-prelude.rs:10:9 | ||
| | ||
LL | #![deny(redundant_imports)] | ||
| ^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,62 @@ | ||
error: the item `TryFrom` is imported redundantly | ||
--> $DIR/suggest-remove-issue-121315.rs:7:9 | ||
| | ||
LL | use std::convert::TryFrom; | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL | ||
| | ||
= note: the item `TryFrom` is already defined here | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/suggest-remove-issue-121315.rs:2:25 | ||
| | ||
LL | #![deny(unused_imports, redundant_imports)] | ||
| ^^^^^^^^^^^^^^^^^ | ||
|
||
error: the item `TryFrom` is imported redundantly | ||
--> $DIR/suggest-remove-issue-121315.rs:14:24 | ||
| | ||
LL | use std::convert::{TryFrom, TryInto}; | ||
| ^^^^^^^ | ||
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL | ||
| | ||
= note: the item `TryFrom` is already defined here | ||
|
||
error: the item `TryInto` is imported redundantly | ||
--> $DIR/suggest-remove-issue-121315.rs:14:33 | ||
| | ||
LL | use std::convert::{TryFrom, TryInto}; | ||
| ^^^^^^^ | ||
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL | ||
| | ||
= note: the item `TryInto` is already defined here | ||
|
||
error: unused import: `AsMut` | ||
--> $DIR/suggest-remove-issue-121315.rs:25:24 | ||
--> $DIR/suggest-remove-issue-121315.rs:24:24 | ||
| | ||
LL | use std::convert::{AsMut, Into}; | ||
| ^^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/suggest-remove-issue-121315.rs:3:9 | ||
--> $DIR/suggest-remove-issue-121315.rs:2:9 | ||
| | ||
LL | #![deny(unused_imports)] | ||
LL | #![deny(unused_imports, redundant_imports)] | ||
| ^^^^^^^^^^^^^^ | ||
|
||
error: the item `Into` is imported redundantly | ||
--> $DIR/suggest-remove-issue-121315.rs:24:31 | ||
| | ||
LL | use std::convert::{AsMut, Into}; | ||
| ^^^^ | ||
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL | ||
| | ||
= note: the item `Into` is already defined here | ||
|
||
error: unused import: `From` | ||
--> $DIR/suggest-remove-issue-121315.rs:34:24 | ||
--> $DIR/suggest-remove-issue-121315.rs:33:24 | ||
| | ||
LL | use std::convert::{From, Infallible}; | ||
| ^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
error: aborting due to 6 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
//@ check-pass | ||
#![deny(unused_imports)] | ||
#![deny(redundant_imports)] | ||
|
||
struct S; | ||
|
||
fn main() { | ||
use S; //FIXME(unused_imports): ~ ERROR the item `S` is imported redundantly | ||
use S; //~ ERROR the item `S` is imported redundantly | ||
|
||
let _s = S; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
error: the item `S` is imported redundantly | ||
--> $DIR/issue-59896.rs:6:9 | ||
| | ||
LL | struct S; | ||
| --------- the item `S` is already defined here | ||
... | ||
LL | use S; | ||
| ^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/issue-59896.rs:1:9 | ||
| | ||
LL | #![deny(redundant_imports)] | ||
| ^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
tests/ui/lint/use-redundant/use-redundant-glob-parent.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
warning: the item `Foo` is imported redundantly | ||
--> $DIR/use-redundant-glob-parent.rs:12:9 | ||
| | ||
LL | use bar::*; | ||
| ------ the item `Foo` is already imported here | ||
... | ||
LL | use bar::Foo; | ||
| ^^^^^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/use-redundant-glob-parent.rs:2:9 | ||
| | ||
LL | #![warn(redundant_imports)] | ||
| ^^^^^^^^^^^^^^^^^ | ||
|
||
warning: 1 warning emitted | ||
|
Oops, something went wrong.