Skip to content

ICE: expr in place where literal is expected (builtin attr parsing) #137687

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

Open
matthiaskrgr opened this issue Feb 26, 2025 · 11 comments · May be fixed by #137729
Open

ICE: expr in place where literal is expected (builtin attr parsing) #137687

matthiaskrgr opened this issue Feb 26, 2025 · 11 comments · May be fixed by #137729
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) ❄️ I-prioritize Issue: Indicates that prioritization has been requested for this issue. regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Milestone

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Feb 26, 2025

auto-reduced (treereduce-rust):

//@compile-flags: --crate-type=lib
#[crate_name = concat!("Cloneb")]

macro_rules! inline {
    () => {};
}

original:

#[crate_name = concat!("Cloneb")]
macro_rules! mac {
    ($ident:ident) => { let $ident = 42; }
}

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

Version information

rustc 1.87.0-nightly (ac91805f3 2025-02-26)
binary: rustc
commit-hash: ac91805f3179fc2225c60e8ccf5a1daa09d43f3d
commit-date: 2025-02-26
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc --crate-type=lib

Program output

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

warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
 --> /tmp/icemaker_global_tempdir.o4pBxOKZHwPg/rustc_testrunner_tmpdir_reporting.DGIJGRHWWShI/mvce.rs:1:1
  |
1 | #[crate_name = concat!("Cloneb")]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_attributes)]` on by default

warning: 2 warnings emitted

note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: expr in place where literal is expected (builtin attr parsing)
 --> /tmp/icemaker_global_tempdir.o4pBxOKZHwPg/rustc_testrunner_tmpdir_reporting.DGIJGRHWWShI/mvce.rs:1:14
  |
1 | #[crate_name = concat!("Cloneb")]
  |              ^
  |
note: delayed at compiler/rustc_attr_parsing/src/parser.rs:359:24
         0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         1: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
         2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
         3: <rustc_errors::DiagCtxtHandle>::span_delayed_bug::<rustc_span::span_encoding::Span, &str>
         4: <rustc_attr_parsing::parser::MetaItemParser>::from_attr
         5: <rustc_resolve::def_collector::DefCollector as rustc_ast::visit::Visitor>::visit_item
         6: <rustc_resolve::def_collector::DefCollector as rustc_ast::visit::Visitor>::visit_crate
         7: <rustc_resolve::Resolver as rustc_expand::base::ResolverExpand>::visit_ast_fragment_with_placeholders
         8: <rustc_expand::expand::MacroExpander>::collect_invocations
         9: <rustc_expand::expand::MacroExpander>::fully_expand_fragment
        10: <rustc_expand::expand::MacroExpander>::expand_crate
        11: rustc_interface::passes::resolver_for_lowering_raw
        12: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 16]>>
        13: <rustc_query_impl::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, ())>>::call_once
        14: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 16]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        15: rustc_query_impl::query_impl::resolver_for_lowering_raw::get_query_non_incr::__rust_end_short_backtrace
        16: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
        17: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
        18: std::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
        19: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        20: std::sys::pal::unix::thread::Thread::new::thread_start
        21: <unknown>
        22: <unknown>
 --> /tmp/icemaker_global_tempdir.o4pBxOKZHwPg/rustc_testrunner_tmpdir_reporting.DGIJGRHWWShI/mvce.rs:1:14
  |
1 | #[crate_name = concat!("Cloneb")]
  |              ^

error: internal compiler error: expr in place where literal is expected (builtin attr parsing)
 --> /tmp/icemaker_global_tempdir.o4pBxOKZHwPg/rustc_testrunner_tmpdir_reporting.DGIJGRHWWShI/mvce.rs:1:1
  |
1 | #[crate_name = concat!("Cloneb")]
  | ^^^^^^^^^^^^^^
  |
