Skip to content

nightly: ICE: borrow checker panic instead of error on borrow of moved value #94662

Description

@barryfam

Code

pub struct DataStruct();

pub struct HelperStruct<'n> {
    pub helpers: [Vec<&'n i64>; 2],
    pub is_empty: bool,
}

impl DataStruct {
    pub fn f(&self) -> HelperStruct
    {
        let helpers = [vec![], vec![]];

        HelperStruct { helpers, is_empty: helpers[0].is_empty() }  // borrow of moved value
    }
}

Meta

Playground beta 1.60.0-beta.2 correctly reports:

error[E0382]: borrow of moved value: `helpers`
--> src/lib.rs:13:43

But Playground nightly rustc 1.61.0-nightly (c274e4969 2022-03-05) instead ICE's

Error output

thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 13', compiler/rustc_infer/src/infer/region_constraints/mod.rs:446:9
...
query stack during panic:
#0 [mir_borrowck] borrow-checking `<impl at src/lib.rs:8:1: 15:2>::f`
#1 [analysis] running analysis passes on this crate
Backtrace

stack backtrace:
   0:     0x7fb9e9e01d2c - std::backtrace_rs::backtrace::libunwind::trace::hd9d6c66ed2138bb0
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7fb9e9e01d2c - std::backtrace_rs::backtrace::trace_unsynchronized::ha4edb04af5a111d2
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fb9e9e01d2c - std::sys_common::backtrace::_print_fmt::h34bfe6ef54352a7f
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7fb9e9e01d2c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h91638cd7890644b7
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7fb9e9e5bbec - core::fmt::write::h407f77bceaf22b75
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/core/src/fmt/mod.rs:1190:17
   5:     0x7fb9e9df2801 - std::io::Write::write_fmt::h85de75cd3cb86034
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/std/src/io/mod.rs:1655:15
   6:     0x7fb9e9e04c65 - std::sys_common::backtrace::_print::h9303e0f315439c4b
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7fb9e9e04c65 - std::sys_common::backtrace::print::h278cbd6c00b20bf7
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7fb9e9e04c65 - std::panicking::default_hook::{{closure}}::h66dc8e0c0481f9ac
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/std/src/panicking.rs:295:22
   9:     0x7fb9e9e04908 - std::panicking::default_hook::h3732f22170eb6fcb
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/std/src/panicking.rs:314:9
  10:     0x7fb9ea59a4a1 - rustc_driver[a243c3d9738e9cda]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7fb9e9e05501 - std::panicking::rust_panic_with_hook::hfa6a9afb1a6b2eff
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/std/src/panicking.rs:702:17
  12:     0x7fb9e9e051e7 - std::panicking::begin_panic_handler::{{closure}}::h6b37cfd8e0c1dd8a
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/std/src/panicking.rs:588:13
  13:     0x7fb9e9e021e4 - std::sys_common::backtrace::__rust_end_short_backtrace::hc59fb3f99f6cb43f
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/std/src/sys_common/backtrace.rs:138:18
  14:     0x7fb9e9e04f19 - rust_begin_unwind
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/std/src/panicking.rs:584:5
  15:     0x7fb9e9dc8a43 - core::panicking::panic_fmt::h7275fb82410a6b0a
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/core/src/panicking.rs:143:14
  16:     0x7fb9e9dc8982 - core::panicking::panic_bounds_check::h744a66d73287484a
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/core/src/panicking.rs:84:5
  17:     0x7fb9ec203d52 - rustc_middle[101c9dc362f50b21]::ty::relate::super_relate_tys::<rustc_infer[7aed9202d1444ef]::infer::combine::Generalizer>
  18:     0x7fb9ec1fb8eb - <rustc_infer[7aed9202d1444ef]::infer::combine::Generalizer as rustc_middle[101c9dc362f50b21]::ty::relate::TypeRelation>::tys
  19:     0x7fb9ec2008e6 - rustc_middle[101c9dc362f50b21]::ty::relate::super_relate_tys::<rustc_infer[7aed9202d1444ef]::infer::combine::Generalizer>
  20:     0x7fb9ec1fb8eb - <rustc_infer[7aed9202d1444ef]::infer::combine::Generalizer as rustc_middle[101c9dc362f50b21]::ty::relate::TypeRelation>::tys
  21:     0x7fb9ec1f4314 - <rustc_infer[7aed9202d1444ef]::infer::combine::CombineFields>::instantiate
  22:     0x7fb9ec240128 - <rustc_infer[7aed9202d1444ef]::infer::equate::Equate as rustc_middle[101c9dc362f50b21]::ty::relate::TypeRelation>::relate::<rustc_middle[101c9dc362f50b21]::ty::Ty>
  23:     0x7fb9eb43eac3 - rustc_middle[101c9dc362f50b21]::ty::relate::super_relate_tys::<rustc_infer[7aed9202d1444ef]::infer::equate::Equate>
  24:     0x7fb9ec245bf9 - <rustc_infer[7aed9202d1444ef]::infer::equate::Equate as rustc_middle[101c9dc362f50b21]::ty::relate::TypeRelation>::tys
  25:     0x7fb9ec146ee3 - <rustc_trait_selection[1ee877ab5e03c17]::traits::select::SelectionContext>::rematch_impl
  26:     0x7fb9ec14dd9d - <rustc_trait_selection[1ee877ab5e03c17]::traits::select::SelectionContext>::confirm_candidate
  27:     0x7fb9ec156726 - <rustc_trait_selection[1ee877ab5e03c17]::traits::select::SelectionContext>::select
  28:     0x7fb9ec194eaf - <rustc_trait_selection[1ee877ab5e03c17]::traits::fulfill::FulfillProcessor>::process_changed_obligations
  29:     0x7fb9ec1a57ee - <rustc_data_structures[de7a003bd3e1aa1c]::obligation_forest::ObligationForest<rustc_trait_selection[1ee877ab5e03c17]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[1ee877ab5e03c17]::traits::fulfill::FulfillProcessor, rustc_data_structures[de7a003bd3e1aa1c]::obligation_forest::Outcome<rustc_trait_selection[1ee877ab5e03c17]::traits::fulfill::PendingPredicateObligation, rustc_infer[7aed9202d1444ef]::traits::FulfillmentErrorCode>>
  30:     0x7fb9ec19479f - <rustc_trait_selection[1ee877ab5e03c17]::traits::fulfill::FulfillmentContext as rustc_infer[7aed9202d1444ef]::traits::engine::TraitEngine>::select_where_possible
  31:     0x7fb9eab4f2be - <rustc_infer[7aed9202d1444ef]::infer::InferCtxtBuilder>::enter::<core[f66f8263def5172a]::result::Result<alloc[16beeacba2f7b906]::vec::Vec<(&rustc_middle[101c9dc362f50b21]::ty::generics::GenericParamDef, alloc[16beeacba2f7b906]::string::String)>, ()>, <rustc_borrowck[a849ad32eca1c1c5]::MirBorrowckCtxt>::report_use_of_moved_or_uninitialized::{closure#10}>
  32:     0x7fb9eab86730 - <rustc_borrowck[a849ad32eca1c1c5]::MirBorrowckCtxt>::report_use_of_moved_or_uninitialized
  33:     0x7fb9ec7f5de7 - <rustc_borrowck[a849ad32eca1c1c5]::MirBorrowckCtxt>::check_if_path_or_subpath_is_moved
  34:     0x7fb9eab9b00a - <rustc_borrowck[a849ad32eca1c1c5]::MirBorrowckCtxt as rustc_mir_dataflow[5c02db949ca048c6]::framework::visitor::ResultsVisitor>::visit_statement_before_primary_effect
  35:     0x7fb9ebc1f7b3 - rustc_mir_dataflow[5c02db949ca048c6]::framework::visitor::visit_results::<rustc_borrowck[a849ad32eca1c1c5]::dataflow::BorrowckAnalyses<rustc_index[8e110a495b4bee61]::bit_set::BitSet<rustc_borrowck[a849ad32eca1c1c5]::dataflow::BorrowIndex>, rustc_index[8e110a495b4bee61]::bit_set::ChunkedBitSet<rustc_mir_dataflow[5c02db949ca048c6]::move_paths::MovePathIndex>, rustc_index[8e110a495b4bee61]::bit_set::ChunkedBitSet<rustc_mir_dataflow[5c02db949ca048c6]::move_paths::InitIndex>>, rustc_borrowck[a849ad32eca1c1c5]::dataflow::BorrowckAnalyses<rustc_mir_dataflow[5c02db949ca048c6]::framework::engine::Results<rustc_borrowck[a849ad32eca1c1c5]::dataflow::Borrows>, rustc_mir_dataflow[5c02db949ca048c6]::framework::engine::Results<rustc_mir_dataflow[5c02db949ca048c6]::impls::MaybeUninitializedPlaces>, rustc_mir_dataflow[5c02db949ca048c6]::framework::engine::Results<rustc_mir_dataflow[5c02db949ca048c6]::impls::EverInitializedPlaces>>, core[f66f8263def5172a]::iter::adapters::map::Map<rustc_middle[101c9dc362f50b21]::mir::traversal::ReversePostorder, rustc_borrowck[a849ad32eca1c1c5]::do_mir_borrowck::{closure#2}>, rustc_borrowck[a849ad32eca1c1c5]::MirBorrowckCtxt>
  36:     0x7fb9ebcb7707 - rustc_borrowck[a849ad32eca1c1c5]::do_mir_borrowck
  37:     0x7fb9ebcab79e - rustc_borrowck[a849ad32eca1c1c5]::mir_borrowck
  38:     0x7fb9ebca8340 - <rustc_borrowck[a849ad32eca1c1c5]::provide::{closure#0} as core[f66f8263def5172a]::ops::function::FnOnce<(rustc_middle[101c9dc362f50b21]::ty::context::TyCtxt, rustc_span[1b916fa4cb305af0]::def_id::LocalDefId)>>::call_once
  39:     0x7fb9ebe4f791 - rustc_query_system[1506d2c0f1ca8e4e]::query::plumbing::try_execute_query::<rustc_query_impl[5f52c835d70aa024]::plumbing::QueryCtxt, rustc_query_system[1506d2c0f1ca8e4e]::query::caches::DefaultCache<rustc_span[1b916fa4cb305af0]::def_id::LocalDefId, &rustc_middle[101c9dc362f50b21]::mir::query::BorrowCheckResult>>
  40:     0x7fb9ebf3045a - <rustc_query_impl[5f52c835d70aa024]::Queries as rustc_middle[101c9dc362f50b21]::ty::query::QueryEngine>::mir_borrowck
  41:     0x7fb9eb7a6ad8 - <rustc_middle[101c9dc362f50b21]::hir::map::Map>::par_body_owners::<rustc_interface[ee304f5e577cf6b9]::passes::analysis::{closure#2}::{closure#0}>
  42:     0x7fb9ec428998 - <rustc_session[7e14f15cd8696afc]::session::Session>::time::<(), rustc_interface[ee304f5e577cf6b9]::passes::analysis::{closure#2}>
  43:     0x7fb9ec414515 - rustc_interface[ee304f5e577cf6b9]::passes::analysis
  44:     0x7fb9ec8c650e - rustc_query_system[1506d2c0f1ca8e4e]::query::plumbing::try_execute_query::<rustc_query_impl[5f52c835d70aa024]::plumbing::QueryCtxt, rustc_query_system[1506d2c0f1ca8e4e]::query::caches::DefaultCache<(), core[f66f8263def5172a]::result::Result<(), rustc_errors[e9d593471e7e5a86]::ErrorGuaranteed>>>
  45:     0x7fb9ec9063ee - rustc_query_system[1506d2c0f1ca8e4e]::query::plumbing::get_query::<rustc_query_impl[5f52c835d70aa024]::queries::analysis, rustc_query_impl[5f52c835d70aa024]::plumbing::QueryCtxt>
  46:     0x7fb9ec3f26d4 - <rustc_interface[ee304f5e577cf6b9]::passes::QueryContext>::enter::<rustc_driver[a243c3d9738e9cda]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[f66f8263def5172a]::result::Result<(), rustc_errors[e9d593471e7e5a86]::ErrorGuaranteed>>
  47:     0x7fb9ec3d004a - <rustc_interface[ee304f5e577cf6b9]::interface::Compiler>::enter::<rustc_driver[a243c3d9738e9cda]::run_compiler::{closure#1}::{closure#2}, core[f66f8263def5172a]::result::Result<core[f66f8263def5172a]::option::Option<rustc_interface[ee304f5e577cf6b9]::queries::Linker>, rustc_errors[e9d593471e7e5a86]::ErrorGuaranteed>>
  48:     0x7fb9ec3e2e5f - rustc_span[1b916fa4cb305af0]::with_source_map::<core[f66f8263def5172a]::result::Result<(), rustc_errors[e9d593471e7e5a86]::ErrorGuaranteed>, rustc_interface[ee304f5e577cf6b9]::interface::create_compiler_and_run<core[f66f8263def5172a]::result::Result<(), rustc_errors[e9d593471e7e5a86]::ErrorGuaranteed>, rustc_driver[a243c3d9738e9cda]::run_compiler::{closure#1}>::{closure#1}>
  49:     0x7fb9ec3d0f24 - rustc_interface[ee304f5e577cf6b9]::interface::create_compiler_and_run::<core[f66f8263def5172a]::result::Result<(), rustc_errors[e9d593471e7e5a86]::ErrorGuaranteed>, rustc_driver[a243c3d9738e9cda]::run_compiler::{closure#1}>
  50:     0x7fb9ec3cef42 - <scoped_tls[a76d38c46f15ed9e]::ScopedKey<rustc_span[1b916fa4cb305af0]::SessionGlobals>>::set::<rustc_interface[ee304f5e577cf6b9]::interface::run_compiler<core[f66f8263def5172a]::result::Result<(), rustc_errors[e9d593471e7e5a86]::ErrorGuaranteed>, rustc_driver[a243c3d9738e9cda]::run_compiler::{closure#1}>::{closure#0}, core[f66f8263def5172a]::result::Result<(), rustc_errors[e9d593471e7e5a86]::ErrorGuaranteed>>
  51:     0x7fb9ec3cd21f - std[54a224735ab911a]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[ee304f5e577cf6b9]::util::run_in_thread_pool_with_globals<rustc_interface[ee304f5e577cf6b9]::interface::run_compiler<core[f66f8263def5172a]::result::Result<(), rustc_errors[e9d593471e7e5a86]::ErrorGuaranteed>, rustc_driver[a243c3d9738e9cda]::run_compiler::{closure#1}>::{closure#0}, core[f66f8263def5172a]::result::Result<(), rustc_errors[e9d593471e7e5a86]::ErrorGuaranteed>>::{closure#0}, core[f66f8263def5172a]::result::Result<(), rustc_errors[e9d593471e7e5a86]::ErrorGuaranteed>>
  52:     0x7fb9ec3cd509 - <<std[54a224735ab911a]::thread::Builder>::spawn_unchecked_<rustc_interface[ee304f5e577cf6b9]::util::run_in_thread_pool_with_globals<rustc_interface[ee304f5e577cf6b9]::interface::run_compiler<core[f66f8263def5172a]::result::Result<(), rustc_errors[e9d593471e7e5a86]::ErrorGuaranteed>, rustc_driver[a243c3d9738e9cda]::run_compiler::{closure#1}>::{closure#0}, core[f66f8263def5172a]::result::Result<(), rustc_errors[e9d593471e7e5a86]::ErrorGuaranteed>>::{closure#0}, core[f66f8263def5172a]::result::Result<(), rustc_errors[e9d593471e7e5a86]::ErrorGuaranteed>>::{closure#1} as core[f66f8263def5172a]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  53:     0x7fb9e9e0f8c3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hb7ce1f9a74daab59
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/alloc/src/boxed.rs:1854:9
  54:     0x7fb9e9e0f8c3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc28d1f774d95b80d
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/alloc/src/boxed.rs:1854:9
  55:     0x7fb9e9e0f8c3 - std::sys::unix::thread::Thread::new::thread_start::h7c8916b17d3c6d45
                               at /rustc/c274e4969f058b1c644243181ece9f829efa7594/library/std/src/sys/unix/thread.rs:108:17
  56:     0x7fb9e9d3f609 - start_thread
  57:     0x7fb9e9c58163 - clone
  58:                0x0 - <unknown>

Activity

  1. added
    C-bugCategory: This is a bug.
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Mar 6, 2022
  2. compiler-errors commented on Mar 7, 2022

    @compiler-errors
    Contributor

    This seems to have regressed a few days ago. Maybe an infer variable is leaking out of a probe. I'll take a look.

    @rustbot claim

  3. compiler-errors commented on Mar 7, 2022

    @compiler-errors
    Contributor

    searched nightlies: from nightly-2022-03-02 to nightly-2022-03-04
    regressed nightly: nightly-2022-03-04
    searched commit range: 8769f4e...10913c0
    regressed commit: 2f8d1a8

    bisected with cargo-bisect-rustc v0.6.1

    Host triple: x86_64-unknown-linux-gnu
    Reproduce with:

    cargo bisect-rustc --regress=ice --start=2022-03-02 --end=2022-03-04 

    Perhaps there's an escaping infer variable in #94375.

  4. added a commit that references this issue on Mar 7, 2022
    c0c452b
  5. WaffleLapkin commented on Mar 7, 2022

    @WaffleLapkin
    Member

    It seems like that was caused by my PR (#94375). @compiler-errors can you explain what was the problem? I don't think I understood it after looking on the fix...

  6. compiler-errors commented on Mar 7, 2022

    @compiler-errors
    Contributor

    @WaffleLapkin: So the type that we try to process the copy obligation for has a region variable (I think it was like &mut '_#0r Vec<&'n i64> where '_#0r is a region variable), but since that new infcx is a fresh/empty one, that region variable doesn't exist in the new infcx's tables. I erased the regions in that type to fix the ICE, since we only really care about trait obligations anyways.

    Alternatively, before passing it to the new infcx, we could instead pass the type to something like like InferCtxt::fully_resolve using the infcx that is stored in the MirBorrowckCtxt. Not sure if that gets rid of the region variable though.

    Lemme know if you need a better explanation, or ping me on zulip or whatev.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions