Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE: parse: builtin attribute "stable" not handled by CheckAttrVisitor #137590

Open
matthiaskrgr opened this issue Feb 25, 2025 · 2 comments
Open
Assignees
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Feb 25, 2025

auto-reduced (treereduce-rust):

struct S(#[stable::skip] u8, u16, u32);

original:

//@ check-pass

struct S(
    #[stable::skip] u8,
    u16,
    #[tokyo::main] u32,
);

fn main() { println!("{} landed on hir feet" , self . name); }

Version information

rustc 1.87.0-nightly (f5729cfed 2025-02-25)
binary: rustc
commit-hash: f5729cfed3c45e061e8a443677fc1d5ef9277df7
commit-date: 2025-02-25
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0

Possibly related line of code:

Some(BuiltinAttribute { type_: AttributeType::CrateLevel, .. }) => {}
Some(_) => {
// FIXME: differentiate between unstable and internal attributes just
// like we do with features instead of just accepting `rustc_`
// attributes by name. That should allow trimming the above list, too.
if !name.as_str().starts_with("rustc_") {
span_bug!(
attr.span(),
"builtin attribute {name:?} not handled by `CheckAttrVisitor`"
)
}
}
None => (),

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

Program output

error[E0433]: failed to resolve: use of unresolved module or unlinked crate `stable`
 --> /tmp/icemaker_global_tempdir.Pu0CoxkwO27L/rustc_testrunner_tmpdir_reporting.RPLa6XCrNAt2/mvce.rs:1:12
  |
1 | struct S(#[stable::skip] u8, u16, u32);
  |            ^^^^^^ use of unresolved module or unlinked crate `stable`

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.Pu0CoxkwO27L/rustc_testrunner_tmpdir_reporting.RPLa6XCrNAt2/mvce.rs:1:40
  |
1 | struct S(#[stable::skip] u8, u16, u32);
  |                                        ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.Pu0CoxkwO27L/rustc_testrunner_tmpdir_reporting.RPLa6XCrNAt2/mvce.rs`

error: internal compiler error: compiler/rustc_passes/src/check_attr.rs:301:41: builtin attribute "stable" not handled by `CheckAttrVisitor`
 --> /tmp/icemaker_global_tempdir.Pu0CoxkwO27L/rustc_testrunner_tmpdir_reporting.RPLa6XCrNAt2/mvce.rs:1:10
  |
1 | struct S(#[stable::skip] u8, u16, u32);
  |          ^^^^^^^^^^^^^^^


thread 'rustc' panicked at compiler/rustc_passes/src/check_attr.rs:301:41:
Box<dyn Any>
stack backtrace:
   0:     0x7751857b0f34 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hca18af6381e1367c
   1:     0x77518601622c - core::fmt::write::h5592619a5f30a24e
   2:     0x7751870dcbd1 - std::io::Write::write_fmt::hc543125416d93a55
   3:     0x7751857b0d92 - std::sys::backtrace::BacktraceLock::print::h2507b83f5fdb3698
   4:     0x7751857b359e - std::panicking::default_hook::{{closure}}::h25029c6d53322486
   5:     0x7751857b3174 - std::panicking::default_hook::hded85171c110cc3b
   6:     0x77518491a827 - std[581eff941795a880]::panicking::update_hook::<alloc[44b1b4d4d47dda6c]::boxed::Box<rustc_driver_impl[dcc8af57e0e84081]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7751857b3e13 - std::panicking::rust_panic_with_hook::hbe0a3b6f34c80380
   8:     0x775184956cd1 - std[581eff941795a880]::panicking::begin_panic::<rustc_errors[c0f9bdb3918293e2]::ExplicitBug>::{closure#0}
   9:     0x77518494b0e6 - std[581eff941795a880]::sys::backtrace::__rust_end_short_backtrace::<std[581eff941795a880]::panicking::begin_panic<rustc_errors[c0f9bdb3918293e2]::ExplicitBug>::{closure#0}, !>
  10:     0x77518494b0cb - std[581eff941795a880]::panicking::begin_panic::<rustc_errors[c0f9bdb3918293e2]::ExplicitBug>
  11:     0x7751849606c1 - <rustc_errors[c0f9bdb3918293e2]::diagnostic::BugAbort as rustc_errors[c0f9bdb3918293e2]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x775184ea5f4c - <rustc_errors[c0f9bdb3918293e2]::DiagCtxtHandle>::span_bug::<rustc_span[159dd1552b739661]::span_encoding::Span, alloc[44b1b4d4d47dda6c]::string::String>
  13:     0x775184f27e1a - rustc_middle[e6f8bc74c8fc856c]::util::bug::opt_span_bug_fmt::<rustc_span[159dd1552b739661]::span_encoding::Span>::{closure#0}
  14:     0x775184f113aa - rustc_middle[e6f8bc74c8fc856c]::ty::context::tls::with_opt::<rustc_middle[e6f8bc74c8fc856c]::util::bug::opt_span_bug_fmt<rustc_span[159dd1552b739661]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  15:     0x775184f1121b - rustc_middle[e6f8bc74c8fc856c]::ty::context::tls::with_context_opt::<rustc_middle[e6f8bc74c8fc856c]::ty::context::tls::with_opt<rustc_middle[e6f8bc74c8fc856c]::util::bug::opt_span_bug_fmt<rustc_span[159dd1552b739661]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  16:     0x77518373ac07 - rustc_middle[e6f8bc74c8fc856c]::util::bug::span_bug_fmt::<rustc_span[159dd1552b739661]::span_encoding::Span>
  17:     0x7751863f8f9d - <rustc_passes[6ccbb36aefae929c]::check_attr::CheckAttrVisitor>::check_attributes
  18:     0x7751863f5d74 - <rustc_passes[6ccbb36aefae929c]::check_attr::CheckAttrVisitor as rustc_hir[2b60df8069066663]::intravisit::Visitor>::visit_item
  19:     0x77518640ba41 - rustc_passes[6ccbb36aefae929c]::check_attr::check_mod_attrs
  20:     0x77518640b9cb - rustc_query_impl[c32460660d187a22]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c32460660d187a22]::query_impl::check_mod_attrs::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e6f8bc74c8fc856c]::query::erase::Erased<[u8; 0usize]>>
  21:     0x7751870743c1 - rustc_query_system[e93ee9904dcaa7d1]::query::plumbing::try_execute_query::<rustc_query_impl[c32460660d187a22]::DynamicConfig<rustc_query_system[e93ee9904dcaa7d1]::query::caches::DefaultCache<rustc_span[159dd1552b739661]::def_id::LocalModDefId, rustc_middle[e6f8bc74c8fc856c]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[c32460660d187a22]::plumbing::QueryCtxt, false>
  22:     0x7751870740bf - rustc_query_impl[c32460660d187a22]::query_impl::check_mod_attrs::get_query_non_incr::__rust_end_short_backtrace
  23:     0x775187073c5c - <rustc_middle[e6f8bc74c8fc856c]::ty::context::TyCtxt>::par_hir_for_each_module::<rustc_interface[5317c0be442ff202]::passes::run_required_analyses::{closure#0}::{closure#0}::{closure#1}::{closure#0}>::{closure#0}
  24:     0x7751863b4f56 - rustc_interface[5317c0be442ff202]::passes::run_required_analyses
  25:     0x77518707633a - rustc_interface[5317c0be442ff202]::passes::analysis
  26:     0x775187076319 - rustc_query_impl[c32460660d187a22]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c32460660d187a22]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e6f8bc74c8fc856c]::query::erase::Erased<[u8; 0usize]>>
  27:     0x7751870d5e8b - rustc_query_system[e93ee9904dcaa7d1]::query::plumbing::try_execute_query::<rustc_query_impl[c32460660d187a22]::DynamicConfig<rustc_query_system[e93ee9904dcaa7d1]::query::caches::SingleCache<rustc_middle[e6f8bc74c8fc856c]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[c32460660d187a22]::plumbing::QueryCtxt, false>
  28:     0x7751870d5b79 - rustc_query_impl[c32460660d187a22]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  29:     0x77518715903c - rustc_interface[5317c0be442ff202]::passes::create_and_enter_global_ctxt::<core[f5b0be8ed3a1b4e]::option::Option<rustc_interface[5317c0be442ff202]::queries::Linker>, rustc_driver_impl[dcc8af57e0e84081]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  30:     0x7751870e7ee0 - rustc_interface[5317c0be442ff202]::interface::run_compiler::<(), rustc_driver_impl[dcc8af57e0e84081]::run_compiler::{closure#0}>::{closure#1}
  31:     0x775186fa1ac8 - std[581eff941795a880]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[5317c0be442ff202]::util::run_in_thread_with_globals<rustc_interface[5317c0be442ff202]::util::run_in_thread_pool_with_globals<rustc_interface[5317c0be442ff202]::interface::run_compiler<(), rustc_driver_impl[dcc8af57e0e84081]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  32:     0x775186fa2274 - <<std[581eff941795a880]::thread::Builder>::spawn_unchecked_<rustc_interface[5317c0be442ff202]::util::run_in_thread_with_globals<rustc_interface[5317c0be442ff202]::util::run_in_thread_pool_with_globals<rustc_interface[5317c0be442ff202]::interface::run_compiler<(), rustc_driver_impl[dcc8af57e0e84081]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[f5b0be8ed3a1b4e]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  33:     0x775186fa376f - std::sys::pal::unix::thread::Thread::new::thread_start::h717201ab54b439ec
  34:     0x7751810a370a - <unknown>
  35:     0x775181127aac - <unknown>
  36:                0x0 - <unknown>

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.87.0-nightly (f5729cfed 2025-02-25) 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`.

@matthiaskrgr matthiaskrgr added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 25, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 25, 2025
@workingjubilee workingjubilee added the A-attributes Area: Attributes (`#[…]`, `#![…]`) label Feb 25, 2025
@jdonszelmann
Copy link
Contributor

@rustbot claim

@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 25, 2025
@jdonszelmann
Copy link
Contributor

jdonszelmann commented Feb 25, 2025

this is a subtle bug where the attribute both isn't parsed with the new attr parsing system, nor is validated anymore (since validation used to validate even when stable was followed by more segments). In the future, we can automatically reject any attribute that isn't parsed using a new-style parser. However, until all of those are there, we can't reject any attribute simply because no parser parsed it since maybe that attribute simply doesn't have a new style parser yet.

So, after talking about it a little with others on discord we thought it's probably best to keep these ICEs around. this used to be an error, now it's an ICE. Removing the ICE check would make new attributes without a new-style parser silently have real bugs which are harder to find and which is a bit spookier than this ICE in rare cases.

This does mean that any attribute we convert to a new style parser will have a corresponding bug exactly like this one where the first segment is a valid new-style attribute and we don't validate it causing this ICE. We can remove the check completely when all attrs are converted, because we can simply exhaustively match on the enum of AttributeKinds making this a compile time error.

Feel free to assign any issue exactly like this one to me, I'll close them all in a few months.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants