Repository navigation
Description
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 buildI 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
# - inline
mod demo { #![cfg_attr(enabled, macros::identity)] /* … */ } - outer
#[cfg_attr(enabled, macros::identity)] pub mod demo; - same file with the
cfginactive (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
mejrs commentedon Jul 21, 2026
Possibly #158046?
cc @Dnreikronos @petrochenkov
Dnreikronos commentedon Jul 21, 2026
I will work it!
Ty!
Rollup merge of rust-lang#159695 - Dnreikronos:proc_macro/cfg_attr_fi…
Rollup merge of rust-lang#159695 - Dnreikronos:proc_macro/cfg_attr_fi…
Rollup merge of rust-lang#159695 - Dnreikronos:proc_macro/cfg_attr_fi…
Rollup merge of rust-lang#159695 - Dnreikronos:proc_macro/cfg_attr_fi…
Rollup merge of rust-lang#159695 - Dnreikronos:proc_macro/cfg_attr_fi…
Unrolled build for #159695
Rollup merge of #159695 - Dnreikronos:proc_macro/cfg_attr_file_mod_in…