Skip to content

Fix leading qualifiers in use-import prefixes - #717

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

Fix leading qualifiers in use-import prefixes#717
PLeVasseur wants to merge 3 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 namespace qualifiers when constructing import path prefixes.
  • Distinguish empty local prefixes, bare extern-prelude prefixes, and qualified global prefixes.
  • Retain qualifiers through nested use trees and reject invalid non-leading or duplicate qualifiers.
  • Centralize the empty and bare-:: glob-import restrictions.
  • Add the corresponding FLS maintenance accounting.

Closes #711

Reference alignment

@PLeVasseur

Copy link
Copy Markdown
Contributor Author

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

@@ -1005,7 +1005,8 @@ Use Imports
SimplePath Renaming?

CommonPathPrefix ::=

@tshepang tshepang Aug 15, 2026

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 this change is not needed since these mean same thing... SimplePath? means SimplePath is optional

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I second that.

@@ -1018,35 +1019,28 @@ A :t:`use import` brings :t:`entities <entity>` :t:`in scope` within the
:t:`use import` resides.

:dp:`fls_sxo1jb25pl8a`

@tshepang tshepang Aug 15, 2026

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 think we should not consider empty segments as what can be a common path prefix. This makes us adjust text elsewhere without adding clarity. To demo my suggestion, in ::foo::{self, b as foo, c::*}, ::foo is the common path prefix. Also, that is equivalent to ::{foo::{self, b as foo, c::*}} since the outer braces do not add any semantic meaning... they are simply discarded.

Following my suggestion also aligns us more with Reference... its definition of common prefix does not include anything with an empty segment.

View changes since the review


#. :dp:`fls_IPYvldMqduf4`
Start the :t:`import path prefix` as follows:
Make the given :t:`use import` the current :t:`use import`, and start the :t:`import path prefix` as follows:

@kirtchev-adacore kirtchev-adacore Aug 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This, coupled with "Make the :t:nesting import the current :t:use import.", is not correct, and is confusing.

Syntactically, a "use import" is just use ...; (see the grammar for UseImport). These two rules somewhat imply that the construction of the import path prefix spans across multiple use imports (and I mean multiple items), which is just not true.

View changes since the review

* :dp:`fls_irdKqoYzBM0M`
If the :t:`use import` is a :t:`nesting import` then start with the
:t:`[path segment]s` of the :t:`nesting import`'s :t:`common path prefix`.
If the :t:`nesting import` has a :t:`common path prefix`, prepend the :t:`common path prefix` to the :t:`import path prefix`. If the :t:`common path prefix` contains a :t:`path segment` and the :t:`import path prefix` was not empty, place a :t:`namespace qualifier` ``::`` between them.

@kirtchev-adacore kirtchev-adacore Aug 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see what you are trying to do here, however this is becoming quite confusing. I think we have a higher-level problem with our approach. Perhaps going start-to-end is not the correct approach.

We basically want to identify the prefix that is supposed to resolve to something, and that something depends on the path segments involved, and the use of certain symbols and keywords. For example, in

use aaa::bbb::{self, ccc::*, ddd::{self, eee}};

the prefixes of interest are

  • aaa::bbb:: for the subsequent self, ccc and ddd,
  • aaa::bbb::ccc:: for the subsequent *,
  • aaa::bbb::ccc::ddd:: for the subsequent self and eee.

Perhaps the correct approach is to define "import path prefix" in terms of a end-to-start order, relative to some path segment, *, or keyword.

What do you think?

View changes since the review

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 ::

3 participants