rust-lang / rust-lang/rust

Permit attributes inside use-trees

Open
#141,704 12 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-attributes A-grammar A-resolve C-feature-request I-lang-radar T-lang
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Can we permit attributes on use items? I would like the following snippet to be syntactically and semantically valid.

use crate::{alpha, beta, #[cfg(feature = "foo")] gamma};

This would be equivalent to

use crate::{alpha, beta};
#[cfg(feature = "foo")]
use crate::gamma;

This would permit me to use rustfmt's option of one import per module and have it actually be true, rather than one import per module per feature gate. Attributes such as #[allow(unused_imports)] are plausibly useful in this position as well.

Syntactically I see no conflicts in the reference, as # starts any attribute and is unambiguous with the start of an identifier and ::.


This feels simple enough to not need a full RFC, which as far as I can tell is what is technically required. I had thought MCPs were for this, but that turns out to be for non-user-facing changes, and ACP deals with T-libs territory. So consider this a lang-MCP, if you will?

cc @rust-lang/lang

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 by reviewing the Rust Reference section on use declarations and the examples in the issue. Determine the language-design and implementation work needed for attributes inside use trees, including cfg and allow attributes, and validate that the resulting syntax and semantics match the requested equivalent imports.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.