Fix leading qualifiers in use-import prefixes - #717
PLeVasseur wants to merge 13 commits into
Conversation
|
Me, realizing I did not request @tshepang and @kirtchev-adacore to review 🙃 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
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. |
There was a problem hiding this comment.
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};,ashould 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
| 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: |
There was a problem hiding this comment.
- looks like the extra paragraph is not needed here
- this also fix grammar
| 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: |
| * :dp:`fls_9dRQ4YGKstSN` | ||
| Otherwise the sequence is empty. | ||
|
|
There was a problem hiding this comment.
this seems invalid, since a nesting import has a common path prefix or not
but maybe am failing to follow reasoning
| * :dp:`fls_9dRQ4YGKstSN` | |
| Otherwise the sequence is empty. |
| * :dp:`fls_GO9rlHrbXAZn` | ||
| Otherwise the sequence is empty. | ||
|
|
There was a problem hiding this comment.
similar to https://github.com/rust-lang/fls/pull/717/changes#r4092739338
| * :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`. |
There was a problem hiding this comment.
avoids making it seem like the namespace qualifier is optional here
| 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` ``::``. |
There was a problem hiding this comment.
using a shortcut since this is all of them
| 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` ``::``. |
There was a problem hiding this comment.
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.
| :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`. | ||
|
|
There was a problem hiding this comment.
I don't we should have such a thing as empty path prefix
| :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`. |
There was a problem hiding this comment.
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 trait-parent rules are unchanged.Closes #711
Reference alignment
Rust Reference: use declarations
Global paths and prelude shadowing, for Rust 2021.
Testing
CI passes.