Skip to content

ICE: can't get the span of an arbitrary parsed attribute #142783

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

#[inline]
#[track_caller]
macro_rules! contained {
    () => {};
}

original:

#[inline]
#[track_caller]
macro_rules! contained { () => {} }

pub fn main() {}

Version information

rustc 1.89.0-nightly (3b97f1308 2025-06-20)
binary: rustc
commit-hash: 3b97f1308ff72016a4aaa93fbe6d09d4d6427815
commit-date: 2025-06-20
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.7

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

warning: unused macro definition: `contained`
 --> /tmp/icemaker_global_tempdir.h2zBL4aoaUWH/rustc_testrunner_tmpdir_reporting.EsRoILp2XH1B/mvce.rs:3:14
  |
3 | macro_rules! contained {
  |              ^^^^^^^^^
  |
  = note: `#[warn(unused_macros)]` on by default

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.h2zBL4aoaUWH/rustc_testrunner_tmpdir_reporting.EsRoILp2XH1B/mvce.rs:5:2
  |
5 | }
  |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.h2zBL4aoaUWH/rustc_testrunner_tmpdir_reporting.EsRoILp2XH1B/mvce.rs`

error[E0518]: attribute should be applied to function or closure
 --> /tmp/icemaker_global_tempdir.h2zBL4aoaUWH/rustc_testrunner_tmpdir_reporting.EsRoILp2XH1B/mvce.rs:1:1
  |
1 | #[inline]
  | ^^^^^^^^^ not a function or closure

warning: `#[track_caller]` is ignored on struct fields, match arms and macro defs
 --> /tmp/icemaker_global_tempdir.h2zBL4aoaUWH/rustc_testrunner_tmpdir_reporting.EsRoILp2XH1B/mvce.rs:2:1
  |
