Skip to content

Permit attributes on use items #141704

Open
Feature Request
@jhpratt

Description

@jhpratt
Member

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

Activity

added
A-attributesArea: Attributes (`#[…]`, `#![…]`)
A-grammarArea: The grammar of Rust
T-langRelevant to the language team
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.
I-lang-easy-decisionIssue: The decision needed by the team is conjectured to be easy; this does not imply nomination
on May 28, 2025
added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on May 28, 2025
removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on May 28, 2025
traviscross

traviscross commented on May 28, 2025

@traviscross
Contributor

@rustbot labels -I-lang-easy-decision +I-lang-nominated +P-lang-drag-2

Thanks for the question.

(Regarding the label, history has shown that questions of where to allow attributes have never been easy.)

added
I-lang-nominatedNominated for discussion during a lang team meeting.
P-lang-drag-2Lang team prioritization drag level 2.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang.
and removed
I-lang-easy-decisionIssue: The decision needed by the team is conjectured to be easy; this does not imply nomination
on May 28, 2025
jhpratt

jhpratt commented on May 29, 2025

@jhpratt
MemberAuthor

Fair enough on the label. It couldn't hurt to try 😅

added
A-resolveArea: Name/path resolution done by `rustc_resolve` specifically
on May 29, 2025
caibirdme

caibirdme commented on Jun 11, 2025

@caibirdme

It's a little bit hard to read what crates are included in the current scope. I think your second code is more intuitive:

use crate::{alpha, beta};
#[cfg(feature = "foo")]
use crate::gamma;
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-attributesArea: Attributes (`#[…]`, `#![…]`)A-grammarArea: The grammar of RustA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-feature-requestCategory: A feature request, i.e: not implemented / a PR.I-lang-nominatedNominated for discussion during a lang team meeting.P-lang-drag-2Lang team prioritization drag level 2.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang.T-langRelevant to the language team

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @traviscross@jhpratt@caibirdme@jieyouxu@rustbot

        Issue actions

          Permit attributes on `use` items · Issue #141704 · rust-lang/rust