Skip to content

[ICE]: "attribute is missing tokens" on #[test] #[procmacro] #159261

Description

@dtolnay

Since #158854, the following causes ICE. Minimized from https://github.com/dtolnay/remain.

# Cargo.toml

[package]
name = "repro"
edition = "2024"
publish = false

[lib]
proc-macro = true
// src/lib.rs

use proc_macro::TokenStream;

#[proc_macro_attribute]
pub fn repro(_args: TokenStream, input: TokenStream) -> TokenStream {
    input
}
// src/main.rs

fn main() {}

#[test]
#[repro::repro]
fn test() {}
$ cargo check --tests

thread 'rustc' (2173850) panicked at /rustc-dev/daf2e5e18b3abc4311d9da3d96fd64138f43d508/compiler/rustc_ast/src/attr/mod.rs:307:36:
attribute is missing tokens: Attribute { kind: Normal(NormalAttr { item: AttrItem { unsafety: Default, path: Path { span: src/main.rs:3:1: 3:8 (#4), segments: [PathSegment { ident: rustc_test_entrypoint_marker#4, id: NodeId(4294967040), args: None }] }, args: Unparsed(Empty) }, tokens: None }), id: AttrId(7), style: Outer, span: src/main.rs:3:1: 3:8 (#4) }
stack backtrace:
   0:     0x792d51a0a6b6 - <<std[ce10694b78262c54]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[da78e946a5d06d53]::fmt::Display>::fmt
   1:     0x792d5200ec88 - core[da78e946a5d06d53]::fmt::write
   2:     0x792d51a1fb2c - <std[ce10694b78262c54]::sys::stdio::unix::Stderr as core[da78e946a5d06d53]::io::write::Write>::write_fmt
   3:     0x792d519dea3a - std[ce10694b78262c54]::panicking::default_hook::{closure#0}
   4:     0x792d519fcdd3 - std[ce10694b78262c54]::panicking::default_hook
   5:     0x792d509ca65b - std[ce10694b78262c54]::panicking::update_hook::<alloc[655ffa9be629a963]::boxed::Box<rustc_driver_impl[b7363d31c325300f]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x792d519fd272 - std[ce10694b78262c54]::panicking::panic_with_hook
   7:     0x792d519deaf2 - std[ce10694b78262c54]::panicking::panic_handler::{closure#0}
   8:     0x792d519d57b9 - std[ce10694b78262c54]::sys::backtrace::__rust_end_short_backtrace::<std[ce10694b78262c54]::panicking::panic_handler::{closure#0}, !>
   9:     0x792d519e044d - __rustc[4c31565a732afefe]::rust_begin_unwind
  10:     0x792d4e7446cc - core[da78e946a5d06d53]::panicking::panic_fmt
  11:     0x792d52bb6b56 - <rustc_ast[bf92cb4a89c1d262]::ast::Attribute>::token_trees
  12:     0x792d536bcc62 - <rustc_expand[4c42811765bd8a03]::expand::MacroExpander>::fully_expand_fragment
  13:     0x792d5368bfd4 - <rustc_expand[4c42811765bd8a03]::expand::MacroExpander>::expand_crate
  14:     0x792d5278e711 - rustc_interface[2fb4e3f9120b3398]::passes::resolver_for_lowering_raw
  15:     0x792d5278df26 - rustc_query_impl[2043934c093d5d4c]::query_impl::resolver_for_lowering_raw::invoke_provider_fn::__rust_begin_short_backtrace
  16:     0x792d5350c161 - rustc_query_impl[2043934c093d5d4c]::execution::try_execute_query::<rustc_middle[e97f70cd95bc576c]::query::caches::SingleCache<rustc_middle[e97f70cd95bc576c]::query::erase::ErasedData<[u8; 24usize]>>, true>
  17:     0x792d5350bc10 - rustc_query_impl[2043934c093d5d4c]::query_impl::resolver_for_lowering_raw::execute_query_incr::__rust_end_short_backtrace
  18:     0x792d531032c0 - rustc_interface[2fb4e3f9120b3398]::interface::run_compiler::<(), rustc_driver_impl[b7363d31c325300f]::run_compiler::{closure#0}>::{closure#1}
  19:     0x792d5316b73a - std[ce10694b78262c54]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[2fb4e3f9120b3398]::util::run_in_thread_with_globals<rustc_interface[2fb4e3f9120b3398]::util::run_in_thread_pool_with_globals<rustc_interface[2fb4e3f9120b3398]::interface::run_compiler<(), rustc_driver_impl[b7363d31c325300f]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  20:     0x792d5316b4ed - <std[ce10694b78262c54]::thread::lifecycle::spawn_unchecked<rustc_interface[2fb4e3f9120b3398]::util::run_in_thread_with_globals<rustc_interface[2fb4e3f9120b3398]::util::run_in_thread_pool_with_globals<rustc_interface[2fb4e3f9120b3398]::interface::run_compiler<(), rustc_driver_impl[b7363d31c325300f]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[da78e946a5d06d53]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  21:     0x792d5316f910 - <std[ce10694b78262c54]::sys::thread::unix::Thread>::new::thread_start
  22:     0x792d4caa3d64 - start_thread
                               at ./nptl/pthread_create.c:448:8
  23:     0x792d4cb373fc - __GI___clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78:0
  24:                0x0 - <unknown>

error: the compiler unexpectedly panicked. This is a bug

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please make sure that you have updated to the latest nightly

note: please attach the file at `/git/repro/rustc-ice-2026-07-14T03_03_04-2173848.txt` to your bug report

note: rustc 1.99.0-nightly (daf2e5e18 2026-07-13) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [resolver_for_lowering_raw] getting the resolver for lowering
end of query stack
error: could not compile `repro` (bin "repro" test)

Caused by:
  process didn't exit successfully: `/home/david/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name repro --edition=2024 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=118 --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 --test --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=27b1a61dcdf6880e -C extra-filename=-9e67cf72997e0fed --out-dir /git/repro/target/debug/deps -C incremental=/git/repro/target/debug/incremental -L dependency=/git/repro/target/debug/deps --extern repro=/git/repro/target/debug/deps/librepro-17a7318b6b244c7c.so` (exit status: 101)

@jdonszelmann @JonathanBrouwer

Metadata

Metadata

Assignees

Labels

A-attributesArea: Attributes (`#[…]`, `#![…]`)A-libtestArea: `#[test]` / the `test` libraryA-proc-macrosArea: Procedural macrosC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}S-has-bisectionStatus: A bisection has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions