Skip to content

ICE: attempted to read from stolen value: rustc_middle::mir::Body', compiler/rustc_mir_transform/src/check_unsafety.rs:445:36 #91015

Closed
@billyb2

Description

@billyb2

Code

pub struct LightsResource {
    positions: [Vec2; 32],
    destruction_timers: [Option<(LightDestructionTimer, bool)>; 32],
    used_indexes: ArrayVec<usize, 32>,
    available_indexes: ArrayVec<usize, 32>,

}


impl LightsResource {
    pub fn new() -> Self {
        Self {
            positions: [Vec2::ZERO; 32],
            // Timer doesn't implement Copy, so I need to manually init the array :(
            destruction_timers: [None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None],
            used_indexes: ArrayVec::new(),
            available_indexes: ArrayVec::from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]),
        }
    }

    pub fn add_light_from_coords(&mut self, position: Vec2) -> LightHandle {
        // Move a value from available indexes to used indexes
        let index = self.available_indexes.pop().unwrap();
        println!("Adding {}", index);

        self.used_indexes.push(index);

        self.positions[index] = position;
        self.destruction_timers[index] = None;

        LightHandle::new(index)

    }

    pub fn add_light(&mut self, position: Vec2, destruction_timer: LightDestructionTimer, should_fade: bool) -> LightHandle {
        // Move a value from available indexes to used indexes
        let index = self.available_indexes.pop().unwrap();
        //println!("Adding {}", index);

        self.used_indexes.push(index);

        self.positions[index] = position;
        self.destruction_timers[index] = Some((destruction_timer, should_fade));

        LightHandle::new(index)

    }

    /// Make sure to remove or change the LightHandle for the entity as well
    pub fn remove_light(&mut self, handle: &LightHandle) {
        let index = handle.to_index();

        // Finds the index of the handle, then removes it
        let index_of_handle = self.used_indexes.iter().position(|u_index| *u_index == index).unwrap();

        self.used_indexes.swap_remove(index_of_handle);
        self.available_indexes.push(index);

    }

    // Copies every used position into the slice, returning the number of bytes written
    pub fn copy_pos_into_slice(&self, slice: &mut [Vec2]) -> usize {
        let mut num_bytes_written: usize = 0;

        slice.iter_mut().zip(self.used_indexes.iter()).for_each(|(dest, index)| {
            *dest = *self.positions.get(*index).unwrap();
            num_bytes_written += 1;

        });

        num_bytes_written

    }

    // Clones every used timer into the slice, returning the number of bytes written
    pub fn clone_timers_into_slice(&self, slice: &mut [Option<(LightDestructionTimer, bool)>]) -> usize {
        let mut num_bytes_written: usize = 0;

        slice.iter_mut().zip(self.used_indexes.iter()).for_each(|(dest, index)| {
            *dest = (*self.destruction_timers.get(*index).unwrap()).clone();
            num_bytes_written += 1;

        });

        num_bytes_written

    }

    pub fn len(&self) -> usize {
        self.used_indexes.len()

    }

    pub fn modify_light_pos(&mut self, handle: &LightHandle) -> Option<&mut Vec2> {
        let index = handle.to_index();

        println!("Mod {}", index);

        debug_assert!(self.used_indexes.contains(&index));

        self.positions.get_mut(index)
    }

    pub fn modify_destruction_timer(&mut self, handle: &LightHandle) -> Option<&mut Option<(LightDestructionTimer, bool)>> {
        let index = handle.to_index();

        debug_assert!(self.used_indexes.contains(&index));

        self.destruction_timers.get_mut(index)
    }

    pub fn light_in_use(&self, handle: &LightHandle) -> bool {
        let index = handle.to_index();

        self.used_indexes.contains(&index)

    }
}

Meta

I can't use the stable compiler, since I rely on some nightly only features

rustc --version --verbose:

rustc 1.58.0-nightly (ad4423997 2021-11-14)
binary: rustc
commit-hash: ad442399756573dccacb314b6bf8079964bcc72a
commit-date: 2021-11-14
host: x86_64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0

Error output

