Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MarcusGrass
Copy link
Contributor

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:

UseSegmentKind::Slf(None) if self.path.is_empty() && self.visibility.is_some() => {
    self.path = vec![];
    return self;
}

In that case

use self;

would be removed, but not:

use self::self;

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.

@MarcusGrass MarcusGrass force-pushed the mg/6558-fix-remove-self-imports branch from 3b3fc2f to 831c2bd Compare June 9, 2025 07:35
Comment on lines -567 to -572
// Normalise foo::self -> foo.
if let UseSegmentKind::Slf(None) = last.kind {
if !self.path.is_empty() {
return self;
}
}
Copy link
Contributor

@ytmimi ytmimi Jun 10, 2025

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.

Comment on lines -560 to -563
UseSegmentKind::Slf(None) if self.path.is_empty() && self.visibility.is_some() => {
self.path = vec![];
return self;
}
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants