rust-lang / rust-lang/fls

Use-import prefix construction does not preserve leading `::`

Open
#711 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-resolve C-bug
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 ::std must retain ::; otherwise it can become indistinguishable from locally resolved std.
  • 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.