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: "[HIR node] cannot be placed in TypeckResults […]" involving const infinite loop #125370

Closed
matthiaskrgr opened this issue May 21, 2024 · 1 comment · Fixed by #125469
Closed
Assignees
Labels
A-const-eval Area: constant evaluation (mir interpretation) 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.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

type Field3 = i64;

#[repr(C)]
union DummyUnion {
    field3: Field3,
}

const UNION: DummyUnion = loop {};

const fn read_field2() -> Field2 {
    const FIELD2: Field2 = loop {
        UNION.field3
    };
}

original:

type Field3 = i64;

#[repr(C)]
union DummyUnion {
    field3: Field3,
}


const UNION: DummyUnion = loop {};



const fn read_field2() -> Field2 {
    const FIELD2: Field2 = loop {UNION.field3};
}

Version information

rustc 1.80.0-nightly (e8fbd9912 2024-05-21)
binary: rustc
commit-hash: e8fbd991287f637f95016a71ddc13438415bbe59
commit-date: 2024-05-21
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.6

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

Program output

error[E0412]: cannot find type `Field2` in this scope
  --> /tmp/icemaker_global_tempdir.90wvVq4JQsyR/rustc_testrunner_tmpdir_reporting.vXN26VLdUAKh/mvce.rs:10:27
   |
1  | type Field3 = i64;
   | ------------------ similarly named type alias `Field3` defined here
