Use-import prefix construction does not preserve leading `::`
Nobody has claimed this yet.
- Dominant language
- reStructuredText
- Stars
- 497
- Forks
- 41
- Avg merge
- 3h 52m
- Merged PRs (30d)
- 4
Description
Problem
The FLS use-import model constructs an import path prefix primarily from path segments. A leading ::, however, is a namespace qualifier rather than a path segment, so the construction in fls_WAA4WmohGu6T does not clearly retain it.
The grammar permits a use-import prefix consisting only of ::, while the related prefix definition and construction describe prefixes in terms of a leading simple path or its path segments. This leaves the FLS unable to rigorously distinguish these Rust 2021 cases:
use {self as this_module}; // Valid: empty local prefix.
use ::{self as root}; // Invalid: imports the bare extern-prelude root.
use ::std::{self as std_alias}; // Valid: global path through the extern prelude.
In particular:
- An empty prefix with no leading
::should resolve from the current module. - A bare
::prefix denotes the extern-prelude root and cannot be imported. - A prefix such as
::stdmust retain::; otherwise it can become indistinguishable from locally resolvedstd. - Prefix construction through nested use trees must retain
::while ensuring it remains at the start of the fully combined path.
This problem predates #694. That PR exposes it by adding a restriction that refers directly to an import path prefix consisting only of ::.
Expected result
The FLS should model the complete use-import prefix, including any leading namespace qualifier, and align the grammar, prefix definitions, construction rules, and legality rules.
The resulting model should account for:
// Valid.
use {self as this_module};
use ::std::{self as std_alias};
use {::{std::mem as m}};
// Invalid.
use ::{self as root};
use ::*;
use ::{*};
use std::{::{std::mem as m}};
use ::{::{std::mem as m}};
This issue is limited to the inherited leading-::/import-prefix model. The keyword-import restrictions added by #694 and unrelated self wording cleanups do not need to be reopened here.
References
- Follow-up discussion from #694: https://github.com/rust-lang/fls/pull/694#discussion_r3547319628
- Rust Reference, use-declaration restrictions: https://doc.rust-lang.org/reference/items/use-declarations.html#r-items.use.restrictions.extern-prelude
- Rust Reference, brace syntax: https://doc.rust-lang.org/reference/items/use-declarations.html#r-items.use.multiple-syntax
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at fls_WAA4WmohGu6T and inspect the grammar, prefix definitions, construction rules, and legality rules for use-import paths. Compare the model with the Rust Reference restrictions and the valid and invalid examples in this issue. Done means leading :: is retained through nested use trees and the listed cases are distinguished correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- documentation
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100