Skip to content

ICE: compiler/rustc_passes/src/check_attr.rs None #140255

Open
@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

#[unsafe(macro_use::VAR2)]

fn dead_code() {}

original:

#[unsafe(macro_use::VAR2( //~ ERROR: is not an unsafe attribute
    cc = "testing",
))]
trait Foo {}

fn dead_code() {
    let _a = cfg!(unsafe(foo));
    //~^ ERROR: expected identifier, found keyword `unsafe`
    //~^^ ERROR: invalid predicate `r#unsafe`
}

Version information

rustc 1.88.0-nightly (7f695232a 2025-04-24)
binary: rustc
commit-hash: 7f695232a80fa1833e2282f2577c5e1ff066bf39
commit-date: 2025-04-24
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2

Possibly related line of code:

}
_ => {}
}
}
fn check_macro_use(&self, hir_id: HirId, attr: &Attribute, target: Target) {
let name = attr.name().unwrap();
match target {
Target::ExternCrate | Target::Mod => {}
_ => {
self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES,
hir_id,

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

Program output

error: `macro_use::VAR2` is not an unsafe attribute
 --> /tmp/icemaker_global_tempdir.Jaq1ngkHMAmh/rustc_testrunner_tmpdir_reporting.AmsF5wxLrYZy/mvce.rs:1:3
  |
1 | #[unsafe(macro_use::VAR2)]
  |   ^^^^^^ this is not an unsafe attribute
  |
  = note: extraneous unsafe is not allowed in attributes

error[E0433]: failed to resolve: use of unresolved module or unlinked crate `macro_use`
 --> /tmp/icemaker_global_tempdir.Jaq1ngkHMAmh/rustc_testrunner_tmpdir_reporting.AmsF5wxLrYZy/mvce.rs:1:10
  |
1 | #[unsafe(macro_use::VAR2)]
  |          ^^^^^^^^^ use of unresolved module or unlinked crate `macro_use`

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.Jaq1ngkHMAmh/rustc_testrunner_tmpdir_reporting.AmsF5wxLrYZy/mvce.rs:3:18
  |
3 | fn dead_code() {}
  |                  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.Jaq1ngkHMAmh/rustc_testrunner_tmpdir_reporting.AmsF5wxLrYZy/mvce.rs`


thread 'rustc' panicked at compiler/rustc_passes/src/check_attr.rs:2304:32:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:     0x78283dcf1af3 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h6074b4823f65de86
   1:     0x78283e405ac7 - core::fmt::write::h53ca745e7669d6ca
   2:     0x78283f83c151 - std::io::Write::write_fmt::h1d067d18f05b6aaf
   3:     0x78283dcf1952 - std::sys::backtrace::BacktraceLock::print::he4f12001bc479577
   4:     0x78283dcf52ca - std::panicking::default_hook::{{closure}}::h22f056db3b35ba5b
   5:     0x78283dcf4e4f - std::panicking::default_hook::h97f2514df82f96dc
   6:     0x78283cd651f3 - std[31fa69963de3e716]::panicking::update_hook::<alloc[e973a43720220a68]::boxed::Box<rustc_driver_impl[9b6440e8c5aa4392]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x78283dcf5b43 - std::panicking::rust_panic_with_hook::h97fae1d3606b557b
   8:     0x78283dcf5806 - std::panicking::begin_panic_handler::{{closure}}::h4e90c3f0910a708d
   9:     0x78283dcf1fc9 - std::sys::backtrace::__rust_end_short_backtrace::h4c9de78e98ddb0d4
  10:     0x78283dcf54fd - __rustc[de6a073325aecdca]::rust_begin_unwind
  11:     0x78283a68c0d0 - core::panicking::panic_fmt::h82117a00ed7f06bd
  12:     0x78283a69128c - core::panicking::panic::h7c1e3ca4629f43e2
  13:     0x78283a68cba9 - core::option::unwrap_failed::hee23a2b06abad8ea
  14:     0x78283ea6e865 - <rustc_passes[8f2e8035e948caae]::check_attr::CheckAttrVisitor>::check_attributes
  15:     0x78283ea6a29d - <rustc_passes[8f2e8035e948caae]::check_attr::CheckAttrVisitor as rustc_hir[62920335b276a22c]::intravisit::Visitor>::visit_item
  16:     0x78283ea69889 - rustc_passes[8f2e8035e948caae]::check_attr::check_mod_attrs
  17:     0x78283ea69727 - rustc_query_impl[57231a76910cd723]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[57231a76910cd723]::query_impl::check_mod_attrs::dynamic_query::{closure#2}::{closure#0}, rustc_middle[36f8a18d65cfb9c0]::query::erase::Erased<[u8; 0usize]>>
  18:     0x78283f2e291e - rustc_query_system[5da669c39f9bedc5]::query::plumbing::try_execute_query::<rustc_query_impl[57231a76910cd723]::DynamicConfig<rustc_query_system[5da669c39f9bedc5]::query::caches::DefaultCache<rustc_span[c874c8932baed791]::def_id::LocalModDefId, rustc_middle[36f8a18d65cfb9c0]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[57231a76910cd723]::plumbing::QueryCtxt, false>
  19:     0x78283f2e263e - rustc_query_impl[57231a76910cd723]::query_impl::check_mod_attrs::get_query_non_incr::__rust_end_short_backtrace
  20:     0x78283f2e2236 - <rustc_middle[36f8a18d65cfb9c0]::ty::context::TyCtxt>::par_hir_for_each_module::<rustc_interface[290ddbb4ad9de59d]::passes::run_required_analyses::{closure#0}::{closure#0}::{closure#1}::{closure#0}>::{closure#0}
  21:     0x78283ee2db2d - rustc_interface[290ddbb4ad9de59d]::passes::run_required_analyses
  22:     0x78283f2df25e - rustc_interface[290ddbb4ad9de59d]::passes::analysis
  23:     0x78283f2df22d - rustc_query_impl[57231a76910cd723]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[57231a76910cd723]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[36f8a18d65cfb9c0]::query::erase::Erased<[u8; 0usize]>>
  24:     0x78283f2e4cfd - rustc_query_system[5da669c39f9bedc5]::query::plumbing::try_execute_query::<rustc_query_impl[57231a76910cd723]::DynamicConfig<rustc_query_system[5da669c39f9bedc5]::query::caches::SingleCache<rustc_middle[36f8a18d65cfb9c0]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[57231a76910cd723]::plumbing::QueryCtxt, false>
  25:     0x78283f2e49f8 - rustc_query_impl[57231a76910cd723]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  26:     0x78283f6448c0 - rustc_interface[290ddbb4ad9de59d]::passes::create_and_enter_global_ctxt::<core[2cb9221611fcb058]::option::Option<rustc_interface[290ddbb4ad9de59d]::queries::Linker>, rustc_driver_impl[9b6440e8c5aa4392]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  27:     0x78283f4f4c44 - rustc_interface[290ddbb4ad9de59d]::interface::run_compiler::<(), rustc_driver_impl[9b6440e8c5aa4392]::run_compiler::{closure#0}>::{closure#1}
  28:     0x78283f32b5e8 - std[31fa69963de3e716]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[290ddbb4ad9de59d]::util::run_in_thread_with_globals<rustc_interface[290ddbb4ad9de59d]::util::run_in_thread_pool_with_globals<rustc_interface[290ddbb4ad9de59d]::interface::run_compiler<(), rustc_driver_impl[9b6440e8c5aa4392]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  29:     0x78283f32ba34 - <<std[31fa69963de3e716]::thread::Builder>::spawn_unchecked_<rustc_interface[290ddbb4ad9de59d]::util::run_in_thread_with_globals<rustc_interface[290ddbb4ad9de59d]::util::run_in_thread_pool_with_globals<rustc_interface[290ddbb4ad9de59d]::interface::run_compiler<(), rustc_driver_impl[9b6440e8c5aa4392]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[2cb9221611fcb058]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  30:     0x78283f32ce37 - std::sys::pal::unix::thread::Thread::new::thread_start::h54e66dc68950361a
  31:     0x7828392a370a - <unknown>
  32:     0x782839327aac - <unknown>
  33:                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.88.0-nightly (7f695232a 2025-04-24) 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 3 previous errors

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

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) ❄️S-has-bisectionStatus: a bisection has been found for this issueS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-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