-
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
add unqualified_local_imports lint #125645
Conversation
This comment has been minimized.
This comment has been minimized.
0afbdb1
to
b4e8f5e
Compare
This comment has been minimized.
This comment has been minimized.
a8e0a8e
to
3bd5671
Compare
The Miri subtree was changed cc @rust-lang/miri |
I have enabled the lint in Miri and fixed all its occurrences, so one can see what that looks like. |
Ah yes, import like it's 2015 😄 There is a number of practical cases where a // Modularize a macro
macro_use! m() {}
pub(crate) use m;
// Local enum
fn f() {
enum E { A, B, C, D }
use E::*;
}
// Maybe something else These cases will not affect rustfmt behavior because the imports like these are typically separated from the main import group at the module top by some other items, but will apparently be reported by this lint. |
This comment has been minimized.
This comment has been minimized.
Ah, hm... I already wondered if the lint should maybe stay silent inside functions. Those are usually pretty unambiguous and they generally won't have large amounts of imports that need grouping. (In fact I might want all imports to be a single group there even if on the file level a different style is used...) |
3bd5671
to
66541a2
Compare
This comment has been minimized.
This comment has been minimized.
66541a2
to
7db99e2
Compare
@@ -14,6 +14,7 @@ macro_rules! precondition { | |||
} | |||
}; | |||
} | |||
#[cfg_attr(not(bootstrap), allow(unclear_local_imports))] | |||
pub(crate) use precondition; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like these re-exports of local macros cannot be disambiguated with either self
nor crate
, so the only way to fix the warning is to allow
it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you instead disable the lint for macro definitions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's probably the best option. Though I don't think I quite understand where these macros even live then if they are neither in self
nor in crate
nor in ::
... Cc @petrochenkov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally this lint would work in rustc_resolve
in roughly the same way as the redundant import lint (#123813).
Then we'd check that self::path
resolves to the same thing as path
in all namespaces and it would work correctly in all cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where these macros even live then if they are neither in
self
nor incrate
nor in::
There are many places where names can live, see enum Scope
in rustc_resolve.
self
and crate
modules are Scope::Module
and ::
is Scope::ExternPrelude
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally this lint would work in rustc_resolve in roughly the same way as the redundant import lint (#123813).
Hm... I am entirely unfamiliar with that part of the codebase. I'm happy for someone else to take over this PR, but it may be a while until I have the time to dig into this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I now made the lint just skip over macro imports.
This comment has been minimized.
This comment has been minimized.
7db99e2
to
bbfdd06
Compare
@rustbot author |
☔ The latest upstream changes (presumably #126891) made this pull request unmergeable. Please resolve the merge conflicts. |
bbfdd06
to
365fff9
Compare
This comment has been minimized.
This comment has been minimized.
365fff9
to
e4cda06
Compare
This comment has been minimized.
This comment has been minimized.
e4cda06
to
1486141
Compare
71b0d28
to
5b4b6ee
Compare
@rustbot ready |
☔ The latest upstream changes (presumably #130709) made this pull request unmergeable. Please resolve the merge conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It still seems odd to me to enable this lint only in Miri. It think it would have been better to enable it in a single rustc crate (rustc_const_eval?) to (a) demonstrate how it works on non-test code that uses StdExternalCrate
, but (b) not cause too much difficulty with bootstrapping. But I'll be optimistic and assume that miri will start using StdExternalCrate
and/or other rustc crates will use this lint in the future.
@bors r+
5b4b6ee
to
1eb51e7
Compare
Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri |
That's a fair point. I have done this for rustc_const_eval now, so you can take a look. |
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (7042c26): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)Results (primary -0.1%, secondary -2.8%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (secondary 2.4%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 767.967s -> 767.3s (-0.09%) |
Hm, seems like the lint is run even when it is allowed? Is there some established way to avoid work for |
I think that (some?) lints are currently running independently of their allowed status, as it was non-trivial to do it otherwise. @blyxyas might know more. |
cc #59024 |
There is work by @blyxyas for not running |
Visiting for weekly rustc-perf triage:
@rustbot label: +perf-regression-triaged |
This lint helps deal with rust-lang/rustfmt#4709 by having the compiler detect imports of local items that are not syntactically distinguishable from imports from other cates. Making them syntactically distinguishable ensures rustfmt can consistently apply the desired import grouping.