thread 'rustc' panicked at 'attempted to read from stolen value: rustc_middle::mir::Body', compiler/rustc_mir_transform/src/check_unsafety.rs:445:36
error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: rustc 1.58.0-nightly (ad4423997 2021-11-14) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z share-generics=y -Z strip=symbols -Z share-generics=y -C opt-level=3 -C embed-bitcode=no -C debuginfo=0 -C debug-assertions=on -C overflow-checks=off -C linker=/usr/bin/clang -C incremental -C link-arg=-fuse-ld=lld -C target-cpu=x86-64-v3 -C prefer-dynamic -C link-arg=-fuse-ld=lld --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [unsafety_check_result] unsafety-checking `graphics::<impl at crates/game_types/src/graphics.rs:239:1: 347:2>::remove_light::{closure#0}`
#1 [unsafety_check_result] unsafety-checking `graphics::<impl at crates/game_types/src/graphics.rs:239:1: 347:2>::remove_light`
#2 [analysis] running analysis passes on this crate
end of query stack
Backtrace

stack backtrace:
   0:     0x7f34b211313c - std::backtrace_rs::backtrace::libunwind::trace::h793e05efd273d0f4
                               at /rustc/ad442399756573dccacb314b6bf8079964bcc72a/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f34b211313c - std::backtrace_rs::backtrace::trace_unsynchronized::h640b7b86ff610c77
                               at /rustc/ad442399756573dccacb314b6bf8079964bcc72a/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f34b211313c - std::sys_common::backtrace::_print_fmt::h362fa2a4f354f877
                               at /rustc/ad442399756573dccacb314b6bf8079964bcc72a/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7f34b211313c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hf439e5ed84c74abd
                               at /rustc/ad442399756573dccacb314b6bf8079964bcc72a/library/std/src/sys_common/backtrace.rs:46:22
   4:     0x7f34b217037c - core::fmt::write::h72801a82c94e6ff1
                               at /rustc/ad442399756573dccacb314b6bf8079964bcc72a/library/core/src/fmt/mod.rs:1149:17
   5:     0x7f34b21038d5 - std::io::Write::write_fmt::h5562a8b6da0f0339
                               at /rustc/ad442399756573dccacb314b6bf8079964bcc72a/library/std/src/io/mod.rs:1697:15
   6:     0x7f34b2116390 - std::sys_common::backtrace::_print::hb29ddd998d02631c
                               at /rustc/ad442399756573dccacb314b6bf8079964bcc72a/library/std/src/sys_common/backtrace.rs:49:5
   7:     0x7f34b2116390 - std::sys_common::backtrace::print::h81965e3d7c90fbb6
                               at /rustc/ad442399756573dccacb314b6bf8079964bcc72a/library/std/src/sys_common/backtrace.rs:36:9
   8:     0x7f34b2116390 - std::panicking::default_hook::{{closure}}::h84db205ab6674b38
                               at /rustc/ad442399756573dccacb314b6bf8079964bcc72a/library/std/src/panicking.rs:211:50
   9:     0x7f34b2115f3b - std::panicking::default_hook::h1bf8bb4159936bca
                               at /rustc/ad442399756573dccacb314b6bf8079964bcc72a/library/std/src/panicking.rs:228:9
  10:     0x7f34b28ac781 - rustc_driver[e620c7401644acc4]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f34b2116ba9 - std::panicking::rust_panic_with_hook::hf8e86850fbbd03b1
                               at /rustc/ad442399756573dccacb314b6bf8079964bcc72a/library/std/src/panicking.rs:610:17
  12:     0x7f34b2116660 - std::panicking::begin_panic_handler::{{closure}}::h590a0d6060ff866e
                               at /rustc/ad442399756573dccacb314b6bf8079964bcc72a/library/std/src/panicking.rs:502:13
  13:     0x7f34b21135f4 - std::sys_common::backtrace::__rust_end_short_backtrace::h260b8bd1c848a03c
                               at /rustc/ad442399756573dccacb314b6bf8079964bcc72a/library/std/src/sys_common/backtrace.rs:139:18
  14:     0x7f34b21165c9 - rust_begin_unwind
                               at /rustc/ad442399756573dccacb314b6bf8079964bcc72a/library/std/src/panicking.rs:498:5
  15:     0x7f34b20db631 - core::panicking::panic_fmt::h7b8580d81fcbbacd
                               at /rustc/ad442399756573dccacb314b6bf8079964bcc72a/library/core/src/panicking.rs:106:14
  16:     0x7f34b3c089d4 - rustc_mir_transform[84d977a3cfe7a6c6]::check_unsafety::unsafety_check_result
  17:     0x7f34b3c03ded - <rustc_mir_transform[84d977a3cfe7a6c6]::check_unsafety::provide::{closure#0} as core[cc79c391059f8e46]::ops::function::FnOnce<(rustc_middle[93690e4789d7fe1d]::ty::context::TyCtxt, rustc_span[2d5555579096f1fe]::def_id::LocalDefId)>>::call_once
  18:     0x7f34b32ccb7d - <rustc_middle[93690e4789d7fe1d]::dep_graph::dep_node::DepKind as rustc_query_system[efb192c4209e4e11]::dep_graph::DepKind>::with_deps::<rustc_query_system[efb192c4209e4e11]::query::plumbing::try_load_from_disk_and_cache_in_memory<rustc_query_impl[e405c240d479aca8]::plumbing::QueryCtxt, rustc_span[2d5555579096f1fe]::def_id::LocalDefId, &rustc_middle[93690e4789d7fe1d]::mir::query::UnsafetyCheckResult>::{closure#0}, &rustc_middle[93690e4789d7fe1d]::mir::query::UnsafetyCheckResult>
  19:     0x7f34b4c34270 - rustc_query_system[efb192c4209e4e11]::query::plumbing::try_load_from_disk_and_cache_in_memory::<rustc_query_impl[e405c240d479aca8]::plumbing::QueryCtxt, rustc_span[2d5555579096f1fe]::def_id::LocalDefId, &rustc_middle[93690e4789d7fe1d]::mir::query::UnsafetyCheckResult>
  20:     0x7f34b416b18b - rustc_query_system[efb192c4209e4e11]::query::plumbing::try_execute_query::<rustc_query_impl[e405c240d479aca8]::plumbing::QueryCtxt, rustc_query_system[efb192c4209e4e11]::query::caches::DefaultCache<rustc_span[2d5555579096f1fe]::def_id::LocalDefId, &rustc_middle[93690e4789d7fe1d]::mir::query::UnsafetyCheckResult>>
  21:     0x7f34b41fdce1 - <rustc_query_impl[e405c240d479aca8]::Queries as rustc_middle[93690e4789d7fe1d]::ty::query::QueryEngine>::unsafety_check_result
  22:     0x7f34b3c0be24 - rustc_mir_transform[84d977a3cfe7a6c6]::check_unsafety::unsafety_check_result
  23:     0x7f34b3c03ded - <rustc_mir_transform[84d977a3cfe7a6c6]::check_unsafety::provide::{closure#0} as core[cc79c391059f8e46]::ops::function::FnOnce<(rustc_middle[93690e4789d7fe1d]::ty::context::TyCtxt, rustc_span[2d5555579096f1fe]::def_id::LocalDefId)>>::call_once
  24:     0x7f34b4cd23f3 - <rustc_query_system[efb192c4209e4e11]::dep_graph::graph::DepGraph<rustc_middle[93690e4789d7fe1d]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[93690e4789d7fe1d]::ty::context::TyCtxt, rustc_span[2d5555579096f1fe]::def_id::LocalDefId, &rustc_middle[93690e4789d7fe1d]::mir::query::UnsafetyCheckResult>
  25:     0x7f34b4c997fe - rustc_data_structures[8eb9d08fbf3883e5]::stack::ensure_sufficient_stack::<(&rustc_middle[93690e4789d7fe1d]::mir::query::UnsafetyCheckResult, rustc_query_system[efb192c4209e4e11]::dep_graph::graph::DepNodeIndex), rustc_query_system[efb192c4209e4e11]::query::plumbing::execute_job<rustc_query_impl[e405c240d479aca8]::plumbing::QueryCtxt, rustc_span[2d5555579096f1fe]::def_id::LocalDefId, &rustc_middle[93690e4789d7fe1d]::mir::query::UnsafetyCheckResult>::{closure#3}>
  26:     0x7f34b416b2bb - rustc_query_system[efb192c4209e4e11]::query::plumbing::try_execute_query::<rustc_query_impl[e405c240d479aca8]::plumbing::QueryCtxt, rustc_query_system[efb192c4209e4e11]::query::caches::DefaultCache<rustc_span[2d5555579096f1fe]::def_id::LocalDefId, &rustc_middle[93690e4789d7fe1d]::mir::query::UnsafetyCheckResult>>
  27:     0x7f34b4bb06f8 - rustc_query_system[efb192c4209e4e11]::query::plumbing::force_query::<rustc_query_impl[e405c240d479aca8]::queries::unsafety_check_result, rustc_query_impl[e405c240d479aca8]::plumbing::QueryCtxt>
  28:     0x7f34b4cabde1 - rustc_query_impl[e405c240d479aca8]::query_callbacks::unsafety_check_result::force_from_dep_node
  29:     0x7f34b4fc8b91 - <rustc_middle[93690e4789d7fe1d]::ty::context::TyCtxt as rustc_query_system[efb192c4209e4e11]::dep_graph::DepContext>::try_force_from_dep_node
  30:     0x7f34b420ac5c - <rustc_query_system[efb192c4209e4e11]::dep_graph::graph::DepGraph<rustc_middle[93690e4789d7fe1d]::dep_graph::dep_node::DepKind>>::try_mark_previous_green::<rustc_query_impl[e405c240d479aca8]::plumbing::QueryCtxt>
  31:     0x7f34b420a0c5 - <rustc_query_system[efb192c4209e4e11]::dep_graph::graph::DepGraph<rustc_middle[93690e4789d7fe1d]::dep_graph::dep_node::DepKind>>::try_mark_previous_green::<rustc_query_impl[e405c240d479aca8]::plumbing::QueryCtxt>
  32:     0x7f34b420a0c5 - <rustc_query_system[efb192c4209e4e11]::dep_graph::graph::DepGraph<rustc_middle[93690e4789d7fe1d]::dep_graph::dep_node::DepKind>>::try_mark_previous_green::<rustc_query_impl[e405c240d479aca8]::plumbing::QueryCtxt>
  33:     0x7f34b4150026 - rustc_query_system[efb192c4209e4e11]::query::plumbing::ensure_must_run::<rustc_query_impl[e405c240d479aca8]::plumbing::QueryCtxt, rustc_span[2d5555579096f1fe]::def_id::LocalDefId, &rustc_middle[93690e4789d7fe1d]::ty::context::TypeckResults>
  34:     0x7f34b41fe32c - <rustc_query_impl[e405c240d479aca8]::Queries as rustc_middle[93690e4789d7fe1d]::ty::query::QueryEngine>::mir_borrowck
  35:     0x7f34b3ae2a97 - <rustc_middle[93690e4789d7fe1d]::hir::map::Map>::par_body_owners::<rustc_interface[f89f8228a4e35bc7]::passes::analysis::{closure#2}::{closure#0}>
  36:     0x7f34b47814d8 - <rustc_session[cec017cef00f19c9]::session::Session>::time::<(), rustc_interface[f89f8228a4e35bc7]::passes::analysis::{closure#2}>
  37:     0x7f34b475dae5 - rustc_interface[f89f8228a4e35bc7]::passes::analysis
  38:     0x7f34b4cee6f0 - <rustc_query_system[efb192c4209e4e11]::dep_graph::graph::DepGraph<rustc_middle[93690e4789d7fe1d]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[93690e4789d7fe1d]::ty::context::TyCtxt, (), core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>>
  39:     0x7f34b4c948b3 - rustc_data_structures[8eb9d08fbf3883e5]::stack::ensure_sufficient_stack::<(core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>, rustc_query_system[efb192c4209e4e11]::dep_graph::graph::DepNodeIndex), rustc_query_system[efb192c4209e4e11]::query::plumbing::execute_job<rustc_query_impl[e405c240d479aca8]::plumbing::QueryCtxt, (), core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>>::{closure#3}>
  40:     0x7f34b4bf4b46 - rustc_query_system[efb192c4209e4e11]::query::plumbing::try_execute_query::<rustc_query_impl[e405c240d479aca8]::plumbing::QueryCtxt, rustc_query_system[efb192c4209e4e11]::query::caches::DefaultCache<(), core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>>>
  41:     0x7f34b4c5cd05 - rustc_query_system[efb192c4209e4e11]::query::plumbing::get_query::<rustc_query_impl[e405c240d479aca8]::queries::analysis, rustc_query_impl[e405c240d479aca8]::plumbing::QueryCtxt>
  42:     0x7f34b474d809 - <rustc_interface[f89f8228a4e35bc7]::passes::QueryContext>::enter::<rustc_driver[e620c7401644acc4]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>>
  43:     0x7f34b473b634 - <rustc_interface[f89f8228a4e35bc7]::interface::Compiler>::enter::<rustc_driver[e620c7401644acc4]::run_compiler::{closure#1}::{closure#2}, core[cc79c391059f8e46]::result::Result<core[cc79c391059f8e46]::option::Option<rustc_interface[f89f8228a4e35bc7]::queries::Linker>, rustc_errors[c8a333c965fedc03]::ErrorReported>>
  44:     0x7f34b472c5cd - rustc_span[2d5555579096f1fe]::with_source_map::<core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>, rustc_interface[f89f8228a4e35bc7]::interface::create_compiler_and_run<core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>, rustc_driver[e620c7401644acc4]::run_compiler::{closure#1}>::{closure#1}>
  45:     0x7f34b474cb7a - rustc_interface[f89f8228a4e35bc7]::interface::create_compiler_and_run::<core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>, rustc_driver[e620c7401644acc4]::run_compiler::{closure#1}>
  46:     0x7f34b472ff7b - <scoped_tls[3fea4c3dcac147b1]::ScopedKey<rustc_span[2d5555579096f1fe]::SessionGlobals>>::set::<rustc_interface[f89f8228a4e35bc7]::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface[f89f8228a4e35bc7]::interface::run_compiler<core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>, rustc_driver[e620c7401644acc4]::run_compiler::{closure#1}>::{closure#0}, core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>>::{closure#0}::{closure#0}, core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>>
  47:     0x7f34b472f095 - std[a5529df289459975]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[f89f8228a4e35bc7]::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface[f89f8228a4e35bc7]::interface::run_compiler<core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>, rustc_driver[e620c7401644acc4]::run_compiler::{closure#1}>::{closure#0}, core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>>::{closure#0}, core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>>
  48:     0x7f34b472b162 - <<std[a5529df289459975]::thread::Builder>::spawn_unchecked<rustc_interface[f89f8228a4e35bc7]::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface[f89f8228a4e35bc7]::interface::run_compiler<core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>, rustc_driver[e620c7401644acc4]::run_compiler::{closure#1}>::{closure#0}, core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>>::{closure#0}, core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>>::{closure#1} as core[cc79c391059f8e46]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  49:     0x7f34b2121e93 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h771719d52c343434
                               at /rustc/ad442399756573dccacb314b6bf8079964bcc72a/library/alloc/src/boxed.rs:1694:9
  50:     0x7f34b2121e93 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hf441746dfa4b0f57
                               at /rustc/ad442399756573dccacb314b6bf8079964bcc72a/library/alloc/src/boxed.rs:1694:9
  51:     0x7f34b2121e93 - std::sys::unix::thread::Thread::new::thread_start::hfd168f9d312b29ca
                               at /rustc/ad442399756573dccacb314b6bf8079964bcc72a/library/std/src/sys/unix/thread.rs:106:17
  52:     0x7f34b2039259 - start_thread
  53:     0x7f34b1f465e3 - __GI___clone
  54:                0x0 - <unknown>

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) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions