Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Regression: proc-macro inner attribute via cfg_attr on out-of-line module fails with "unclosed delimiter" #159648

Closed

Description

@JurajSadel

Code

I tried this code:

A proc-macro attribute used as an inner attribute on an out-of-line (file) module, gated behind cfg_attr, fails to parse when the cfg is active.

macros/src/lib.rs (proc-macro crate):

use proc_macro::TokenStream;

#[proc_macro_attribute]
pub fn identity(_attr: TokenStream, input: TokenStream) -> TokenStream {
    input
}

Cargo.toml:

[package]
name = "reproducer"
version = "0.1.0"
edition = "2024"

[dependencies]
macros = { path = "macros" }

src/lib.rs:

#![feature(custom_inner_attributes, proc_macro_hygiene)]

pub mod demo;

src/demo.rs:

#![cfg_attr(enabled, macros::identity)]
//! docs

Build with the cfg active:

RUSTFLAGS='--cfg enabled' cargo +nightly build

I expected to see this happen: the crate compiles, exactly as it does on nightly-2026-07-19 (and as it still does when the cfg is inactive so the attribute is stripped).

Instead, this happened: the file fails to parse.

error: this file contains an unclosed delimiter
 --> src/demo.rs:1:22
  |
1 | #![cfg_attr(enabled, macros::identity)]
  |   -        -         ^
  |   |        |
  |   |        unclosed delimiter
  |   unclosed delimiter

error: could not compile `reproducer` (lib) due to 1 previous error

The failure is specific to the cfg_attr-wrapped proc-macro inner attribute on an out-of-line module. These all still work:

  • direct #![macros::identity] (no cfg_attr)
  • inline mod demo { #![cfg_attr(enabled, macros::identity)] /* … */ }
  • outer #[cfg_attr(enabled, macros::identity)] pub mod demo;
  • same file with the cfg inactive (attribute stripped)

Fails on both cargo build and cargo doc.

Real-world impact: broke esp-hal nightly CI, which uses #![cfg_attr(docsrs, procmacros::doc_replace)] on ~45 module files.

Version it worked on

It most recently worked on: nightly-2026-07-19 (rustc eff8269f7 2026-07-18)

Version with regression

rustc --version --verbose:

rustc 1.99.0-nightly (87e5904f5 2026-07-20)
binary: rustc
commit-hash: 87e5904f5eb6398af6b22eac2802c78934260c48
commit-date: 2026-07-20
host: x86_64-unknown-linux-gnu
release: 1.99.0-nightly

Backtrace

Backtrace

No backtrace — parse error, not an ICE.

@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged +A-proc-macros +A-parser +F-custom_inner_attributes

Activity

  1. added
    C-bug
    regression-untriaged
    on Jul 21, 2026
  2. added
    needs-triage
    I-prioritize
    A-parser
    A-proc-macros
    F-custom_inner_attributes
    regression-from-stable-to-nightly
    and removed
    regression-untriaged
    on Jul 21, 2026
  3. mejrs commented on Jul 21, 2026

    @mejrs
    Member
  4. Dnreikronos commented on Jul 21, 2026

    @Dnreikronos
    Contributor

    Possibly #158046?

    cc @Dnreikronos @petrochenkov

    I will work it!
    Ty!

  5. added
    T-compiler
    and removed
    I-prioritize
    needs-triage
    on Jul 23, 2026
  6. added a commit that references this issue on Jul 25, 2026
    3974fe5
  7. added 2 commits that reference this issue on Jul 25, 2026
    e464af0
    43759b2
  8. added 2 commits that reference this issue on Jul 26, 2026
    5700c74
    0a72846
  9. added a commit that references this issue on Jul 26, 2026
    becec03
  10. added a commit that references this issue on Jul 27, 2026
    fc5d00d
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-parserA-proc-macrosC-bugF-custom_inner_attributesT-compilerregression-from-stable-to-nightly

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions