rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.64k stars 12.49k forks source link

ICE: `adding a def'n for node-id NodeId(18) and def kind AnonConst but a previous def'n exists` #128016

Closed matthiaskrgr closed 2 weeks ago

matthiaskrgr commented 1 month ago

auto-reduced (treereduce-rust):

macro_rules! len {
    () => {
        target
    };
}

fn main() {
    let val: [str; len!()] = [];
}

original:

#![deny("{}", equal(&1, &2))]

macro_rules! len {
    () => (target) //~  ERROR trailing semicolon
                  //~| WARN this was previously accepted
}

fn main() {
    let val: [str; len!()] = [];
}

Version information

rustc 1.81.0-nightly (2e6fc4254 2024-07-20)
binary: rustc
commit-hash: 2e6fc425411280c658d852813de01c5157255088
commit-date: 2024-07-20
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7

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

Program output

``` error[E0425]: cannot find value `target` in this scope --> /tmp/icemaker_global_tempdir.1khAqktZak0k/rustc_testrunner_tmpdir_reporting.F2c9o1Y4kXrG/mvce.rs:3:9 | 3 | target | ^^^^^^ not found in this scope ... 8 | let val: [str; len!()] = []; | ------ in this macro invocation | = note: this error originates in the macro `len` (in Nightly builds, run with -Z macro-backtrace for more info) thread 'rustc' panicked at compiler/rustc_ast_lowering/src/lib.rs:503:9: adding a def'n for node-id NodeId(18) 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: 0x7e8412c083a5 - std::backtrace_rs::backtrace::libunwind::trace::h160e615c518ecb01 at /rustc/2e6fc425411280c658d852813de01c5157255088/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5 1: 0x7e8412c083a5 - std::backtrace_rs::backtrace::trace_unsynchronized::he30c6d2f98d2efdc at /rustc/2e6fc425411280c658d852813de01c5157255088/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7e8412c083a5 - std::sys::backtrace::_print_fmt::hb87cad28f2e90a0b at /rustc/2e6fc425411280c658d852813de01c5157255088/library/std/src/sys/backtrace.rs:65:5 3: 0x7e8412c083a5 - ::fmt::h362429114acc76fb at /rustc/2e6fc425411280c658d852813de01c5157255088/library/std/src/sys/backtrace.rs:40:26 4: 0x7e8412c57eab - core::fmt::rt::Argument::fmt::h2dd3e5813b018ccc at /rustc/2e6fc425411280c658d852813de01c5157255088/library/core/src/fmt/rt.rs:173:76 5: 0x7e8412c57eab - core::fmt::write::haceebbcd70688c9b at /rustc/2e6fc425411280c658d852813de01c5157255088/library/core/src/fmt/mod.rs:1182:21 6: 0x7e8412bfce7f - std::io::Write::write_fmt::h7c7b83fdf5105f1d at /rustc/2e6fc425411280c658d852813de01c5157255088/library/std/src/io/mod.rs:1827:15 7: 0x7e8412c0ab91 - std::sys::backtrace::BacktraceLock::print::hd97590b35fdf3d35 at /rustc/2e6fc425411280c658d852813de01c5157255088/library/std/src/sys/backtrace.rs:43:9 8: 0x7e8412c0ab91 - std::panicking::default_hook::{{closure}}::h587635c60073753d at /rustc/2e6fc425411280c658d852813de01c5157255088/library/std/src/panicking.rs:269:22 9: 0x7e8412c0a86c - std::panicking::default_hook::h41bedcdd5e6a0e44 at /rustc/2e6fc425411280c658d852813de01c5157255088/library/std/src/panicking.rs:296:9 10: 0x7e840f024e1a - std[f9e60369e5bdbf77]::panicking::update_hook::>::{closure#0} 11: 0x7e8412c0b55f - as core::ops::function::Fn>::call::h7651476b4c558d70 at /rustc/2e6fc425411280c658d852813de01c5157255088/library/alloc/src/boxed.rs:2084:9 12: 0x7e8412c0b55f - std::panicking::rust_panic_with_hook::heee9f152ffb5d0c8 at /rustc/2e6fc425411280c658d852813de01c5157255088/library/std/src/panicking.rs:808:13 13: 0x7e8412c0b187 - std::panicking::begin_panic_handler::{{closure}}::h808b135ae5150977 at /rustc/2e6fc425411280c658d852813de01c5157255088/library/std/src/panicking.rs:674:13 14: 0x7e8412c08869 - std::sys::backtrace::__rust_end_short_backtrace::h3c8a02e9918c1a26 at /rustc/2e6fc425411280c658d852813de01c5157255088/library/std/src/sys/backtrace.rs:168:18 15: 0x7e8412c0ae14 - rust_begin_unwind at /rustc/2e6fc425411280c658d852813de01c5157255088/library/std/src/panicking.rs:665:5 16: 0x7e8412c54463 - core::panicking::panic_fmt::h124ff2929e2b97c8 at /rustc/2e6fc425411280c658d852813de01c5157255088/library/core/src/panicking.rs:74:14 17: 0x7e8412045276 - ::create_def.cold 18: 0x7e8410ccdfdd - ::lower_anon_const_to_anon_const 19: 0x7e8410ccdc72 - ::lower_anon_const_to_const_arg_direct 20: 0x7e8410ccd9f3 - ::lower_array_length 21: 0x7e8410cf9b8f - ::lower_ty_direct 22: 0x7e8410cae238 - ::lower_block_noalloc 23: 0x7e8410cd4d10 - ::lower_maybe_coroutine_body 24: 0x7e8410cee69f - ::lower_item_kind 25: 0x7e8410cd215f - ::lower_node 26: 0x7e8410ccfb79 - rustc_ast_lowering[d5c02056e301041c]::lower_to_hir 27: 0x7e84114c5260 - rustc_query_impl[7076d3a069d488ea]::plumbing::__rust_begin_short_backtrace::> 28: 0x7e84114c2302 - rustc_query_system[eb2b374bcd8a9022]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[7076d3a069d488ea]::plumbing::QueryCtxt, false> 29: 0x7e84114c1f1e - rustc_query_impl[7076d3a069d488ea]::query_impl::hir_crate::get_query_non_incr::__rust_end_short_backtrace 30: 0x7e8410e9a064 - rustc_query_impl[7076d3a069d488ea]::plumbing::__rust_begin_short_backtrace::> 31: 0x7e8410e9961f - rustc_query_system[eb2b374bcd8a9022]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[7076d3a069d488ea]::plumbing::QueryCtxt, false> 32: 0x7e8410e9938f - rustc_query_impl[7076d3a069d488ea]::query_impl::hir_attrs::get_query_non_incr::__rust_end_short_backtrace 33: 0x7e8410878006 - ::attrs 34: 0x7e84117af401 - rustc_passes[141401c4575c1f66]::entry::entry_fn 35: 0x7e84117af398 - rustc_query_impl[7076d3a069d488ea]::plumbing::__rust_begin_short_backtrace::> 36: 0x7e84117af36f - >::call_once 37: 0x7e84117aec88 - rustc_query_system[eb2b374bcd8a9022]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[7076d3a069d488ea]::plumbing::QueryCtxt, false> 38: 0x7e84117aea29 - rustc_query_impl[7076d3a069d488ea]::query_impl::entry_fn::get_query_non_incr::__rust_end_short_backtrace 39: 0x7e8410b0ffb2 - rustc_interface[635a4d36e766d1e0]::passes::analysis 40: 0x7e8410b0fdc7 - rustc_query_impl[7076d3a069d488ea]::plumbing::__rust_begin_short_backtrace::> 41: 0x7e84114c3725 - rustc_query_system[eb2b374bcd8a9022]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[7076d3a069d488ea]::plumbing::QueryCtxt, false> 42: 0x7e84114c348f - rustc_query_impl[7076d3a069d488ea]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 43: 0x7e84114002c5 - rustc_interface[635a4d36e766d1e0]::interface::run_compiler::, rustc_driver_impl[23129d3f9f762646]::run_compiler::{closure#0}>::{closure#1} 44: 0x7e8411394189 - std[f9e60369e5bdbf77]::sys::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[23129d3f9f762646]::run_compiler::{closure#0}>::{closure#1}, core[c927cdc4da4eb0de]::result::Result<(), rustc_span[8f3a5487dfe29266]::ErrorGuaranteed>>::{closure#0}, core[c927cdc4da4eb0de]::result::Result<(), rustc_span[8f3a5487dfe29266]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c927cdc4da4eb0de]::result::Result<(), rustc_span[8f3a5487dfe29266]::ErrorGuaranteed>> 45: 0x7e8411393f3a - <::spawn_unchecked_, rustc_driver_impl[23129d3f9f762646]::run_compiler::{closure#0}>::{closure#1}, core[c927cdc4da4eb0de]::result::Result<(), rustc_span[8f3a5487dfe29266]::ErrorGuaranteed>>::{closure#0}, core[c927cdc4da4eb0de]::result::Result<(), rustc_span[8f3a5487dfe29266]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c927cdc4da4eb0de]::result::Result<(), rustc_span[8f3a5487dfe29266]::ErrorGuaranteed>>::{closure#1} as core[c927cdc4da4eb0de]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 46: 0x7e8412c155bb - as core::ops::function::FnOnce>::call_once::haeea406f77e87cac at /rustc/2e6fc425411280c658d852813de01c5157255088/library/alloc/src/boxed.rs:2070:9 47: 0x7e8412c155bb - as core::ops::function::FnOnce>::call_once::h024bb75f9bcc5dfb at /rustc/2e6fc425411280c658d852813de01c5157255088/library/alloc/src/boxed.rs:2070:9 48: 0x7e8412c155bb - std::sys::pal::unix::thread::Thread::new::thread_start::h106d07b62ccda4e0 at /rustc/2e6fc425411280c658d852813de01c5157255088/library/std/src/sys/pal/unix/thread.rs:108:17 49: 0x7e84129a9ded - 50: 0x7e8412a2d0dc - 51: 0x0 - 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.81.0-nightly (2e6fc4254 2024-07-20) 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 1 previous error For more information about this error, try `rustc --explain E0425`. ```