2 | #[track_caller]
  | ^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_attributes)]` on by default


thread 'rustc' panicked at /rustc-dev/3b97f1308ff72016a4aaa93fbe6d09d4d6427815/compiler/rustc_hir/src/hir.rs:1305:18:
can't get the span of an arbitrary parsed attribute: Parsed(Inline(Hint, /tmp/icemaker_global_tempdir.h2zBL4aoaUWH/rustc_testrunner_tmpdir_reporting.EsRoILp2XH1B/mvce.rs:1:1: 1:10 (#0)))
stack backtrace:
   0:     0x796ff7ce3033 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hdb1beb1efd036030
   1:     0x796ff8402d3f - core::fmt::write::h6fde5d988b046e43
   2:     0x796ff7cd8cc3 - std::io::Write::write_fmt::hfdc56ad9972213fb
   3:     0x796ff7ce2e92 - std::sys::backtrace::BacktraceLock::print::h7d50fbfbc01ef440
   4:     0x796ff7ce698a - std::panicking::default_hook::{{closure}}::h2d0b345b2d72c7b1
   5:     0x796ff7ce650f - std::panicking::default_hook::he0e1084842380634
   6:     0x796ff6ddc397 - std[6b85dd0cacdad3fb]::panicking::update_hook::<alloc[e197c52ffb0c953d]::boxed::Box<rustc_driver_impl[b5010b6a00a10337]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x796ff7ce71db - std::panicking::rust_panic_with_hook::h551040e3eccc63b8
   8:     0x796ff7ce6eda - std::panicking::begin_panic_handler::{{closure}}::h82732907cb122ecc
   9:     0x796ff7ce3509 - std::sys::backtrace::__rust_end_short_backtrace::h8d0b6d7b81e6f1ec
  10:     0x796ff7ce6bbd - __rustc[e49b1424bdfe04fc]::rust_begin_unwind
  11:     0x796ff448fbc0 - core::panicking::panic_fmt::h2de75984da6179f3
  12:     0x796ff8ae0d9f - <rustc_passes[ed7886fbdff4a823]::check_attr::CheckAttrVisitor>::check_attributes
  13:     0x796ff8ad7c86 - <rustc_passes[ed7886fbdff4a823]::check_attr::CheckAttrVisitor as rustc_hir[cd02d9627a3ada87]::intravisit::Visitor>::visit_item
  14:     0x796ff8ad71bf - rustc_passes[ed7886fbdff4a823]::check_attr::check_mod_attrs
  15:     0x796ff8ad7061 - rustc_query_impl[7d775a893a945633]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7d775a893a945633]::query_impl::check_mod_attrs::dynamic_query::{closure#2}::{closure#0}, rustc_middle[cffb9c37e6e9a24b]::query::erase::Erased<[u8; 0usize]>>
  16:     0x796ff928d058 - rustc_query_system[2228cb53b85e8de8]::query::plumbing::try_execute_query::<rustc_query_impl[7d775a893a945633]::DynamicConfig<rustc_query_system[2228cb53b85e8de8]::query::caches::DefaultCache<rustc_span[fb51e5d36bb23ffe]::def_id::LocalModDefId, rustc_middle[cffb9c37e6e9a24b]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[7d775a893a945633]::plumbing::QueryCtxt, false>
  17:     0x796ff928cd7d - rustc_query_impl[7d775a893a945633]::query_impl::check_mod_attrs::get_query_non_incr::__rust_end_short_backtrace
  18:     0x796ff928ca1b - <rustc_middle[cffb9c37e6e9a24b]::ty::context::TyCtxt>::par_hir_for_each_module::<rustc_interface[400f48cd83754571]::passes::run_required_analyses::{closure#0}::{closure#0}::{closure#1}::{closure#0}>::{closure#0}
  19:     0x796ff8ed7e8b - rustc_interface[400f48cd83754571]::passes::analysis
  20:     0x796ff8ed7bad - rustc_query_impl[7d775a893a945633]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7d775a893a945633]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[cffb9c37e6e9a24b]::query::erase::Erased<[u8; 0usize]>>
  21:     0x796ff94a1d3c - rustc_query_system[2228cb53b85e8de8]::query::plumbing::try_execute_query::<rustc_query_impl[7d775a893a945633]::DynamicConfig<rustc_query_system[2228cb53b85e8de8]::query::caches::SingleCache<rustc_middle[cffb9c37e6e9a24b]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[7d775a893a945633]::plumbing::QueryCtxt, false>
  22:     0x796ff94a1a12 - rustc_query_impl[7d775a893a945633]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  23:     0x796ff960ee96 - rustc_interface[400f48cd83754571]::passes::create_and_enter_global_ctxt::<core[913fe49cdece82e8]::option::Option<rustc_interface[400f48cd83754571]::queries::Linker>, rustc_driver_impl[b5010b6a00a10337]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  24:     0x796ff9627963 - rustc_interface[400f48cd83754571]::interface::run_compiler::<(), rustc_driver_impl[b5010b6a00a10337]::run_compiler::{closure#0}>::{closure#1}
  25:     0x796ff9651402 - std[6b85dd0cacdad3fb]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[400f48cd83754571]::util::run_in_thread_with_globals<rustc_interface[400f48cd83754571]::util::run_in_thread_pool_with_globals<rustc_interface[400f48cd83754571]::interface::run_compiler<(), rustc_driver_impl[b5010b6a00a10337]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  26:     0x796ff96510e6 - <<std[6b85dd0cacdad3fb]::thread::Builder>::spawn_unchecked_<rustc_interface[400f48cd83754571]::util::run_in_thread_with_globals<rustc_interface[400f48cd83754571]::util::run_in_thread_pool_with_globals<rustc_interface[400f48cd83754571]::interface::run_compiler<(), rustc_driver_impl[b5010b6a00a10337]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[913fe49cdece82e8]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  27:     0x796ff964f73d - std::sys::pal::unix::thread::Thread::new::thread_start::ha32bf3e026b53de8
  28:     0x796ff30a57eb - <unknown>
  29:     0x796ff312918c - <unknown>
  30:                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: rustc 1.89.0-nightly (3b97f1308 2025-06-20) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [check_mod_attrs] checking attributes in top-level module
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors; 2 warnings emitted

Some errors have detailed explanations: E0518, E0601.
For more information about an error, try `rustc --explain E0518`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesArea: Attributes (`#[…]`, `#![…]`)C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions