rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.36k stars 12.72k forks source link

compiler panic when moving struct definition #93096

Closed zvkemp closed 1 year ago

zvkemp commented 2 years ago

Code

Code is part of a private repo, so I can't share everything. The change involved moving a struct definition (the ApplicationSummaryKey in the below example) from one module to a new submodule of that module. It is triggered by cargo build or cargo test (possibly other commands). Was not triggered by nightly, but it's unclear if that's because there wasn't a stale nightly build already.

This is the function at the top of the query stack when the panic occurs:

    pub(crate) async fn commit_buffer_in_transaction(
        &mut self,
        db: &mut sqlx::Transaction<'_, Postgres>,
    ) -> Result<HashSet<ApplicationSummaryKey<T::Span>>, Error> {
        let mut keys = HashSet::new();

        for (key, summary) in self.data.drain() {
            summary.commit(&mut *db).await?;
            keys.insert(key);
        }

        Ok(keys)
    }

Also note this crate is part of a workspace, and the panic only happens when run from the workspace root; it does not happen if run in the crate's subdirectory. A cargo clean -p {crate} fixed the issue, and now I cannot reproduce it.

Meta

rustc --version --verbose:

rustc 1.58.0 (02072b482 2022-01-11)
binary: rustc
commit-hash: 02072b482a8b5357f7fb5e5637444ae30e423c40
commit-date: 2022-01-11
host: aarch64-apple-darwin
release: 1.58.0
LLVM version: 13.0.0

Error output

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', /rustc/02072b482a8b5357f7fb5e5637444ae30e423c40/compiler/rustc_hir/src/definitions.rs:452:14
Backtrace

``` stack backtrace: 0: _rust_begin_unwind 1: core::panicking::panic_fmt 2: core::panicking::panic 3: ::def_path_hash_to_def_id 4: as rustc_middle::dep_graph::dep_node::DepNodeExt>::extract_def_id 5: rustc_query_impl::query_callbacks::hir_owner::force_from_dep_node 6: ::try_force_from_dep_node 7: >::try_mark_previous_green:: 8: >::try_mark_previous_green:: 9: >::try_mark_previous_green:: 10: >::try_mark_green:: 11: rustc_query_system::query::plumbing::try_load_from_disk_and_cache_in_memory:: 12: rustc_query_system::query::plumbing::try_execute_query::> 13: rustc_query_system::query::plumbing::get_query:: 14: ::visit_rvalue 15: rustc_mir_transform::check_unsafety::unsafety_check_result 16: >::call_once 17: >::with_task:: 18: rustc_data_structures::stack::ensure_sufficient_stack::<(&rustc_middle::mir::query::UnsafetyCheckResult, rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job::{closure#3}> 19: rustc_query_system::query::plumbing::try_execute_query::> 20: rustc_query_system::query::plumbing::force_query:: 21: rustc_query_impl::query_callbacks::unsafety_check_result::force_from_dep_node 22: ::try_force_from_dep_node 23: >::try_mark_previous_green:: 24: >::try_mark_previous_green:: 25: >::try_mark_previous_green:: 26: >::try_mark_green:: 27: rustc_query_system::query::plumbing::try_load_from_disk_and_cache_in_memory:: 28: rustc_query_system::query::plumbing::try_execute_query::> 29: rustc_query_system::query::plumbing::get_query:: 30: rustc_typeck::collect::type_of::type_of 31: >::with_task:: 32: rustc_data_structures::stack::ensure_sufficient_stack::<(&rustc_middle::ty::TyS, rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job::{closure#3}> 33: rustc_query_system::query::plumbing::try_execute_query::> 34: rustc_query_system::query::plumbing::get_query:: 35: ::expand_opaque_ty 36: as core::iter::traits::collect::Extend<&rustc_middle::ty::TyS>>::extend::>, ru stc_middle::ty::util::fold_list as rustc_middle::ty::fold::TypeFoldable>::super_fold_with::{closure#0}>::{closure#1}>> 37: rustc_middle::ty::util::fold_list:: as rustc_middle::ty::fold::TypeFoldable>::super_fold_with::{closure#0}> 38: <&rustc_middle::ty::TyS as rustc_middle::ty::fold::TypeFoldable>::super_fold_with:: 39: as core::iter::traits::collect::Extend>::extend::>, <&rustc_middle::ty::list::List as rustc_middle::ty::fold::TypeFoldable>::super_fold_with::{closure#0}>> 40: <&rustc_middle::ty::list::List as rustc_middle::ty::fold::TypeFoldable>::fold_with:: 41: <&rustc_middle::ty::TyS as rustc_middle::ty::fold::TypeFoldable>::super_fold_with:: 42: <&rustc_middle::ty::list::List as rustc_middle::ty::fold::TypeFoldable>::fold_with:: 43: ::expand_opaque_ty 44: ::expand_opaque_ty 45: ::try_expand_impl_trait_type 46: rustc_typeck::check::check::check_item_type 47: ::visit_item_likes_in_module:: 48: rustc_typeck::check::check::check_mod_item_types 49: >::with_task:: 50: rustc_data_structures::stack::ensure_sufficient_stack::<((), rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job::{clo sure#3}> 51: rustc_query_system::query::plumbing::try_execute_query::> 52: rustc_query_system::query::plumbing::get_query:: 53: ::for_each_module:: 54: rustc_typeck::check_crate 55: rustc_interface::passes::analysis 56: >::with_task::> 57: rustc_data_structures::stack::ensure_sufficient_stack::<(core::result::Result<(), rustc_errors::ErrorReported>, rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job>::{closure#3}> 58: rustc_query_system::query::plumbing::try_execute_query::>> 59: rustc_query_system::query::plumbing::get_query:: 60: ::enter::> 61: ::enter::, rustc_errors::ErrorReported>> 62: rustc_span::with_source_map::, rustc_interface::interface::create_compiler_and_run, rustc_driver::run_compiler::{closure#1}>::{closure# 1}> 63: >::set::, rustc_driver: :run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>> note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. query stack during panic: #0 [unsafety_check_result] unsafety-checking `rollups::rollup_buffer::::commit_buffer_in_transaction::{closure#0}` #1 [unsafety_check_result] unsafety-checking `rollups::rollup_buffer::::commit_buffer_in_transaction` #2 [mir_borrowck] borrow-checking `rollups::rollup_buffer::::commit_buffer_in_transaction` #3 [type_of] computing type of `rollups::rollup_buffer::::commit_buffer_in_transaction::{opaque#0}` #4 [check_mod_item_types] checking item types in top-level module #5 [analysis] running analysis passes on this crate ```

Aaron1011 commented 2 years ago

@zvkemp Can you try the following to see if you can reproduce this again:

  1. Run cargo clean
  2. Undo the change you made (e.g. move ApplicationSummaryKey back to its original location, and undo any other changes you made)
  3. Run cargo build from the workspace root
  4. Re-apply the change (move ApplicationSummaryKey to the new location)
  5. Run cargo build again
zvkemp commented 2 years ago

@aaron1101 Unfortunately I can't reproduce the issue again using that procedure; in hindsight I should have copied the target directory state before running cargo clean. I'll reply to this issue again if I end up getting it working (or rather not working).

bergmark commented 2 years ago

I think I ran across the same issue, but it was after switching git branches multiple times so finding a reproduction seems hard :( I ran cargo test in crate-a and while cargo was compiling crate-b i got:

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', /rustc/02072b482a8b5357f7fb5e5637444ae30e423c40/compiler/rustc_hir/src/definitions.rs:452:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: 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.58.0 (02072b482 2022-01-11) running on x86_64-apple-darwin

note: compiler flags: -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C incremental --crate-type lib

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

query stack during panic:
#0 [unsafety_check_result] unsafety-checking `handler::account::account_get::{closure#0}`
#1 [unsafety_check_result] unsafety-checking `handler::account::account_get`
end of query stack
error: could not compile `crate-b`

a clean build resolved it.

zvkemp commented 2 years ago

I've had another panic with a similar stacktrace, again after globally renaming a struct. This one is only triggered by cargo test.

@aaron1101 I've backed up the target directory this time, so please let me know if there's anything you'd like me to look at in more detail.

Backtrace

``` thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', /rustc/02072b482a8b5357f7fb5e5637444ae30e423c40/compiler/rustc_hir/src/definitions.rs:452:14 stack backtrace: 0: _rust_begin_unwind 1: core::panicking::panic_fmt 2: core::panicking::panic 3: ::def_path_hash_to_def_id 4: as rustc_middle::dep_graph::dep_node::DepNodeExt>::extract_def_id 5: rustc_query_impl::query_callbacks::hir_owner::force_from_dep_node 6: ::try_force_from_dep_node 7: >::try_mark_previous_green:: 8: >::try_mark_previous_green:: 9: >::try_mark_green:: 10: rustc_query_system::query::plumbing::ensure_must_run:: 11: rustc_query_system::query::plumbing::get_query:: 12: >, ::par_visit_all_item_likes::{closure#0}>::{closure#0}::{closure#0}> as core::ops::function::FnOnce<()>>::call_once 13: rustc_data_structures::sync::par_for_each_in::<&alloc::vec::Vec>, ::par_visit_all_item_likes::{closure#0}> 14: ::track_errors:: 15: rustc_typeck::check_crate 16: rustc_interface::passes::analysis 17: >::with_task::> 18: rustc_data_structures::stack::ensure_sufficient_stack::<(core::result::Result<(), rustc_errors::ErrorReported>, rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job>::{closure#3}> 19: rustc_query_system::query::plumbing::try_execute_query::>> 20: rustc_query_system::query::plumbing::get_query:: 21: ::enter::> 22: ::enter::, rustc_errors::ErrorReported>> 23: rustc_span::with_source_map::, rustc_interface::interface::create_compiler_and_run, rustc_driver::run_compiler::{closure#1}>::{closure#1}> 24: >::set::, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>> note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. error: internal compiler error: unexpected panic note: 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.58.0 (02072b482 2022-01-11) running on aarch64-apple-darwin note: compiler flags: -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C incremental note: some of the compiler flags provided by cargo are hidden query stack during panic: #0 [analysis] running analysis passes on this crate ```

Aaron1011 commented 2 years ago

@zvkemp Are you able to consistently reproduce the crash after running cargo clean by re-applying the sequence of building and editing that you performed?

rsalmei commented 2 years ago

I've just had it too, going to try cargo clean afterwards:

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', /rustc/02072b482a8b5357f7fb5e5637444ae30e423c40/compiler/rustc_hir/src/definitions.rs:452:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: 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.58.0 (02072b482 2022-01-11) running on x86_64-apple-darwin

note: compiler flags: -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C incremental --crate-type bin

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

query stack during panic:
#0 [evaluate_obligation] evaluating trait selection obligation `impl core::future::future::Future<Output = core::result::Result<alloc::boxed::Box<(dyn warp::reply::Reply + 'static)>, core::convert::Infallible>>: core::marker::Send`  |  = note: this failure-note originates in the macro `mk_route` (in Nightly builds, run with -Z macro-backtrace for more info)

#1 [typeck] type-checking `api::run`
end of query stack

EDIT: cargo clean did fix it. I was refactoring some things and moved a module inside another directory. I think that was the trigger.

ineiti commented 2 years ago

Same thing here, but cargo clean fixed it. I had a not-too-old git-commit, so I tried to do:

git stash
cargo clean
cargo build
git stash pop
cargo build

But it didn't trigger the error...

xanathar commented 2 years ago

Same here.

Running cargo test after an important refactoring made rustc panic on x86_64-pc-windows-msvc.

Without thinking twice I ran cargo clean and that fixed everything, so I assume it was some intermediate files which were inconsistent, maybe caused by rust analyzer running cargo check while editing?

Anyway, the gist is that I can't provide a minimal source code reproing because 1) it seems unrelated to the specific source code 2) if clean fixes, code probably wouldn't repro anyway.

Meta

rustc --version --verbose:

rustc 1.58.0 (02072b482 2022-01-11)
binary: rustc
commit-hash: 02072b482a8b5357f7fb5e5637444ae30e423c40
commit-date: 2022-01-11
host: x86_64-pc-windows-msvc
release: 1.58.0
LLVM version: 13.0.0

Error output

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', /rustc/02072b482a8b5357f7fb5e5637444ae30e423c40\compiler\rustc_hir\src\definitions.rs:452:14
Backtrace

``` thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', /rustc/02072b482a8b5357f7fb5e5637444ae30e423c40\compiler\rustc_hir\src\definitions.rs:452:14 stack backtrace: 0: 0x7ffd2ba19c3f - ::fmt::h4e35ab114ce29e2e 1: 0x7ffd2ba44aea - core::fmt::write::h83a1b8a9a204aefd 2: 0x7ffd2ba0b538 - ::fmt::h1ddade45cf8208fa 3: 0x7ffd2ba1d556 - std::panicking::take_hook::h2b301730edd12368 4: 0x7ffd2ba1cf35 - std::panicking::take_hook::h2b301730edd12368 5: 0x7ffd2bffd5de - ::visit_attribute 6: 0x7ffd2ba1de69 - std::panicking::rust_panic_with_hook::hcafb622216ee7b39 7: 0x7ffd2ba1d8df - rust_begin_unwind 8: 0x7ffd2ba1a587 - ::fmt::h4e35ab114ce29e2e 9: 0x7ffd2ba1d869 - rust_begin_unwind 10: 0x7ffd2ba78f20 - core::panicking::panic_fmt::h642c5216f3cb43f3 11: 0x7ffd2ba78e6c - core::panicking::panic::h4fc2634ac0de5286 12: 0x7ffd3045391a - ::def_path_hash_to_def_id 13: 0x7ffd3054714e - as rustc_middle[fc5481cb4acc12cb]::dep_graph::dep_node::DepNodeExt>::extract_def_id 14: 0x7ffd2f7bdd0e - rustc_query_impl[e09ea31778da6781]::query_callbacks::hir_owner 15: 0x7ffd30438613 - ::try_force_from_dep_node 16: 0x7ffd2f7f40fb - rustc_query_impl[e09ea31778da6781]::query_callbacks::diagnostic_hir_wf_check 17: 0x7ffd2f7f40d7 - rustc_query_impl[e09ea31778da6781]::query_callbacks::diagnostic_hir_wf_check 18: 0x7ffd2f7f40d7 - rustc_query_impl[e09ea31778da6781]::query_callbacks::diagnostic_hir_wf_check 19: 0x7ffd2f7f40d7 - rustc_query_impl[e09ea31778da6781]::query_callbacks::diagnostic_hir_wf_check 20: 0x7ffd2f7f40d7 - rustc_query_impl[e09ea31778da6781]::query_callbacks::diagnostic_hir_wf_check 21: 0x7ffd2f7f40d7 - rustc_query_impl[e09ea31778da6781]::query_callbacks::diagnostic_hir_wf_check 22: 0x7ffd2f7cc40d - rustc_query_impl[e09ea31778da6781]::query_callbacks::diagnostic_hir_wf_check 23: 0x7ffd2f4f876c - ::output_path 24: 0x7ffd2f64b552 - ::output_path 25: 0x7ffd2c1f1a01 - ::to_resolver_outputs 26: 0x7ffd2c147af6 - rustc_interface[f7d5b064990b81b2]::passes::analysis 27: 0x7ffd2f75282b - ::spec_to_self_profile_string 28: 0x7ffd2f827a6e - rustc_query_impl[e09ea31778da6781]::query_callbacks::diagnostic_hir_wf_check 29: 0x7ffd2f6f6561 - >::describe 30: 0x7ffd2f5f0591 - ::output_path 31: 0x7ffd2f726d22 - ::try_mark_green 32: 0x7ffd2c06d62a - ::fmt 33: 0x7ffd2c02362c - ::fmt 34: 0x7ffd2c014e1b - ::visit_ident 35: 0x7ffd2c041141 - ::fmt 36: 0x7ffd2c020643 - rustc_driver[12b05176f1464f4f]::pretty::print_after_hir_lowering 37: 0x7ffd2c0884b8 - ::fmt 38: 0x7ffd2ba2b8ec - std::sys::windows::thread::Thread::new::h10c3f3613eb8c5b7 39: 0x7ffdb36a54e0 - BaseThreadInitThunk 40: 0x7ffdb420485b - RtlUserThreadStart error: internal compiler error: unexpected panic note: 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.58.0 (02072b482 2022-01-11) running on x86_64-pc-windows-msvc note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type lib note: some of the compiler flags provided by cargo are hidden query stack during panic: #0 [analysis] running analysis passes on this crate end of query stack ```

Manishearth commented 2 years ago

I have an open source crate having this problem in https://github.com/manishearth/icu4x/tree/ice-dep-hash : cd utils/zerovec && cargo check --all-features

I'm unable to reproduce after cargo clean, but the last commit is what caused the ICE

workingjubilee commented 1 year ago

This is almost certainly a duplicate of this issue and was probably resolved in this PR: