-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Be more specific when flagging imports as redundant due to the extern prelude #122954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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]`'d crate because | ||
// if we 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() {} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.