Skip to content

ICE: forcing query with already existing 'DepNode' #121755

Closed
@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

macro x(
    $macro_name:ident,
    $macro2_name:ident,
    $type_name:ident,
    $field_name:ident,
    $const_name:ident
) {
    pub struct $type_name {}

    pub const $const_name: $type_name = $type_name {};

    #[macro_export]
    macro_rules! $macro_name {
        (check_fields) => {{
            assert_eq!($const_name.field, Field::MacroCtxt);
        }};
    }

    pub macro $macro2_name {
            (Copy $e:expr) => {},
            (check_fields) => {test_fields!(check_fields);},

        }
}

x!(test_fields, test_fields2, MyStruct, field, MY_CONST);

pub fn check_fields_local() {
    test_fields!(check_fields);
    test_fields2!(check_fields);
}
original code

original:

#![feature(decl_macro)]

#[derive(Copy, Clone, PartialEq, Debug)]
pub enum Field {
    RootCtxt,
    MacroCtxt,
}

#[rustfmt::skip]
macro x(
    $macro_name:ident,
    $macro2_name:ident,
    $type_name:ident,
    $field_name:ident,
    $const_name:ident
) {
    #[derive(Copy, Clone)]
    pub struct $type_name {
        pub field: Field,
        pub $const_name: Field,
    }

    pub const $const_name: $type_name =
        $type_name { field: Field::MacroCtxt, $field_name: Field::RootCtxt };

    #[macro_export]
    macro_rules! $macro_name {
        (construct $e:expr) => {{
            let e = $e;
            assert_eq!(e.field, Field::MacroCtxt);
            assert_eq!(e.$field_name, Field::RootCtxt);
        }};
        (check_fields) => {{
            assert_eq!($const_name.field, Field::MacroCtxt);
            assert_eq!($const_name.$field_name, Field::RootCtxt);
        }};
        (construct) => {
            $type_name { field: Field::MacroCtxt, $field_name: Field::RootCtxt }
        };
    }

    pub macro $macro2_name {
        (Copy $e:expr) => {{
            let e = $e;
            assert_eq!(e.field, Field::MacroCtxt);
            assert_eq!(Copy.$field_name, Field::RootCtxt);
        }},
        (check_fields) => {test_fields!(check_fields);},
        (construct) => {
            (check_fields) { field: Field::MacroCtxt, $field_name: Field::RootCtxt }
        }
    }
}

x!(test_fields, test_fields2, MyStruct, field, MY_CONST);

pub fn check_fields(s: MyStruct) {
    macro!(check_fields_of s);
}

pub fn check_fields_local() {
    test_fields!(check_fields);
    test_fields2!(check_fields);

    let s1 = test_fields!(construct);
    test_fields!(check_fields_of s1);

    let s2 = test_fields2!(construct);
    test_fields2!(check_fields_of s2);
}

Version information

rustc 1.78.0-nightly (ef324565d 2024-02-27)
binary: rustc
commit-hash: ef324565d071c6d7e2477a195648549e33d6a465
commit-date: 2024-02-27
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zincremental-verify-ich=yes -Cincremental=<dir> -Cdebuginfo=2

Program output

error[E0658]: `macro` is experimental
  --> /tmp/icemaker_global_tempdir.K2wBhJQqioS7/rustc_testrunner_tmpdir_reporting.az3BohUb00y4/mvce.rs:1:1
   |
1  | / macro x(
2  | |     $macro_name:ident,
3  | |     $macro2_name:ident,
4  | |     $type_name:ident,
...  |
23 | |         }
24 | | }
   | |_^
   |
   = note: see issue #39412 <https://github.com/rust-lang/rust/issues/39412> for more information
   = help: add `#![feature(decl_macro)]` to the crate attributes to enable
   = note: this compiler was built on 2024-02-27; consider upgrading it if it is out of date

error[E0658]: `macro` is experimental
  --> /tmp/icemaker_global_tempdir.K2wBhJQqioS7/rustc_testrunner_tmpdir_reporting.az3BohUb00y4/mvce.rs:19:5
   |
19 | /     pub macro $macro2_name {
20 | |             (Copy $e:expr) => {},
21 | |             (check_fields) => {test_fields!(check_fields);},
22 | |
23 | |         }
   | |_________^
...
26 |   x!(test_fields, test_fields2, MyStruct, field, MY_CONST);
   |   -------------------------------------------------------- in this macro invocation
   |
   = note: see issue #39412 <https://github.com/rust-lang/rust/issues/39412> for more information
   = help: add `#![feature(decl_macro)]` to the crate attributes to enable
   = note: this compiler was built on 2024-02-27; consider upgrading it if it is out of date
   = note: this error originates in the macro `x` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.K2wBhJQqioS7/rustc_testrunner_tmpdir_reporting.az3BohUb00y4/mvce.rs:31:2
   |
