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: adding a def'n for node-id NodeId(13) and def kind AnonConst but a previous def'n exists: DefKey #131915

Closed
matthiaskrgr opened this issue Oct 19, 2024 · 1 comment · Fixed by #132653
Assignees
Labels
A-ast Area: AST A-HIR Area: The high-level intermediate representation (HIR) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

macro_rules! y {
    ( $($matcher:tt)*) => {
        x
    };
}

const _: A<
    {
        y! { test.tou8 }
    },
>;

original:

macro_rules! y {
    ($macro_name:tt $($matcher:tt)*) => {
        x
    };
}

const _: A<{ y!{ test.tou8 } }>;

Version information

rustc 1.84.0-nightly (b27f33a4d 2024-10-19)
binary: rustc
commit-hash: b27f33a4d9c42ee6b5347a75a8a990a883437da9
commit-date: 2024-10-19
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1

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

Program output

error: free constant item without body
  --> /tmp/icemaker_global_tempdir.AdIxA8iQnjEG/rustc_testrunner_tmpdir_reporting.XHKTAGkfAHi1/mvce.rs:7:1
   |
7  | / const _: A<
8  | |     {
9  | |         y! { test.tou8 }
10 | |     },
11 | | >;
   | |  ^ help: provide a definition for the constant: `= <expr>;`
   | |__|
   |

error[E0412]: cannot find type `A` in this scope
 --> /tmp/icemaker_global_tempdir.AdIxA8iQnjEG/rustc_testrunner_tmpdir_reporting.XHKTAGkfAHi1/mvce.rs:7:10
  |
7 | const _: A<
  |          ^ not found in this scope

error[E0425]: cannot find value `x` in this scope
 --> /tmp/icemaker_global_tempdir.AdIxA8iQnjEG/rustc_testrunner_tmpdir_reporting.XHKTAGkfAHi1/mvce.rs:3:9
  |
3 |         x
  |         ^ not found in this scope
...
9 |         y! { test.tou8 }
  |         ---------------- in this macro invocation
  |
  = note: this error originates in the macro `y` (in Nightly builds, run with -Z macro-backtrace for more info)
help: you might be missing a const parameter
  |
7 | const _<const x: /* Type */>: A<
  |        +++++++++++++++++++++

thread 'rustc' panicked at compiler/rustc_ast_lowering/src/lib.rs:512:9:
adding a def'n for node-id NodeId(13) and def kind AnonConst but a previous def'n exists: DefKey { parent: Some(DefIndex(4)), disambiguated_data: DisambiguatedDefPathData { data: AnonConst, disambiguator: 0 } }
stack backtrace:
   0:     0x715d9948520a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hdac32ff7d08097b3
   1:     0x715d99c03e0a - core::fmt::write::he7b2961891ad0e03
   2:     0x715d9afa8dd1 - std::io::Write::write_fmt::h6fc7483bcf4f9c11
   3:     0x715d99485062 - std::sys::backtrace::BacktraceLock::print::hc7d7319873b6f660
   4:     0x715d99487546 - std::panicking::default_hook::{{closure}}::ha61e3147cba8ee8a
   5:     0x715d99487390 - std::panicking::default_hook::hc4bb3c2728ef613e
   6:     0x715d985067af - std[6fffc856d94a0e6]::panicking::update_hook::<alloc[d3ea509624c99f1]::boxed::Box<rustc_driver_impl[b57619f16e18ebfc]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x715d99487c58 - std::panicking::rust_panic_with_hook::ha7c28fcdc2bea7fe
   8:     0x715d99487a2a - std::panicking::begin_panic_handler::{{closure}}::h8bf205dbcfff5ce0
   9:     0x715d994856b9 - std::sys::backtrace::__rust_end_short_backtrace::h2a05a2f71e10a349
  10:     0x715d994876ec - rust_begin_unwind
  11:     0x715d95ee7b00 - core::panicking::panic_fmt::hd3f3c67c8def5639
  12:     0x715d9b81ab7d - <rustc_ast_lowering[7570fa9a18bde2ff]::LoweringContext>::create_def.cold
  13:     0x715d9a25b4e4 - <rustc_ast_lowering[7570fa9a18bde2ff]::LoweringContext>::lower_anon_const_to_anon_const
  14:     0x715d9a25b166 - <rustc_ast_lowering[7570fa9a18bde2ff]::LoweringContext>::lower_anon_const_to_const_arg_direct
  15:     0x715d9a27e0d7 - <rustc_ast_lowering[7570fa9a18bde2ff]::LoweringContext>::lower_qpath
  16:     0x715d9a289c16 - <rustc_ast_lowering[7570fa9a18bde2ff]::LoweringContext>::lower_ty_direct
  17:     0x715d9a249c48 - <rustc_ast_lowering[7570fa9a18bde2ff]::LoweringContext>::lower_item_kind
  18:     0x715d9a25efc5 - <rustc_ast_lowering[7570fa9a18bde2ff]::item::ItemLowerer>::lower_node
  19:     0x715d9a261d41 - rustc_ast_lowering[7570fa9a18bde2ff]::lower_to_hir
  20:     0x715d9ab86960 - rustc_query_impl[78a5845e8abfae96]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[78a5845e8abfae96]::query_impl::hir_crate::dynamic_query::{closure#2}::{closure#0}, rustc_middle[29c9719f087184d3]::query::erase::Erased<[u8; 8usize]>>
  21:     0x715d9ab85879 - rustc_query_system[f09a170c383828e5]::query::plumbing::try_execute_query::<rustc_query_impl[78a5845e8abfae96]::DynamicConfig<rustc_query_system[f09a170c383828e5]::query::caches::SingleCache<rustc_middle[29c9719f087184d3]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[78a5845e8abfae96]::plumbing::QueryCtxt, false>
  22:     0x715d9ab8521e - rustc_query_impl[78a5845e8abfae96]::query_impl::hir_crate::get_query_non_incr::__rust_end_short_backtrace
  23:     0x715d9a05a345 - rustc_query_impl[78a5845e8abfae96]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[78a5845e8abfae96]::query_impl::hir_attrs::dynamic_query::{closure#2}::{closure#0}, rustc_middle[29c9719f087184d3]::query::erase::Erased<[u8; 8usize]>>
  24:     0x715d9a0598e2 - rustc_query_system[f09a170c383828e5]::query::plumbing::try_execute_query::<rustc_query_impl[78a5845e8abfae96]::DynamicConfig<rustc_query_system[f09a170c383828e5]::query::caches::VecCache<rustc_hir[589805fb5f1ad5c3]::hir_id::OwnerId, rustc_middle[29c9719f087184d3]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[78a5845e8abfae96]::plumbing::QueryCtxt, false>
  25:     0x715d9a05964f - rustc_query_impl[78a5845e8abfae96]::query_impl::hir_attrs::get_query_non_incr::__rust_end_short_backtrace
  26:     0x715d99e00410 - <rustc_middle[29c9719f087184d3]::hir::map::Map>::attrs
  27:     0x715d9ab3b241 - rustc_passes[d7be05dacd881f89]::entry::entry_fn
  28:     0x715d9ab3b1d8 - rustc_query_impl[78a5845e8abfae96]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[78a5845e8abfae96]::query_impl::entry_fn::dynamic_query::{closure#2}::{closure#0}, rustc_middle[29c9719f087184d3]::query::erase::Erased<[u8; 12usize]>>
  29:     0x715d9ab3b1b5 - <rustc_query_impl[78a5845e8abfae96]::query_impl::entry_fn::dynamic_query::{closure#2} as core[c4cfdfe838f37049]::ops::function::FnOnce<(rustc_middle[29c9719f087184d3]::ty::context::TyCtxt, ())>>::call_once
  30:     0x715d9ab3ab49 - rustc_query_system[f09a170c383828e5]::query::plumbing::try_execute_query::<rustc_query_impl[78a5845e8abfae96]::DynamicConfig<rustc_query_system[f09a170c383828e5]::query::caches::SingleCache<rustc_middle[29c9719f087184d3]::query::erase::Erased<[u8; 12usize]>>, false, false, false>, rustc_query_impl[78a5845e8abfae96]::plumbing::QueryCtxt, false>
  31:     0x715d9ab3a8e9 - rustc_query_impl[78a5845e8abfae96]::query_impl::entry_fn::get_query_non_incr::__rust_end_short_backtrace
  32:     0x715d9a62b5c6 - rustc_interface[624eb7a003d8889d]::passes::run_required_analyses
  33:     0x715d9ab2c39e - rustc_interface[624eb7a003d8889d]::passes::analysis
  34:     0x715d9ab2c371 - rustc_query_impl[78a5845e8abfae96]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[78a5845e8abfae96]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[29c9719f087184d3]::query::erase::Erased<[u8; 1usize]>>
  35:     0x715d9ab8312e - rustc_query_system[f09a170c383828e5]::query::plumbing::try_execute_query::<rustc_query_impl[78a5845e8abfae96]::DynamicConfig<rustc_query_system[f09a170c383828e5]::query::caches::SingleCache<rustc_middle[29c9719f087184d3]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[78a5845e8abfae96]::plumbing::QueryCtxt, false>
  36:     0x715d9ab82e0f - rustc_query_impl[78a5845e8abfae96]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  37:     0x715d9aa2335e - rustc_interface[624eb7a003d8889d]::interface::run_compiler::<core[c4cfdfe838f37049]::result::Result<(), rustc_span[817e7a822cf0ab0]::ErrorGuaranteed>, rustc_driver_impl[b57619f16e18ebfc]::run_compiler::{closure#0}>::{closure#1}
  38:     0x715d9aab0d94 - std[6fffc856d94a0e6]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[624eb7a003d8889d]::util::run_in_thread_with_globals<rustc_interface[624eb7a003d8889d]::util::run_in_thread_pool_with_globals<rustc_interface[624eb7a003d8889d]::interface::run_compiler<core[c4cfdfe838f37049]::result::Result<(), rustc_span[817e7a822cf0ab0]::ErrorGuaranteed>, rustc_driver_impl[b57619f16e18ebfc]::run_compiler::{closure#0}>::{closure#1}, core[c4cfdfe838f37049]::result::Result<(), rustc_span[817e7a822cf0ab0]::ErrorGuaranteed>>::{closure#0}, core[c4cfdfe838f37049]::result::Result<(), rustc_span[817e7a822cf0ab0]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c4cfdfe838f37049]::result::Result<(), rustc_span[817e7a822cf0ab0]::ErrorGuaranteed>>
  39:     0x715d9aab11a8 - <<std[6fffc856d94a0e6]::thread::Builder>::spawn_unchecked_<rustc_interface[624eb7a003d8889d]::util::run_in_thread_with_globals<rustc_interface[624eb7a003d8889d]::util::run_in_thread_pool_with_globals<rustc_interface[624eb7a003d8889d]::interface::run_compiler<core[c4cfdfe838f37049]::result::Result<(), rustc_span[817e7a822cf0ab0]::ErrorGuaranteed>, rustc_driver_impl[b57619f16e18ebfc]::run_compiler::{closure#0}>::{closure#1}, core[c4cfdfe838f37049]::result::Result<(), rustc_span[817e7a822cf0ab0]::ErrorGuaranteed>>::{closure#0}, core[c4cfdfe838f37049]::result::Result<(), rustc_span[817e7a822cf0ab0]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c4cfdfe838f37049]::result::Result<(), rustc_span[817e7a822cf0ab0]::ErrorGuaranteed>>::{closure#1} as core[c4cfdfe838f37049]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  40:     0x715d9aab1c6b - std::sys::pal::unix::thread::Thread::new::thread_start::h9c90f5bca820af03
  41:     0x715d9c31b39d - <unknown>
  42:     0x715d9c3a049c - <unknown>
  43:                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.84.0-nightly (b27f33a4d 2024-10-19) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [hir_crate] getting the crate HIR
#1 [hir_attrs] getting HIR owner attributes in ``
end of query stack
error: aborting due to 3 previous errors

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

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

bisects to #125915

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Oct 20, 2024
@workingjubilee workingjubilee added A-HIR Area: The high-level intermediate representation (HIR) A-ast Area: AST labels Oct 21, 2024
@BoxyUwU BoxyUwU self-assigned this Nov 2, 2024
@Noratrieb Noratrieb removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 9, 2024
@bors bors closed this as completed in b7dc481 Nov 12, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Nov 12, 2024
Rollup merge of rust-lang#132653 - BoxyUwU:const_arg_stmt_mac_call, r=compiler-errors

Don't use `maybe_unwrap_block` when checking for macro calls in a block expr

Fixes rust-lang#131915

Using `maybe_unwrap_block` to determine if we are looking at a `{ mac_call!{} }` will fail sometimes as `mac_call!{}` could be a `StmtKind::MacCall` not a `StmtKind::Expr`. This caused the def collector to think that `{ mac_call!{} }` was a non-trivial const argument and create a definition for it even though it should not.

r? `@compiler-errors`  cc `@camelid`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ast Area: AST A-HIR Area: The high-level intermediate representation (HIR) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants