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 · 8 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 · 8 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) ❄️ P-high High priority 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 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
Copy link
Contributor

Minimized from the levi repo (from the crater results):

src/lib.rs:

macro_rules! call_macro {
    ($text:expr) => {
        #[derive(bar::Bar)]
        #[arg($text)]
        pub struct Foo;
    };
}

call_macro!(1 + 1);

bar/src/lib.rs

extern crate proc_macro;

use proc_macro::TokenStream;

#[proc_macro_derive(Bar, attributes(arg))]
pub fn derive_bar(_: proc_macro::TokenStream) -> proc_macro::TokenStream {
    TokenStream::new()
}

Zip of all files required for reproduction: repro.zip

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) ❄️ P-high High priority 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
8 participants