Replacing self overwriting with proper resolution#152996
Replacing self overwriting with proper resolution#152996mu001999 wants to merge 3 commits intorust-lang:mainfrom
self overwriting with proper resolution#152996Conversation
This comment has been minimized.
This comment has been minimized.
178d259 to
abd6031
Compare
This comment has been minimized.
This comment has been minimized.
abd6031 to
3102edf
Compare
This comment has been minimized.
This comment has been minimized.
3102edf to
c206a47
Compare
self appear at the end of any paths in importsself at the end of any paths in imports
This comment has been minimized.
This comment has been minimized.
c206a47 to
d7a8a0a
Compare
d7a8a0a to
d845289
Compare
This comment has been minimized.
This comment has been minimized.
d845289 to
77169f5
Compare
This comment has been minimized.
This comment has been minimized.
77169f5 to
ce8d16a
Compare
This comment has been minimized.
This comment has been minimized.
b4d62d4 to
9ac9e00
Compare
This comment has been minimized.
This comment has been minimized.
9ac9e00 to
39dc3a0
Compare
|
It looks like #146972 (comment) suggests to support trailing However, if we are doing it, then I think it's time to abandon the whole " |
Semantics of trailing But what will trailing |
|
@rustbot author |
This comment has been minimized.
This comment has been minimized.
|
@rustbot ready |
This comment has been minimized.
This comment has been minimized.
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
This code currently compiles in stable rust: struct Thing;
use Thing::{self as Alias};If this code will stop compiling with this PR, then this PR needs a crater run. |
|
Yes, we'll certainly run crater. |
|
Let's perhaps split this into 2 steps.
The first part may require a new deprecation lint for the |
|
@rustbot review |
|
Could you limit this PR to just the first step from #152996 (comment)? |
|
@rustbot review |
|
Thanks! |
This comment has been minimized.
This comment has been minimized.
|
Is it safe to remove the T-Clippy label? |
I think it is now :) |
|
@craterbot check |
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🎉 Experiment
Footnotes
|
|
9 non-spurious regressions:
|
Description for lang teamThis PR implements the first part of the lang team guidance from #146972 (comment). It results in minor breakage as seen above - #152996 (comment). |
|
Some cases that came up in discussion in the @rust-lang/lang meeting: use some_module::SomeEnum::{self, Variant1, Variant2};
use some_module::SomeEnum::{self as MyEnum, Variant1, Variant2};There was a general feeling that those should work. Is this what you mean by "always resolves to a module (in nameres sense, including enums and traits)"? |
|
@joshtriplett My reading is that |
|
There's been a long-standing request from @rust-lang/libs-api to support Would making this change make that much harder in the future, or just take an already-hard thing and make it marginally harder? (In any case, this shouldn't be taken as precedent for "we will never ever want a struct to act as a module for nameres purposes", even if we end up making this particular proposed change for now.) |
Yes, enums and traits are modules in name resolution sense, so
I don't think there's much connection. |
View all comments
As a follow-up PR to #146972 (step 1), after this PR:
1. Trailing(in future)selfcan appear in paths (as the consensus in #146972 (comment))2. E0429 will be no longer emitted,(in future)use ...::self [as target];will be equivalent touse ...::{self [as target]};3. Things like
struct S {}; use S::{self as Other};will be rejectedThis PR used to add a new lint
redundant_self, which would lintuse ...::self [as target];anduse ...::{self [as target]};, and the last commit fixes all warnings emitted by this lint.But this lint and clippy lint unnecessary_self_imports have some overlap. And
use std::io::self;is not equivalent touse std::ioin fact for now, the new lint will also cause the following known issue:So I removed this lint, and I think what it does should be done by extending the clippy lint
unnecessary_self_imports.r? petrochenkov