Skip to content

Fix leading qualifiers in use-import prefixes - #717

Open
PLeVasseur wants to merge 13 commits into
rust-lang:mainfrom
PLeVasseur:fix-use-import-leading-namespace
Open

PLeVasseur wants to merge 13 commits into
rust-lang:mainfrom
PLeVasseur:fix-use-import-leading-namespace

Conversation

@PLeVasseur

@PLeVasseur PLeVasseur commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Preserve leading :: in import path prefixes, distinguishing an empty prefix from bare :: and qualified paths such as ::std.

Replace the stateful construction with a declarative definition and reject misplaced root qualifiers, including in empty nested groups.

Clarify the construction cases, separator, nesting, and self-specific legality wording in response to review.

Reconcile the shadowing rules with explicit global lookup: local names do not prevent ::std from selecting the external crate. The broader nonglobal ambiguity model and trait-parent rules are unchanged.

Closes #711

Reference alignment

Rust Reference: use declarations

Global paths and prelude shadowing, for Rust 2021.

Testing

CI passes.

@PLeVasseur

Copy link
Copy Markdown
Contributor Author

Me, realizing I did not request @tshepang and @kirtchev-adacore to review 🙃

Comment thread src/entities-and-resolution.rst
Comment thread src/entities-and-resolution.rst
Comment thread src/entities-and-resolution.rst Outdated
Comment thread src/entities-and-resolution.rst Outdated
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@PLeVasseur PLeVasseur left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following up! I think this is probably worth another review now.

View changes since this review

Comment thread src/entities-and-resolution.rst
Comment thread src/entities-and-resolution.rst
Comment thread src/entities-and-resolution.rst Outdated
Comment thread src/entities-and-resolution.rst Outdated
Comment thread src/entities-and-resolution.rst Outdated
Comment thread src/entities-and-resolution.rst Outdated
Comment thread src/entities-and-resolution.rst Outdated
Comment thread src/entities-and-resolution.rst Outdated
Comment thread src/entities-and-resolution.rst Outdated
Comment thread src/entities-and-resolution.rst Outdated
Comment thread src/entities-and-resolution.rst
@rustbot

rustbot commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

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.

@tshepang tshepang left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have left some comments, but maybe before handling those, I do wonder why we need the concept of an "import path prefix" when we have "common path prefix". To support that, I don't think we should treat "global paths" (paths starting with ::) in such a special way... they should only add additional tooling-related behavior, and the distinction defined in just one place.

With examples, I think in...

  • use a::{b, c};, a should be a "common path prefix"
  • use ::a::{b, c};, a (or ::a, not sure) should similarly be considered a "common path prefix"
    • additional semantics of this being a "global path" can be explained elsewhere

View changes since this review

Comment on lines +1031 to +1034
For each :t:`nesting import` in which the :t:`glob import` or :t:`simple import` is nested, from outermost to innermost:

* :dp:`fls_MOXId37fcNPY`
If the :t:`use import` is a :t:`simple import` then start with the
:t:`[path segment]s` of the :t:`simple import`'s :t:`simple path`
:t:`path prefix`.
* :dp:`fls_irdKqoYzBM0M`
A sequence determined as follows:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • looks like the extra paragraph is not needed here
  • this also fix grammar
Suggested change
For each :t:`nesting import` in which the :t:`glob import` or :t:`simple import` is nested, from outermost to innermost:
* :dp:`fls_MOXId37fcNPY`
If the :t:`use import` is a :t:`simple import` then start with the
:t:`[path segment]s` of the :t:`simple import`'s :t:`simple path`
:t:`path prefix`.
* :dp:`fls_irdKqoYzBM0M`
A sequence determined as follows:
For each :t:`nesting import` in which the :t:`glob import` or :t:`simple import` is nested, from outermost to innermost, the sequence is determined as follows:

Comment on lines +1042 to +1044
* :dp:`fls_9dRQ4YGKstSN`
Otherwise the sequence is empty.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems invalid, since a nesting import has a common path prefix or not
but maybe am failing to follow reasoning

Suggested change
* :dp:`fls_9dRQ4YGKstSN`
Otherwise the sequence is empty.

Comment on lines +1057 to +1059
* :dp:`fls_GO9rlHrbXAZn`
Otherwise the sequence is empty.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to https://github.com/rust-lang/fls/pull/717/changes#r4092739338

Suggested change
* :dp:`fls_GO9rlHrbXAZn`
Otherwise the sequence is empty.

Otherwise the sequence is empty.

* :dp:`fls_MOXId37fcNPY`
For a :t:`simple import`, the :t:`simple import`'s :t:`simple path` after removing the last :t:`path segment` and any :t:`namespace qualifier` ``::`` that separates the last :t:`path segment` from a preceding :t:`path segment`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoids making it seem like the namespace qualifier is optional here

Suggested change
For a :t:`simple import`, the :t:`simple import`'s :t:`simple path` after removing the last :t:`path segment` and any :t:`namespace qualifier` ``::`` that separates the last :t:`path segment` from a preceding :t:`path segment`.
For a :t:`simple import`, the :t:`simple import`'s :t:`simple path` after removing the last :t:`path segment` and the :t:`namespace qualifier` ``::`` preceding the :t:`path segment`.

into :t:`scope`.

:dp:`fls_BMtRtjJ7gBKT`
A :t:`glob import`, :t:`nesting import`, or :t:`simple import` expressed with a leading :t:`namespace qualifier` ``::`` shall not be nested within any :t:`nesting import` that has a :t:`common path prefix` or is expressed with a leading :t:`namespace qualifier` ``::``.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using a shortcut since this is all of them

Suggested change
A :t:`glob import`, :t:`nesting import`, or :t:`simple import` expressed with a leading :t:`namespace qualifier` ``::`` shall not be nested within any :t:`nesting import` that has a :t:`common path prefix` or is expressed with a leading :t:`namespace qualifier` ``::``.
A :t:`use import` expressed with a leading :t:`namespace qualifier` ``::`` shall not be nested within any :t:`nesting import` that has a :t:`common path prefix` or is expressed with a leading :t:`namespace qualifier` ``::``.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the part "A use import expressed with a leading namespace qualifier shall not be nested within any nesting import" to mean that use a::{::b, c}; is not allowed, but I don't understand the rest of the sentence.

Comment on lines +1074 to +1076
:dp:`fls_UZHHtqJ0ekju`
An empty :t:`import path prefix` of a :t:`simple import` whose :t:`simple path` is expressed as :t:`keyword` ``self`` resolves to the current :t:`module`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't we should have such a thing as empty path prefix

Suggested change
:dp:`fls_UZHHtqJ0ekju`
An empty :t:`import path prefix` of a :t:`simple import` whose :t:`simple path` is expressed as :t:`keyword` ``self`` resolves to the current :t:`module`.


:dp:`fls_JHU0ersYB6eL`
An :t:`import path prefix` shall resolve to a :t:`module` or :t:`enum`.
An :t:`import path prefix` that contains a :t:`path segment` shall resolve to an :t:`enum` or :t:`module`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use-import prefix construction does not preserve leading ::

4 participants