...
10 | const fn read_field2() -> Field2 {
   |                           ^^^^^^ help: a type alias with a similar name exists: `Field3`

error[E0412]: cannot find type `Field2` in this scope
  --> /tmp/icemaker_global_tempdir.90wvVq4JQsyR/rustc_testrunner_tmpdir_reporting.vXN26VLdUAKh/mvce.rs:11:19
   |
1  | type Field3 = i64;
   | ------------------ similarly named type alias `Field3` defined here
...
11 |     const FIELD2: Field2 = loop {
   |                   ^^^^^^ help: a type alias with a similar name exists: `Field3`

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

error: internal compiler error: compiler/rustc_middle/src/ty/typeck_results.rs:570:9: node HirId(DefId(0:7 ~ mvce[3aa8]::read_field2).4) (type `Field2`) cannot be placed in TypeckResults with hir_owner DefId(0:8 ~ mvce[3aa8]::read_field2::FIELD2)

thread 'rustc' panicked at compiler/rustc_middle/src/ty/typeck_results.rs:570:9:
Box<dyn Any>
stack backtrace:
   0:     0x7700d32687f5 - std::backtrace_rs::backtrace::libunwind::trace::hd2d645855696f4dc
                               at /rustc/e8fbd991287f637f95016a71ddc13438415bbe59/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x7700d32687f5 - std::backtrace_rs::backtrace::trace_unsynchronized::hf00e72a4f54751c9
                               at /rustc/e8fbd991287f637f95016a71ddc13438415bbe59/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7700d32687f5 - std::sys_common::backtrace::_print_fmt::hb11f864b4b226580
                               at /rustc/e8fbd991287f637f95016a71ddc13438415bbe59/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7700d32687f5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h5a916293b9277970
                               at /rustc/e8fbd991287f637f95016a71ddc13438415bbe59/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7700d32b791b - core::fmt::rt::Argument::fmt::h4ec318fe98aa1bd1
                               at /rustc/e8fbd991287f637f95016a71ddc13438415bbe59/library/core/src/fmt/rt.rs:165:63
   5:     0x7700d32b791b - core::fmt::write::ha63637c90825c5e4
                               at /rustc/e8fbd991287f637f95016a71ddc13438415bbe59/library/core/src/fmt/mod.rs:1169:21
   6:     0x7700d325d62f - std::io::Write::write_fmt::h61a12b81ba013cad
                               at /rustc/e8fbd991287f637f95016a71ddc13438415bbe59/library/std/src/io/mod.rs:1835:15
   7:     0x7700d32685ce - std::sys_common::backtrace::_print::h83df8853f46ce7cb
                               at /rustc/e8fbd991287f637f95016a71ddc13438415bbe59/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7700d32685ce - std::sys_common::backtrace::print::h6fcb62536ff44863
                               at /rustc/e8fbd991287f637f95016a71ddc13438415bbe59/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7700d326afc9 - std::panicking::default_hook::{{closure}}::h19c458ac7bffa126
  10:     0x7700d326ad0d - std::panicking::default_hook::h89e3de1f0a9d7973
                               at /rustc/e8fbd991287f637f95016a71ddc13438415bbe59/library/std/src/panicking.rs:298:9
  11:     0x7700cfcf5410 - std[8269a5b9a5bb6fe2]::panicking::update_hook::<alloc[c96cdaa1028c7bf0]::boxed::Box<rustc_driver_impl[36cb5aea6267632f]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7700d326b6fb - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hc1d41c2d85fc40dc
                               at /rustc/e8fbd991287f637f95016a71ddc13438415bbe59/library/alloc/src/boxed.rs:2077:9
  13:     0x7700d326b6fb - std::panicking::rust_panic_with_hook::h09cbbd76cef8ad08
                               at /rustc/e8fbd991287f637f95016a71ddc13438415bbe59/library/std/src/panicking.rs:799:13
  14:     0x7700cfd25024 - std[8269a5b9a5bb6fe2]::panicking::begin_panic::<rustc_errors[bd6c64ee2c36f2ad]::ExplicitBug>::{closure#0}
  15:     0x7700cfd21dd6 - std[8269a5b9a5bb6fe2]::sys_common::backtrace::__rust_end_short_backtrace::<std[8269a5b9a5bb6fe2]::panicking::begin_panic<rustc_errors[bd6c64ee2c36f2ad]::ExplicitBug>::{closure#0}, !>
  16:     0x7700cfd21ab6 - std[8269a5b9a5bb6fe2]::panicking::begin_panic::<rustc_errors[bd6c64ee2c36f2ad]::ExplicitBug>
  17:     0x7700cfd2e3a1 - <rustc_errors[bd6c64ee2c36f2ad]::diagnostic::BugAbort as rustc_errors[bd6c64ee2c36f2ad]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7700d01f2e3c - rustc_middle[f207ff10487be477]::util::bug::opt_span_bug_fmt::<rustc_span[4f56d3863912db0d]::span_encoding::Span>::{closure#0}
  19:     0x7700d01d7c1a - rustc_middle[f207ff10487be477]::ty::context::tls::with_opt::<rustc_middle[f207ff10487be477]::util::bug::opt_span_bug_fmt<rustc_span[4f56d3863912db0d]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  20:     0x7700d01d7a9b - rustc_middle[f207ff10487be477]::ty::context::tls::with_context_opt::<rustc_middle[f207ff10487be477]::ty::context::tls::with_opt<rustc_middle[f207ff10487be477]::util::bug::opt_span_bug_fmt<rustc_span[4f56d3863912db0d]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  21:     0x7700cdfbe6e0 - rustc_middle[f207ff10487be477]::util::bug::bug_fmt
  22:     0x7700d01f11eb - rustc_middle[f207ff10487be477]::ty::typeck_results::invalid_hir_id_for_typeck_results
  23:     0x7700d1693c98 - <dyn rustc_hir_analysis[bd5c9d43345fd6d9]::hir_ty_lowering::HirTyLowerer>::lower_ty_common::{closure#0}
  24:     0x7700cff15c93 - <rustc_hir_typeck[ec232e2d5d2d64bd]::fn_ctxt::FnCtxt>::suggest_missing_break_or_return_expr
  25:     0x7700cfee9ebf - <rustc_hir_typeck[ec232e2d5d2d64bd]::coercion::CoerceMany<rustc_hir[f45e204bf9f1debb]::hir::Expr>>::report_return_mismatched_types
  26:     0x7700d1a3a624 - <rustc_hir_typeck[ec232e2d5d2d64bd]::fn_ctxt::FnCtxt>::check_block_with_expected
  27:     0x7700d1a42183 - <rustc_hir_typeck[ec232e2d5d2d64bd]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  28:     0x7700d10d0169 - rustc_hir_typeck[ec232e2d5d2d64bd]::typeck
  29:     0x7700d10ce391 - rustc_query_impl[56bb04b70428af26]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[56bb04b70428af26]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f207ff10487be477]::query::erase::Erased<[u8; 8usize]>>
  30:     0x7700d13a4931 - rustc_query_system[c4191fc337511782]::query::plumbing::try_execute_query::<rustc_query_impl[56bb04b70428af26]::DynamicConfig<rustc_query_system[c4191fc337511782]::query::caches::VecCache<rustc_span[4f56d3863912db0d]::def_id::LocalDefId, rustc_middle[f207ff10487be477]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[56bb04b70428af26]::plumbing::QueryCtxt, false>
  31:     0x7700d13a3654 - rustc_query_impl[56bb04b70428af26]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  32:     0x7700d1e50bdf - rustc_hir_analysis[bd5c9d43345fd6d9]::check::check::check_item_type
  33:     0x7700d16a543c - rustc_hir_analysis[bd5c9d43345fd6d9]::check::wfcheck::check_well_formed
  34:     0x7700d16a3edd - rustc_query_impl[56bb04b70428af26]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[56bb04b70428af26]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f207ff10487be477]::query::erase::Erased<[u8; 1usize]>>
  35:     0x7700d16a3680 - rustc_query_system[c4191fc337511782]::query::plumbing::try_execute_query::<rustc_query_impl[56bb04b70428af26]::DynamicConfig<rustc_query_system[c4191fc337511782]::query::caches::VecCache<rustc_hir[f45e204bf9f1debb]::hir_id::OwnerId, rustc_middle[f207ff10487be477]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[56bb04b70428af26]::plumbing::QueryCtxt, false>
  36:     0x7700d16a33ff - rustc_query_impl[56bb04b70428af26]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  37:     0x7700d16a12b7 - rustc_hir_analysis[bd5c9d43345fd6d9]::check::wfcheck::check_mod_type_wf
  38:     0x7700d16a10e1 - rustc_query_impl[56bb04b70428af26]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[56bb04b70428af26]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f207ff10487be477]::query::erase::Erased<[u8; 1usize]>>
  39:     0x7700d1d5a886 - rustc_query_system[c4191fc337511782]::query::plumbing::try_execute_query::<rustc_query_impl[56bb04b70428af26]::DynamicConfig<rustc_query_system[c4191fc337511782]::query::caches::DefaultCache<rustc_span[4f56d3863912db0d]::def_id::LocalModDefId, rustc_middle[f207ff10487be477]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[56bb04b70428af26]::plumbing::QueryCtxt, false>
  40:     0x7700d1d5a63f - rustc_query_impl[56bb04b70428af26]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  41:     0x7700d13a1986 - rustc_hir_analysis[bd5c9d43345fd6d9]::check_crate
  42:     0x7700d138187e - rustc_interface[2341298b7187afbd]::passes::analysis
  43:     0x7700d13813d5 - rustc_query_impl[56bb04b70428af26]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[56bb04b70428af26]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f207ff10487be477]::query::erase::Erased<[u8; 1usize]>>
  44:     0x7700d1d5e225 - rustc_query_system[c4191fc337511782]::query::plumbing::try_execute_query::<rustc_query_impl[56bb04b70428af26]::DynamicConfig<rustc_query_system[c4191fc337511782]::query::caches::SingleCache<rustc_middle[f207ff10487be477]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[56bb04b70428af26]::plumbing::QueryCtxt, false>
  45:     0x7700d1d5df89 - rustc_query_impl[56bb04b70428af26]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  46:     0x7700d1bdcfce - rustc_interface[2341298b7187afbd]::interface::run_compiler::<core[40c7e4402753f050]::result::Result<(), rustc_span[4f56d3863912db0d]::ErrorGuaranteed>, rustc_driver_impl[36cb5aea6267632f]::run_compiler::{closure#0}>::{closure#1}
  47:     0x7700d1bc8309 - std[8269a5b9a5bb6fe2]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[2341298b7187afbd]::util::run_in_thread_with_globals<rustc_interface[2341298b7187afbd]::util::run_in_thread_pool_with_globals<rustc_interface[2341298b7187afbd]::interface::run_compiler<core[40c7e4402753f050]::result::Result<(), rustc_span[4f56d3863912db0d]::ErrorGuaranteed>, rustc_driver_impl[36cb5aea6267632f]::run_compiler::{closure#0}>::{closure#1}, core[40c7e4402753f050]::result::Result<(), rustc_span[4f56d3863912db0d]::ErrorGuaranteed>>::{closure#0}, core[40c7e4402753f050]::result::Result<(), rustc_span[4f56d3863912db0d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[40c7e4402753f050]::result::Result<(), rustc_span[4f56d3863912db0d]::ErrorGuaranteed>>
  48:     0x7700d1bc80b6 - <<std[8269a5b9a5bb6fe2]::thread::Builder>::spawn_unchecked_<rustc_interface[2341298b7187afbd]::util::run_in_thread_with_globals<rustc_interface[2341298b7187afbd]::util::run_in_thread_pool_with_globals<rustc_interface[2341298b7187afbd]::interface::run_compiler<core[40c7e4402753f050]::result::Result<(), rustc_span[4f56d3863912db0d]::ErrorGuaranteed>, rustc_driver_impl[36cb5aea6267632f]::run_compiler::{closure#0}>::{closure#1}, core[40c7e4402753f050]::result::Result<(), rustc_span[4f56d3863912db0d]::ErrorGuaranteed>>::{closure#0}, core[40c7e4402753f050]::result::Result<(), rustc_span[4f56d3863912db0d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[40c7e4402753f050]::result::Result<(), rustc_span[4f56d3863912db0d]::ErrorGuaranteed>>::{closure#2} as core[40c7e4402753f050]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  49:     0x7700d32754db - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7124f4fc5e2e1235
                               at /rustc/e8fbd991287f637f95016a71ddc13438415bbe59/library/alloc/src/boxed.rs:2063:9
  50:     0x7700d32754db - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7a8e6980b6ee4ea2
                               at /rustc/e8fbd991287f637f95016a71ddc13438415bbe59/library/alloc/src/boxed.rs:2063:9
  51:     0x7700d32754db - std::sys::pal::unix::thread::Thread::new::thread_start::h7f4aaf7f9b76a840
                               at /rustc/e8fbd991287f637f95016a71ddc13438415bbe59/library/std/src/sys/pal/unix/thread.rs:108:17
  52:     0x7700ccaaa1cf - <unknown>
  53:     0x7700ccb2b6ec - <unknown>
  54:                0x0 - <unknown>

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.80.0-nightly (e8fbd9912 2024-05-21) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `read_field2::FIELD2`
#1 [check_well_formed] checking that `read_field2::FIELD2` is well-formed
end of query stack
error: aborting due to 4 previous errors

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

@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. labels May 21, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 21, 2024
@matthiaskrgr
Copy link
Member Author

#123812 fyi @compiler-errors

@fmease fmease added A-const-eval Area: constant evaluation (mir interpretation) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 21, 2024
@fmease fmease changed the title ICE: node HirId(DefId(..)..) (type Field2) cannot be placed in TypeckResults with hir_owner DefId(..) ICE: "[HIR node] cannot be placed in TypeckResults […]" involving const infinite loop May 21, 2024
@compiler-errors compiler-errors self-assigned this May 23, 2024
workingjubilee added a commit to workingjubilee/rustc that referenced this issue May 26, 2024
…nst-body, r=cjgillot

Don't skip out of inner const when looking for body for suggestion

Self-explanatory title, I'll point out the important logic in an inline comment.

Fixes rust-lang#125370
jhpratt added a commit to jhpratt/rust that referenced this issue May 26, 2024
…nst-body, r=cjgillot

Don't skip out of inner const when looking for body for suggestion

Self-explanatory title, I'll point out the important logic in an inline comment.

Fixes rust-lang#125370
jhpratt added a commit to jhpratt/rust that referenced this issue May 26, 2024
…nst-body, r=cjgillot

Don't skip out of inner const when looking for body for suggestion

Self-explanatory title, I'll point out the important logic in an inline comment.

Fixes rust-lang#125370
@bors bors closed this as completed in b65b2b6 May 27, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue May 27, 2024
Rollup merge of rust-lang#125469 - compiler-errors:dont-skip-inner-const-body, r=cjgillot

Don't skip out of inner const when looking for body for suggestion

Self-explanatory title, I'll point out the important logic in an inline comment.

Fixes rust-lang#125370
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: constant evaluation (mir interpretation) 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants