Skip to content

Use-import prefix construction does not preserve leading :: #711

Description

@PLeVasseur

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-resolveName resolution, paths, namespaces, preludes, etc.C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions