-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Be more specific when flagging imports as redundant due to the extern prelude #122954
Conversation
@bors r+ rollup |
And this diagnostic may fire for all of them, not just extern prelude. |
I see |
Std Library PreludeSpan is hopefully never dummy, so we can assume it's unreachable in this code path. Language Preludeuse std::primitive::u8; //~ WARN the item `u8` is imported redundantly
const _: u8 = 0; You are right, this one is reachable and this PR currently misclassifies the prelude.
|
All that to say, I will look into emitting |
Ah, and if we do use the // ::: dep.rs ::: rustc dep.rs --crate-type=lib
#[macro_export]
macro_rules! m { () => {} }
#[macro_export]
macro_rules! g { () => {} }
// ::: usr.rs ::: rustc usr.rs --crate-type=lib -L.
#[macro_use] extern crate dep;
use dep::m; // <-- this is actually redundant but we don't emit any warnings
m!();
g!(); |
The lint is just conservative with macros in general. In any case, the span won't be dummy in this scenario. |
Yeah, seems right, it produces an error in that case https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=8718593e4c9d888ae72a8ac08164b38d |
So we have 3 prelude cases with dummy spans:
use allow; // warning: the item `allow` is imported redundantly
#[allow(unused)]
fn main() {} From those, extern prelude should be most common. |
@fmease |
1acd048
to
bfffbd0
Compare
Sorry for the delay.
I've added that to my internal rustc issue tracker to be revisited by me at some point.
For the For the tool prelude case, we already have tests/ui/rust-2018/uniform-paths/cross-crate.rs and tests/ui/rust-2018/uniform-paths/prelude-fail-2.rs. They should sufficiently cover this case, I think. I've noticed that we currently have tests for redundant imports in two places, namely |
bfffbd0
to
8a24ddf
Compare
@bors r+ |
…r=petrochenkov Be more specific when flagging imports as redundant due to the extern prelude There are multiple distinct kinds of [preludes](https://doc.rust-lang.org/reference/names/preludes.html). Be more specific when flagging imports as redundant due to the [extern prelude](https://doc.rust-lang.org/reference/names/preludes.html#extern-prelude). r? Nilstrieb or compiler
Rollup of 6 pull requests Successful merges: - rust-lang#122470 (`f16` and `f128` step 4: basic library support) - rust-lang#122954 (Be more specific when flagging imports as redundant due to the extern prelude) - rust-lang#123314 (Skip `unused_parens` report for `Paren(Path(..))` in macro.) - rust-lang#123360 (Document restricted_std) - rust-lang#123703 (Use `fn` ptr signature instead of `{closure@..}` in infer error) - rust-lang#123732 (Factor some common `io::Error` constants) r? `@ghost` `@rustbot` modify labels: rollup
…r=petrochenkov Be more specific when flagging imports as redundant due to the extern prelude There are multiple distinct kinds of [preludes](https://doc.rust-lang.org/reference/names/preludes.html). Be more specific when flagging imports as redundant due to the [extern prelude](https://doc.rust-lang.org/reference/names/preludes.html#extern-prelude). r? Nilstrieb or compiler
Rollup of 7 pull requests Successful merges: - rust-lang#122470 (`f16` and `f128` step 4: basic library support) - rust-lang#122954 (Be more specific when flagging imports as redundant due to the extern prelude) - rust-lang#123314 (Skip `unused_parens` report for `Paren(Path(..))` in macro.) - rust-lang#123360 (Document restricted_std) - rust-lang#123661 (Stabilize `cstr_count_bytes`) - rust-lang#123703 (Use `fn` ptr signature instead of `{closure@..}` in infer error) - rust-lang#123704 (Tweak value suggestions in `borrowck` and `hir_analysis`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 8 pull requests Successful merges: - rust-lang#122470 (`f16` and `f128` step 4: basic library support) - rust-lang#122954 (Be more specific when flagging imports as redundant due to the extern prelude) - rust-lang#123314 (Skip `unused_parens` report for `Paren(Path(..))` in macro.) - rust-lang#123360 (Document restricted_std) - rust-lang#123661 (Stabilize `cstr_count_bytes`) - rust-lang#123703 (Use `fn` ptr signature instead of `{closure@..}` in infer error) - rust-lang#123756 (clean up docs for `File::sync_*`) - rust-lang#123761 (Use `suggest_impl_trait` in return type suggestion on type error) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 8 pull requests Successful merges: - rust-lang#122470 (`f16` and `f128` step 4: basic library support) - rust-lang#122954 (Be more specific when flagging imports as redundant due to the extern prelude) - rust-lang#123314 (Skip `unused_parens` report for `Paren(Path(..))` in macro.) - rust-lang#123360 (Document restricted_std) - rust-lang#123661 (Stabilize `cstr_count_bytes`) - rust-lang#123703 (Use `fn` ptr signature instead of `{closure@..}` in infer error) - rust-lang#123756 (clean up docs for `File::sync_*`) - rust-lang#123761 (Use `suggest_impl_trait` in return type suggestion on type error) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#122954 - fmease:defined-by-extern-prelude, r=petrochenkov Be more specific when flagging imports as redundant due to the extern prelude There are multiple distinct kinds of [preludes](https://doc.rust-lang.org/reference/names/preludes.html). Be more specific when flagging imports as redundant due to the [extern prelude](https://doc.rust-lang.org/reference/names/preludes.html#extern-prelude). r? Nilstrieb or compiler
There are multiple distinct kinds of preludes. Be more specific when flagging imports as redundant due to the extern prelude.
r? Nilstrieb or compiler