Fix leading qualifiers in use-import prefixes - #15
Open
PLeVasseur wants to merge 16 commits into
Open
PLeVasseur wants to merge 16 commits into
PLeVasseur wants to merge 16 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
::stdfrom selecting the external crate. The broader nonglobal ambiguity model and the trailing-selfrules in Paths are unchanged; the enum-or-module requirement on import path prefixes now exempts a simple import whose path ends inself, 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
selfand permittedselfparents.Global paths and prelude shadowing, for Rust 2021.