matthiaskrgr commented 1 month ago

another one for #125915 cc @camelid

matthiaskrgr commented 1 month ago

This also showed up in the crater reports for https://github.com/rust-lang/rust/issues/128468 build-fail/gh/rustindia/mpw-rs/d0150eff7a0eb1f43524d29b1a932f966d24f6a8/beta-2024-07-26.txt or regressed/gh/georgebarwood/RustWeb2/57ef036e3c07701d2579b4b1542a5a1131460f4d/beta-2024-07-26.txt for example

camelid commented 1 month ago

Minimized a bit more (avoid incorrect str usage):

macro_rules! len {
    () => {
        target
    };
}

fn main() {
    let val: [bool; len!()] = [];
}
BoxyUwU commented 1 month ago

I'll look into this since this is on beta now so its somewhat time sensitive ^^'

camelid commented 1 month ago

It seems like this is Res::Err-related because this code compiles fine:

macro_rules! len {
    () => {{
        let target = 0;
        target
    }};
}

fn main() {
    let val: [bool; len!()] = [];
}

Which is actually really weird because it's allowing use of a non-const in const context?? EDIT: it is a const, because the let is inside a const context

compiler-errors commented 1 month ago

How is it a non-const?

fn main() {
    let val: [bool; {
        let target = 0;
        target
    }] = [];
}

is valid code.

BoxyUwU commented 1 month ago
macro_rules! len {
    () => {
        BAR
    };
}

const BAR: usize = 0;

fn bar() {
    let val: [bool; len!()] = [];
}

This is an example of stable->beta pass->ICE

BoxyUwU commented 1 month ago
macro_rules! len {
    ($x:ident) => {
        $x
    };
}

fn bar<const N: usize>() {
    let val: [bool; len!(N)] = [true; N];
}

This has a slightly different ICE message but is the same root cause and is also a stable->beta pass->ICE

apiraino commented 1 month ago

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-critical