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: Node. . cannot be placed in TypeckResults with hir_owner #116658

Closed
matthiaskrgr opened this issue Oct 12, 2023 · 1 comment · Fixed by #116676
Closed

ICE: Node. . cannot be placed in TypeckResults with hir_owner #116658

matthiaskrgr opened this issue Oct 12, 2023 · 1 comment · Fixed by #116676
Assignees
Labels
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

matthiaskrgr commented Oct 12, 2023

Code

rustc --edition=2021

fn test() {
    let x = match **x {
        Some(&a) if { panic!() } => {}
    };
    let mut p = &x;

    {
        let mut closure = expect_sig(|p, y| *p = y);
        //~^ ERROR
        closure(&mut p, &y);
    }

    deref(p);
}

fn expect_sig<F>(f: F) -> F
where
    F: FnMut(&mut &i32, &i32),
{
    f
}

Meta

rustc --version --verbose:

rustc 1.75.0-nightly (c1691db36 2023-10-11)
binary: rustc
commit-hash: c1691db366c0f2e2341c60377c248ca2d9335076
commit-date: 2023-10-11
host: x86_64-unknown-linux-gnu
release: 1.75.0-nightly
LLVM version: 17.0.2

Error output

error[E0425]: cannot find value `x` in this scope
 --> treereduce.out:2:21
  |
2 |     let x = match **x {
  |                     ^ not found in this scope

error[E0425]: cannot find value `y` in this scope
  --> treereduce.out:10:26
   |
10 |         closure(&mut p, &y);
   |                          ^ help: a local variable with a similar name exists: `p`

error[E0601]: `main` function not found in crate `treereduce`
  --> treereduce.out:21:2
   |
21 | }
   |  ^ consider adding a `main` function to `treereduce.out`
Backtrace

error: internal compiler error: compiler/rustc_middle/src/ty/typeck_results.rs:494:9: node HirId(DefId(0:7 ~ treereduce[6f61]::test::panic_cold_explicit).2) (expr `$crate::panicking::panic_explicit`) cannot be placed in TypeckResults with hir_owner DefId(0:3 ~ treereduce[6f61]::test)

thread 'rustc' panicked at /rustc/c1691db366c0f2e2341c60377c248ca2d9335076/compiler/rustc_errors/src/lib.rs:1658:9:
Box<dyn Any>
stack backtrace:
   0:     0x7efcb216291c - std::backtrace_rs::backtrace::libunwind::trace::h1a396f4229b95b89
                               at /rustc/c1691db366c0f2e2341c60377c248ca2d9335076/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7efcb216291c - std::backtrace_rs::backtrace::trace_unsynchronized::had22ccd71191bcf5
                               at /rustc/c1691db366c0f2e2341c60377c248ca2d9335076/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7efcb216291c - std::sys_common::backtrace::_print_fmt::h6327fff1763299f2
                               at /rustc/c1691db366c0f2e2341c60377c248ca2d9335076/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7efcb216291c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h5c308bc33123b3c6
                               at /rustc/c1691db366c0f2e2341c60377c248ca2d9335076/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7efcb21ca370 - core::fmt::rt::Argument::fmt::hef0d41e90575ec4b
                               at /rustc/c1691db366c0f2e2341c60377c248ca2d9335076/library/core/src/fmt/rt.rs:142:9
   5:     0x7efcb21ca370 - core::fmt::write::h9e48193d66acdcfa
                               at /rustc/c1691db366c0f2e2341c60377c248ca2d9335076/library/core/src/fmt/mod.rs:1117:17
   6:     0x7efcb2155bdf - std::io::Write::write_fmt::h28ef69c5512926cf
                               at /rustc/c1691db366c0f2e2341c60377c248ca2d9335076/library/std/src/io/mod.rs:1763:15
   7:     0x7efcb2162704 - std::sys_common::backtrace::_print::h55d64ccf5cbdab6d
                               at /rustc/c1691db366c0f2e2341c60377c248ca2d9335076/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7efcb2162704 - std::sys_common::backtrace::print::h2df81292c2f87861
                               at /rustc/c1691db366c0f2e2341c60377c248ca2d9335076/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7efcb2165517 - std::panicking::default_hook::{{closure}}::ha7e6872e55317a45
  10:     0x7efcb216525a - std::panicking::default_hook::hb6ef52fce67e4118
                               at /rustc/c1691db366c0f2e2341c60377c248ca2d9335076/library/std/src/panicking.rs:292:9
  11:     0x7efcb4d15295 - std[f742926918452c50]::panicking::update_hook::<alloc[f677c22cdd567b61]::boxed::Box<rustc_driver_impl[13831840ef09002e]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7efcb2165cb8 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h9b42aa266f672cfd
                               at /rustc/c1691db366c0f2e2341c60377c248ca2d9335076/library/alloc/src/boxed.rs:2021:9
  13:     0x7efcb2165cb8 - std::panicking::rust_panic_with_hook::h69579898fe8322bc
                               at /rustc/c1691db366c0f2e2341c60377c248ca2d9335076/library/std/src/panicking.rs:735:13
  14:     0x7efcb50c7d54 - std[f742926918452c50]::panicking::begin_panic::<rustc_errors[74511e581188d85f]::ExplicitBug>::{closure#0}
  15:     0x7efcb50be816 - std[f742926918452c50]::sys_common::backtrace::__rust_end_short_backtrace::<std[f742926918452c50]::panicking::begin_panic<rustc_errors[74511e581188d85f]::ExplicitBug>::{closure#0}, !>
  16:     0x7efcb50b9256 - std[f742926918452c50]::panicking::begin_panic::<rustc_errors[74511e581188d85f]::ExplicitBug>
  17:     0x7efcb50a1484 - <rustc_errors[74511e581188d85f]::HandlerInner>::bug::<alloc[f677c22cdd567b61]::string::String>
  18:     0x7efcb50a1244 - <rustc_errors[74511e581188d85f]::Handler>::bug::<alloc[f677c22cdd567b61]::string::String>
  19:     0x7efcb5142cdd - rustc_middle[75501c6963a0c8e6]::util::bug::opt_span_bug_fmt::<rustc_span[afe2d1e5c4333398]::span_encoding::Span>::{closure#0}
  20:     0x7efcb5129c4a - rustc_middle[75501c6963a0c8e6]::ty::context::tls::with_opt::<rustc_middle[75501c6963a0c8e6]::util::bug::opt_span_bug_fmt<rustc_span[afe2d1e5c4333398]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7efcb5129b08 - rustc_middle[75501c6963a0c8e6]::ty::context::tls::with_context_opt::<rustc_middle[75501c6963a0c8e6]::ty::context::tls::with_opt<rustc_middle[75501c6963a0c8e6]::util::bug::opt_span_bug_fmt<rustc_span[afe2d1e5c4333398]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7efcb3150610 - rustc_middle[75501c6963a0c8e6]::util::bug::bug_fmt
  23:     0x7efcb51414fb - rustc_middle[75501c6963a0c8e6]::ty::typeck_results::invalid_hir_id_for_typeck_results
  24:     0x7efcb5140f10 - <rustc_middle[75501c6963a0c8e6]::ty::typeck_results::TypeckResults>::node_type_opt
  25:     0x7efcb4eb710e - <rustc_hir_typeck[3b7eb2450609c071]::fn_ctxt::FnCtxt>::label_fn_like
  26:     0x7efcb4eb2ec2 - <rustc_hir_typeck[3b7eb2450609c071]::fn_ctxt::FnCtxt>::report_arg_errors
  27:     0x7efcb35125be - <rustc_hir_typeck[3b7eb2450609c071]::fn_ctxt::FnCtxt>::check_argument_types
  28:     0x7efcb35c93e3 - <rustc_hir_typeck[3b7eb2450609c071]::fn_ctxt::FnCtxt>::check_method_argument_types
  29:     0x7efcb34fec1a - <rustc_hir_typeck[3b7eb2450609c071]::fn_ctxt::FnCtxt>::check_call
  30:     0x7efcb35154ca - <rustc_hir_typeck[3b7eb2450609c071]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  31:     0x7efcb359cf62 - <rustc_hir_typeck[3b7eb2450609c071]::fn_ctxt::FnCtxt>::check_block_with_expected
  32:     0x7efcb3515b5f - <rustc_hir_typeck[3b7eb2450609c071]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  33:     0x7efcb359d092 - <rustc_hir_typeck[3b7eb2450609c071]::fn_ctxt::FnCtxt>::check_block_with_expected
  34:     0x7efcb3515b5f - <rustc_hir_typeck[3b7eb2450609c071]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  35:     0x7efcb31c88fd - rustc_hir_typeck[3b7eb2450609c071]::check::check_fn
  36:     0x7efcb310de24 - rustc_hir_typeck[3b7eb2450609c071]::typeck
  37:     0x7efcb33dbd47 - rustc_query_impl[1ffb7affbb03209e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1ffb7affbb03209e]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[75501c6963a0c8e6]::query::erase::Erased<[u8; 8usize]>>
  38:     0x7efcb33db722 - rustc_query_system[c3767f58cc42410a]::query::plumbing::try_execute_query::<rustc_query_impl[1ffb7affbb03209e]::DynamicConfig<rustc_query_system[c3767f58cc42410a]::query::caches::VecCache<rustc_span[afe2d1e5c4333398]::def_id::LocalDefId, rustc_middle[75501c6963a0c8e6]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[1ffb7affbb03209e]::plumbing::QueryCtxt, false>
  39:     0x7efcb32a80f4 - rustc_query_impl[1ffb7affbb03209e]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  40:     0x7efcb43872cc - rustc_hir_analysis[f8382607e94a3f7b]::check_crate
  41:     0x7efcb437cc3a - rustc_interface[eddcebe151d82f7d]::passes::analysis
  42:     0x7efcb45ca1d7 - rustc_query_impl[1ffb7affbb03209e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1ffb7affbb03209e]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[75501c6963a0c8e6]::query::erase::Erased<[u8; 1usize]>>
  43:     0x7efcb45c9dc6 - rustc_query_system[c3767f58cc42410a]::query::plumbing::try_execute_query::<rustc_query_impl[1ffb7affbb03209e]::DynamicConfig<rustc_query_system[c3767f58cc42410a]::query::caches::SingleCache<rustc_middle[75501c6963a0c8e6]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[1ffb7affbb03209e]::plumbing::QueryCtxt, false>
  44:     0x7efcb45c9b7d - rustc_query_impl[1ffb7affbb03209e]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  45:     0x7efcb44e4d5d - std[f742926918452c50]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[eddcebe151d82f7d]::util::run_in_thread_with_globals<rustc_interface[eddcebe151d82f7d]::interface::run_compiler<core[95fcb21667417300]::result::Result<(), rustc_span[afe2d1e5c4333398]::ErrorGuaranteed>, rustc_driver_impl[13831840ef09002e]::run_compiler::{closure#1}>::{closure#0}, core[95fcb21667417300]::result::Result<(), rustc_span[afe2d1e5c4333398]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[95fcb21667417300]::result::Result<(), rustc_span[afe2d1e5c4333398]::ErrorGuaranteed>>
  46:     0x7efcb44e4013 - <<std[f742926918452c50]::thread::Builder>::spawn_unchecked_<rustc_interface[eddcebe151d82f7d]::util::run_in_thread_with_globals<rustc_interface[eddcebe151d82f7d]::interface::run_compiler<core[95fcb21667417300]::result::Result<(), rustc_span[afe2d1e5c4333398]::ErrorGuaranteed>, rustc_driver_impl[13831840ef09002e]::run_compiler::{closure#1}>::{closure#0}, core[95fcb21667417300]::result::Result<(), rustc_span[afe2d1e5c4333398]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[95fcb21667417300]::result::Result<(), rustc_span[afe2d1e5c4333398]::ErrorGuaranteed>>::{closure#1} as core[95fcb21667417300]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  47:     0x7efcb2170c25 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h725394f575a3e436
                               at /rustc/c1691db366c0f2e2341c60377c248ca2d9335076/library/alloc/src/boxed.rs:2007:9
  48:     0x7efcb2170c25 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h657091e5671149c6
                               at /rustc/c1691db366c0f2e2341c60377c248ca2d9335076/library/alloc/src/boxed.rs:2007:9
  49:     0x7efcb2170c25 - std::sys::unix::thread::Thread::new::thread_start::h51f0a69447f1c1c5
                               at /rustc/c1691db366c0f2e2341c60377c248ca2d9335076/library/std/src/sys/unix/thread.rs:108:17
  50:     0x7efcb1f139eb - <unknown>
  51:     0x7efcb1f977cc - <unknown>
  52:                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 attach the file at `/tmp/F/rustc-ice-2023-10-12T12:58:32.758469483Z-391861.txt` to your bug report

query stack during panic:
#0 [typeck] type-checking `test`
#1 [analysis] running analysis passes on this crate
end of query stack
error[E0425]: cannot find function `deref` in this scope
  --> treereduce.out:13:5
   |
13 |     deref(p);
   |     ^^^^^ not found in this scope

error: aborting due to 5 previous errors

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

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

Regression in nightly-2023-10-11
Regression in c30b28b
Regression in rust-lang-ci@1a6d2c9
#116250 🤔 cc @estebank

@estebank estebank self-assigned this Oct 12, 2023
estebank added a commit to estebank/rust that referenced this issue Oct 12, 2023
When we encounter a type error involving a closure, we try to typeck
prior closure invocations to see if they influenced the current expected
type. When trying to do so, ensure that the closure was defined in our
current scope.

Fix rust-lang#116658.
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 13, 2023
…rors

On type error involving closure, avoid ICE

When we encounter a type error involving a closure, we try to typeck prior closure invocations to see if they influenced the current expected type. When trying to do so, ensure that the closure was defined in our current scope.

Fix rust-lang#116658.
@bors bors closed this as completed in e761875 Oct 13, 2023
@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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