Skip to content

Fix leading qualifiers in use-import prefixes - #15

Open
PLeVasseur wants to merge 16 commits into
import-prefix-round5-preview-basefrom
import-prefix-round5-preview-v6
Open

PLeVasseur wants to merge 16 commits into
import-prefix-round5-preview-basefrom
import-prefix-round5-preview-v6

Conversation

@PLeVasseur

Copy link
Copy Markdown
Owner

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 the trailing-self rules in Paths are unchanged; the enum-or-module requirement on import path prefixes now exempts a simple import whose path ends in self, so that a trait parent is accepted as those rules already permit.

Closes rust-lang#711

Reference alignment

Rust Reference: use declarations, including brace syntax, trailing self and permitted self parents.

Global paths and prelude shadowing, for Rust 2021.

Address the review of 2026-09-24 on the import path prefix construction:

- Fold the redundant "A sequence determined as follows" bullet into the
  "For each nesting import" step, which now enumerates only the nesting
  imports that contribute a common path prefix or a leading `::`.
- State the import's own contribution as flat cases with their own
  conditions; a glob import with no prefix of its own and a plain single
  segment simple import match no case and contribute nothing.
- Split the simple import case by multi segment and single segment path
  so the separating `::` is removed exactly and a leading `::` on a single
  segment path is kept.
- Phrase the glob and `self` prefix rules by what the import path prefix
  contains, matching the existing enum-or-module rule.
- Use "use import" as the subject of the nesting restriction.

The construction is unchanged in effect for every case in the review
matrix.
`fls_JHU0ersYB6eL` required every import path prefix that contains a
path segment to resolve to an enum or module. A simple import whose
simple path ends in keyword `self` brings the entity that its prefix
resolves to into scope, and `fls_oRdi3KXFbJcR` allows that entity to be
a trait, as does the Reference (items.use.self.module). So
`use m::Trait::{self as T};` was accepted by rustc and rejected by the
FLS text.

Exempt such imports from `fls_JHU0ersYB6eL`. Glob imports and simple
imports whose last path segment is not `self` are unchanged. Recorded as
its own changelog entry.
Preserve the import-prefix maintenance entries alongside the upstream trait-bound entry.
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.

1 participant