note: delayed at /rustc/ac91805f3179fc2225c60e8ccf5a1daa09d43f3d/compiler/rustc_attr_parsing/src/context.rs:336:43
         0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         1: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
         2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
         3: <rustc_errors::DiagCtxtHandle>::span_delayed_bug::<rustc_span::span_encoding::Span, &str>
         4: <rustc_resolve::def_collector::DefCollector as rustc_ast::visit::Visitor>::visit_item
         5: <rustc_resolve::def_collector::DefCollector as rustc_ast::visit::Visitor>::visit_crate
         6: <rustc_resolve::Resolver as rustc_expand::base::ResolverExpand>::visit_ast_fragment_with_placeholders
         7: <rustc_expand::expand::MacroExpander>::collect_invocations
         8: <rustc_expand::expand::MacroExpander>::fully_expand_fragment
         9: <rustc_expand::expand::MacroExpander>::expand_crate
        10: rustc_interface::passes::resolver_for_lowering_raw
        11: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 16]>>
        12: <rustc_query_impl::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, ())>>::call_once
        13: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 16]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        14: rustc_query_impl::query_impl::resolver_for_lowering_raw::get_query_non_incr::__rust_end_short_backtrace
        15: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
        16: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
        17: std::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
        18: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        19: std::sys::pal::unix::thread::Thread::new::thread_start
        20: <unknown>
        21: <unknown>
 --> /tmp/icemaker_global_tempdir.o4pBxOKZHwPg/rustc_testrunner_tmpdir_reporting.DGIJGRHWWShI/mvce.rs:1:1
  |
1 | #[crate_name = concat!("Cloneb")]
  | ^^^^^^^^^^^^^^

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 (ac91805f3 2025-02-26) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -Z dump-mir-dir=dir

query stack during panic:
end of query stack

@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 26, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 26, 2025
@matthiaskrgr
Copy link
Member Author

smaller

#[crate_name = concat !()]
macro_rules !a {
  () => {}
}
fn main() {}

@matthiaskrgr matthiaskrgr added A-attributes Area: Attributes (`#[…]`, `#![…]`) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 26, 2025
@cyrgani
Copy link
Contributor

cyrgani commented Feb 26, 2025

cc @jdonszelmann

@jdonszelmann
Copy link
Contributor

Here we go again 😂. @rustbot claim

@jdonszelmann
Copy link
Contributor

Ah, crate_name probably has similar exceptions as crate type from last time. I know how to fix so that's good :)

@fmease
Copy link
Member

fmease commented Feb 26, 2025

Ah, crate_name probably has similar exceptions as crate type from last time.

Yes :) albeit more recent and even stricter: #127581 (merged two weeks ago) :D

@cuviper

This comment has been minimized.

@cuviper cuviper added the regression-from-stable-to-beta Performance or correctness regression from stable to beta. label Apr 18, 2025
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Apr 18, 2025
@cuviper cuviper added this to the 1.87.0 milestone Apr 18, 2025
@apiraino
Copy link
Contributor

Assigning priority (discussion on Zulip).

@rustbot label -I-prioritize +P-high

@rustbot rustbot added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Apr 19, 2025
@theemathas

This comment has been minimized.

jdonszelmann added a commit to jdonszelmann/rust that referenced this issue May 2, 2025
jdonszelmann added a commit to jdonszelmann/rust that referenced this issue May 2, 2025
@fmease
Copy link
Member

fmease commented May 2, 2025

Nota bene: Matthias's ICE != the 3 ICEs from the crater regression! Matthias's ICE triggers the delayed_span_bugs found in compiler/rustc_attr_parsing/src/parser.rs:359:24 and compiler/rustc_attr_parsing/src/context.rs:336:43 while the crater regressions and theemathas's MCVE trigger a different one, namely compiler/rustc_attr_parsing/src/parser.rs:498:34.

This is relevant/important because PR #124141 unintentionally fixed the crater regressions on master but not Matthias's issue (of which we don't know if it's likely to be hit by real users and thus worth hotfixing on beta). For that, subscribe to draft PR #140584.

@jieyouxu
Copy link
Member

jieyouxu commented May 3, 2025

NOTE: reading two separate issues in a trenchcoat is really confusing me, so I pulled out the crater regression into a separate issue #140612 to make it clear we're tracking two different issues. I've reproduced the comments pertaining to the crater regressions in #140612, and I'll mark the comment pertaining to the crater regressions on this issue as off-topic to prevent it from being way too confusing. I'll also update the PRs that backlink this issue if suitable.

@jieyouxu
Copy link
Member

jieyouxu commented May 3, 2025

Re. this regression, we may want to revisit its prioritization.
@rustbot label: -P-high +I-prioritize

@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. and removed P-high High priority labels May 3, 2025
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) ❄️ I-prioritize Issue: Indicates that prioritization has been requested for this issue. regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
9 participants