31 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.K2wBhJQqioS7/rustc_testrunner_tmpdir_reporting.az3BohUb00y4/mvce.rs`

error[E0609]: no field `field` on type `MyStruct`
  --> /tmp/icemaker_global_tempdir.K2wBhJQqioS7/rustc_testrunner_tmpdir_reporting.az3BohUb00y4/mvce.rs:15:36
   |
15 |             assert_eq!($const_name.field, Field::MacroCtxt);
   |                                    ^^^^^ unknown field
...
29 |     test_fields!(check_fields);
   |     -------------------------- in this macro invocation
   |
   = note: this error originates in the macro `test_fields` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type `Field`
  --> /tmp/icemaker_global_tempdir.K2wBhJQqioS7/rustc_testrunner_tmpdir_reporting.az3BohUb00y4/mvce.rs:15:43
   |
15 |             assert_eq!($const_name.field, Field::MacroCtxt);
   |                                           ^^^^^ use of undeclared type `Field`
...
29 |     test_fields!(check_fields);
   |     -------------------------- in this macro invocation
   |
   = note: this error originates in the macro `test_fields` (in Nightly builds, run with -Z macro-backtrace for more info)

thread 'rustc' panicked at /rustc/ef324565d071c6d7e2477a195648549e33d6a465/compiler/rustc_query_system/src/dep_graph/graph.rs:348:9:
forcing query with already existing `DepNode`
- query-key: (DefId(0:5 ~ mvce[1c99]::MyStruct), field#9)
- dep-node: find_field(4bb1f4a1f312726f-449d5a7820423352)
stack backtrace:
   0:     0x7ff3acf8cc46 - std::backtrace_rs::backtrace::libunwind::trace::hcd31ff68bb8eb3c8
                               at /rustc/ef324565d071c6d7e2477a195648549e33d6a465/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7ff3acf8cc46 - std::backtrace_rs::backtrace::trace_unsynchronized::h14d76bd5509bf096
                               at /rustc/ef324565d071c6d7e2477a195648549e33d6a465/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7ff3acf8cc46 - std::sys_common::backtrace::_print_fmt::hccb1d92c773f2e33
                               at /rustc/ef324565d071c6d7e2477a195648549e33d6a465/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7ff3acf8cc46 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::haec236aae0c71094
                               at /rustc/ef324565d071c6d7e2477a195648549e33d6a465/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7ff3acfddbcc - core::fmt::rt::Argument::fmt::hfe5c81d163ead061
                               at /rustc/ef324565d071c6d7e2477a195648549e33d6a465/library/core/src/fmt/rt.rs:142:9
   5:     0x7ff3acfddbcc - core::fmt::write::hae70f68f90cda8d6
                               at /rustc/ef324565d071c6d7e2477a195648549e33d6a465/library/core/src/fmt/mod.rs:1120:17
   6:     0x7ff3acf814cf - std::io::Write::write_fmt::h2920683ffc23d04e
                               at /rustc/ef324565d071c6d7e2477a195648549e33d6a465/library/std/src/io/mod.rs:1846:15
   7:     0x7ff3acf8c9f4 - std::sys_common::backtrace::_print::h5625fa16158ef797
                               at /rustc/ef324565d071c6d7e2477a195648549e33d6a465/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7ff3acf8c9f4 - std::sys_common::backtrace::print::h736502c57d395fe5
                               at /rustc/ef324565d071c6d7e2477a195648549e33d6a465/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7ff3acf8f73b - std::panicking::default_hook::{{closure}}::hd092ecfc821f695b
  10:     0x7ff3acf8f489 - std::panicking::default_hook::h7f251f2c2a8aa52c
                               at /rustc/ef324565d071c6d7e2477a195648549e33d6a465/library/std/src/panicking.rs:292:9
  11:     0x7ff3afea5d3c - std[578157ee06130f18]::panicking::update_hook::<alloc[1f5b0d5bc2928dda]::boxed::Box<rustc_driver_impl[58539505cbc2faf7]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7ff3acf8fea0 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hc774e046b4082d87
                               at /rustc/ef324565d071c6d7e2477a195648549e33d6a465/library/alloc/src/boxed.rs:2030:9
  13:     0x7ff3acf8fea0 - std::panicking::rust_panic_with_hook::h50c9145ee7057605
                               at /rustc/ef324565d071c6d7e2477a195648549e33d6a465/library/std/src/panicking.rs:783:13
  14:     0x7ff3acf8fbe2 - std::panicking::begin_panic_handler::{{closure}}::h94d2e31aacd46455
                               at /rustc/ef324565d071c6d7e2477a195648549e33d6a465/library/std/src/panicking.rs:657:13
  15:     0x7ff3acf8d126 - std::sys_common::backtrace::__rust_end_short_backtrace::h38d64ea497d2de47
                               at /rustc/ef324565d071c6d7e2477a195648549e33d6a465/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7ff3acf8f914 - rust_begin_unwind
                               at /rustc/ef324565d071c6d7e2477a195648549e33d6a465/library/std/src/panicking.rs:645:5
  17:     0x7ff3acfda0e5 - core::panicking::panic_fmt::ha1515334750a7e83
                               at /rustc/ef324565d071c6d7e2477a195648549e33d6a465/library/core/src/panicking.rs:72:14
  18:     0x7ff3b1f833d6 - rustc_query_system[cf6fea66217b4faa]::query::plumbing::try_execute_query::<rustc_query_impl[ba88ac09c9d7b12d]::DynamicConfig<rustc_query_system[cf6fea66217b4faa]::query::caches::DefaultCache<(rustc_span[20f1163f305bb5ee]::def_id::DefId, rustc_span[20f1163f305bb5ee]::symbol::Ident), rustc_middle[2ebf57413533262e]::query::erase::Erased<[u8; 4usize]>>, false, false, false>, rustc_query_impl[ba88ac09c9d7b12d]::plumbing::QueryCtxt, true>
  19:     0x7ff3b1f8263b - rustc_query_impl[ba88ac09c9d7b12d]::query_impl::find_field::get_query_incr::__rust_end_short_backtrace
  20:     0x7ff3b144a252 - <rustc_hir_typeck[12acd77aad38ccf6]::fn_ctxt::FnCtxt>::check_field
  21:     0x7ff3b1c82294 - <rustc_hir_typeck[12acd77aad38ccf6]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  22:     0x7ff3b1c82088 - <rustc_hir_typeck[12acd77aad38ccf6]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  23:     0x7ff3b1c84d9c - <rustc_hir_typeck[12acd77aad38ccf6]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  24:     0x7ff3b1c702fb - <rustc_hir_typeck[12acd77aad38ccf6]::fn_ctxt::FnCtxt>::check_match
  25:     0x7ff3b1c8248e - <rustc_hir_typeck[12acd77aad38ccf6]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  26:     0x7ff3b179dc9b - <rustc_hir_typeck[12acd77aad38ccf6]::fn_ctxt::FnCtxt>::check_block_with_expected
  27:     0x7ff3b1c819a5 - <rustc_hir_typeck[12acd77aad38ccf6]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  28:     0x7ff3b179dc9b - <rustc_hir_typeck[12acd77aad38ccf6]::fn_ctxt::FnCtxt>::check_block_with_expected
  29:     0x7ff3b1c819a5 - <rustc_hir_typeck[12acd77aad38ccf6]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  30:     0x7ff3b1c916f8 - rustc_hir_typeck[12acd77aad38ccf6]::check::check_fn
  31:     0x7ff3b15c38f1 - rustc_hir_typeck[12acd77aad38ccf6]::typeck
  32:     0x7ff3b15c2bb5 - rustc_query_impl[ba88ac09c9d7b12d]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ba88ac09c9d7b12d]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[2ebf57413533262e]::query::erase::Erased<[u8; 8usize]>>
  33:     0x7ff3b16bd46d - rustc_query_system[cf6fea66217b4faa]::query::plumbing::try_execute_query::<rustc_query_impl[ba88ac09c9d7b12d]::DynamicConfig<rustc_query_system[cf6fea66217b4faa]::query::caches::VecCache<rustc_span[20f1163f305bb5ee]::def_id::LocalDefId, rustc_middle[2ebf57413533262e]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[ba88ac09c9d7b12d]::plumbing::QueryCtxt, true>
  34:     0x7ff3b1ac76c9 - rustc_query_impl[ba88ac09c9d7b12d]::query_impl::typeck::get_query_incr::__rust_end_short_backtrace
  35:     0x7ff3b1ac6a52 - <rustc_middle[2ebf57413533262e]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[b9c969b446149ad8]::check_crate::{closure#6}>::{closure#0}
  36:     0x7ff3b1ac531d - rustc_hir_analysis[b9c969b446149ad8]::check_crate
  37:     0x7ff3b1d65bef - rustc_interface[549d5cba17650390]::passes::analysis
  38:     0x7ff3b1d65859 - rustc_query_impl[ba88ac09c9d7b12d]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ba88ac09c9d7b12d]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[2ebf57413533262e]::query::erase::Erased<[u8; 1usize]>>
  39:     0x7ff3b1f380e2 - rustc_query_system[cf6fea66217b4faa]::query::plumbing::try_execute_query::<rustc_query_impl[ba88ac09c9d7b12d]::DynamicConfig<rustc_query_system[cf6fea66217b4faa]::query::caches::SingleCache<rustc_middle[2ebf57413533262e]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[ba88ac09c9d7b12d]::plumbing::QueryCtxt, true>
  40:     0x7ff3b1f37cdc - rustc_query_impl[ba88ac09c9d7b12d]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
  41:     0x7ff3b1f40c16 - rustc_interface[549d5cba17650390]::interface::run_compiler::<core[6cbd71b2db6ebc95]::result::Result<(), rustc_span[20f1163f305bb5ee]::ErrorGuaranteed>, rustc_driver_impl[58539505cbc2faf7]::run_compiler::{closure#0}>::{closure#0}
  42:     0x7ff3b21e7dc5 - std[578157ee06130f18]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[549d5cba17650390]::util::run_in_thread_with_globals<rustc_interface[549d5cba17650390]::util::run_in_thread_pool_with_globals<rustc_interface[549d5cba17650390]::interface::run_compiler<core[6cbd71b2db6ebc95]::result::Result<(), rustc_span[20f1163f305bb5ee]::ErrorGuaranteed>, rustc_driver_impl[58539505cbc2faf7]::run_compiler::{closure#0}>::{closure#0}, core[6cbd71b2db6ebc95]::result::Result<(), rustc_span[20f1163f305bb5ee]::ErrorGuaranteed>>::{closure#0}, core[6cbd71b2db6ebc95]::result::Result<(), rustc_span[20f1163f305bb5ee]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[6cbd71b2db6ebc95]::result::Result<(), rustc_span[20f1163f305bb5ee]::ErrorGuaranteed>>
  43:     0x7ff3b21e7bf2 - <<std[578157ee06130f18]::thread::Builder>::spawn_unchecked_<rustc_interface[549d5cba17650390]::util::run_in_thread_with_globals<rustc_interface[549d5cba17650390]::util::run_in_thread_pool_with_globals<rustc_interface[549d5cba17650390]::interface::run_compiler<core[6cbd71b2db6ebc95]::result::Result<(), rustc_span[20f1163f305bb5ee]::ErrorGuaranteed>, rustc_driver_impl[58539505cbc2faf7]::run_compiler::{closure#0}>::{closure#0}, core[6cbd71b2db6ebc95]::result::Result<(), rustc_span[20f1163f305bb5ee]::ErrorGuaranteed>>::{closure#0}, core[6cbd71b2db6ebc95]::result::Result<(), rustc_span[20f1163f305bb5ee]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[6cbd71b2db6ebc95]::result::Result<(), rustc_span[20f1163f305bb5ee]::ErrorGuaranteed>>::{closure#1} as core[6cbd71b2db6ebc95]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  44:     0x7ff3acf99875 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hbfe673f8fb6b1f32
                               at /rustc/ef324565d071c6d7e2477a195648549e33d6a465/library/alloc/src/boxed.rs:2016:9
  45:     0x7ff3acf99875 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h91a1aab6b746134a
                               at /rustc/ef324565d071c6d7e2477a195648549e33d6a465/library/alloc/src/boxed.rs:2016:9
  46:     0x7ff3acf99875 - std::sys::pal::unix::thread::Thread::new::thread_start::h8e91ee627a6e8489
                               at /rustc/ef324565d071c6d7e2477a195648549e33d6a465/library/std/src/sys/pal/unix/thread.rs:108:17
  47:     0x7ff3acd8155a - <unknown>
  48:     0x7ff3acdfea3c - <unknown>
  49:                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: rustc 1.78.0-nightly (ef324565d 2024-02-27) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z incremental-verify-ich=yes -C incremental=[REDACTED] -C debuginfo=2

query stack during panic:
#0 [find_field] find the index of maybe nested field `field` in `MyStruct`
#1 [typeck] type-checking `check_fields_local`
#2 [analysis] running analysis passes on this crate
end of query stack
error[E0433]: failed to resolve: use of undeclared type `Field`
  --> /tmp/icemaker_global_tempdir.K2wBhJQqioS7/rustc_testrunner_tmpdir_reporting.az3BohUb00y4/mvce.rs:15:43
   |
15 |             assert_eq!($const_name.field, Field::MacroCtxt);
   |                                           ^^^^^ use of undeclared type `Field`
...
30 |     test_fields2!(check_fields);
   |     --------------------------- in this macro invocation
   |
   = note: this error originates in the macro `test_fields` which comes from the expansion of the macro `test_fields2` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 6 previous errors

Some errors have detailed explanations: E0433, E0601, E0609, E0658.
For more information about an error, try `rustc --explain E0433`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-incr-compArea: Incremental compilationC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions