-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Be more specific when flagging imports that are redundant due to the …
…extern prelude
- Loading branch information
Showing
9 changed files
with
108 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// 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)] | ||
//~^ NOTE the lint level is defined here | ||
fn main() { | ||
use aux_issue_121915; | ||
//~^ ERROR the item `aux_issue_121915` is imported redundantly | ||
aux_issue_121915::item(); | ||
} |
6 changes: 3 additions & 3 deletions
6
...orts/redundant-import-issue-121915.stderr → ...ts/redundant-import-extern-prelude.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
This file was deleted.
Oops, something went wrong.
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,18 @@ | ||
// Check that we detect imports (of built-in attributes) that are redundant due to | ||
// the language prelude and that we emit a reasonable diagnostic. | ||
//~^^ NOTE the item `allow` is already defined by the extern prelude | ||
|
||
// Note that we use the term "extern prelude" in the label even though "language prelude" | ||
// would be more correct. However, it's not worth special-casing this. | ||
|
||
// See also the discussion in <https://github.com/rust-lang/rust/pull/122954>. | ||
|
||
//@ edition: 2018 | ||
|
||
#![deny(unused_imports)] | ||
//~^ NOTE the lint level is defined here | ||
|
||
use allow; //~ ERROR the item `allow` is imported redundantly | ||
|
||
#[allow(unused)] | ||
fn main() {} |
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(unused_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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Check that we detect imports that are redundant due to the language prelude | ||
// and that we emit a reasonable diagnostic. | ||
//~^^ NOTE the item `u8` is already defined by the extern prelude | ||
|
||
// Note that we use the term "extern prelude" in the label even though "language prelude" | ||
// would be more correct. However, it's not worth special-casing this. | ||
|
||
// See also the discussion in <https://github.com/rust-lang/rust/pull/122954>. | ||
|
||
#![deny(unused_imports)] | ||
//~^ NOTE the lint level is defined here | ||
|
||
use std::primitive::u8; | ||
//~^ ERROR the item `u8` is imported redundantly | ||
|
||
const _: u8 = 0; | ||
|
||
fn main() {} |
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(unused_imports)] | ||
| ^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
23 changes: 23 additions & 0 deletions
23
tests/ui/imports/redundant-import-undetected-macro-use-prelude.rs
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,23 @@ | ||
// This test demonstrates that we currently don't make an effort to detect | ||
// imports made redundant by the `#[macro_use]` prelude. | ||
// See also the discussion in <https://github.com/rust-lang/rust/pull/122954>. | ||
|
||
//@ check-pass | ||
//@ aux-build:two_macros.rs | ||
#![deny(unused_imports)] | ||
|
||
#[macro_use] | ||
extern crate two_macros; | ||
|
||
// This import is actually redundant due to the `#[macro_use]` above. | ||
use two_macros::n; | ||
|
||
// We intentionally reference two items from the `#[macro_use]` because if | ||
// were to reference only item `n`, we would flag the `#[macro_use]` attribute | ||
// as redundant which would be correct of course. | ||
// That's interesting on its own -- we prefer "blaming" the `#[macro_use]` | ||
// over the import (here, `use two_macros::n`) when it comes to redundancy. | ||
n!(); | ||
m!(); | ||
|
||
fn main() {} |