-
Notifications
You must be signed in to change notification settings - Fork 927
fix: #6558 don't try to repair invalid self-imports. #6573
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
fix: #6558 don't try to repair invalid self-imports. #6573
Conversation
Attempts break idempotence.
3b3fc2f
to
831c2bd
Compare
src/imports.rs
Outdated
// Normalise foo::self -> foo. | ||
if let UseSegmentKind::Slf(None) = last.kind { | ||
if !self.path.is_empty() { | ||
return self; | ||
} | ||
} |
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'd still like to normalize foo::self
-> foo
. Maybe we can special case this to not normalize self::self
-> self
to prevent idempotent issues in this really obscure case.
src/imports.rs
Outdated
UseSegmentKind::Slf(None) if self.path.is_empty() && self.visibility.is_some() => { | ||
self.path = vec![]; | ||
return self; | ||
} |
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 take it this is where we get rid of use self;
? I don't think there's any harm in keeping this behavior as long as we handle use self::self
in a way that's idempotent.
…ke `self::self`
831c2bd
to
935a355
Compare
A lot fewer changes to behaviour was caused this time around |
Will take another look at this later this evening. Thanks for applying the feedback so quickly |
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.
Nice to see that we're able to remove use self;
, while special casing the use self::self;
scenario.
Maybe in a future diff --git a/src/imports.rs b/src/imports.rs
index cfc2f3bd..9f30ac09 100644
--- a/src/imports.rs
+++ b/src/imports.rs
@@ -565,10 +565,18 @@ impl UseTree {
}
// Normalise foo::self -> foo.
+ // Normalise bar::self::self -> bar.
+ // Remove self::self.
if let UseSegmentKind::Slf(None) = last.kind {
- if !self.path.is_empty() {
- return self;
+ while let Some(UseSegmentKind::Slf(_)) = self.path.last().map(|segment| &segment.kind) {
+ self.path.pop();
+ }
+
+ if self.path.is_empty() {
+ self.path = vec![];
}
+
+ return self;
}
// Normalise foo::self as bar -> foo as bar. |
Fix #6558
Current attempts break idempotence.
As the tests show, paths ending with
self
are now untouched, this PR just removes some code (and adds/modifies some tests).A potential change here would be to keep this part of the code:
In that case
would be removed, but not:
Which woud also fix the idempotence issue, but formatting away
use self;
. Although maybe it's best that the compiler inform the user that they're doing something wrong instead of 'sweeping it under the rug' so to say.