Repository: rust
Issue: ICE: `Failed to extract DefId: opt_local_def_id_to_hir_id`
Labels: I-ICE,T-compiler,A-incr-comp,C-bug,S-needs-repro

<!--
Thank you for finding an Internal Compiler Error! 🧊  If possible, try to provide
a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for
how to create smaller examples.
http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/
-->

### Code

https://github.com/spacejam/sled/tree/ice_2023_09_03

Unfortunately the error does not persist after doing a `cargo clean` so I think the backtrace at the bottom might be the best source of info. Maybe this relates to incremental compilation etc...


### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```
λ rustc --version --verbose
rustc 1.71.0 (8ede3aae2 2023-07-12)
binary: rustc
commit-hash: 8ede3aae28fe6e4d52b38157d7bfe0d3bceef225
commit-date: 2023-07-12
host: aarch64-apple-darwin
release: 1.71.0
LLVM version: 16.0.5
```

### Error output

```
$ cargo build

warning: `panic` setting is ignored for `test` profile
   Compiling sled v1.0.0-alpha.117 (/Users/tylerneely/src/sled)
error[E0412]: cannot find type `PageCache` in this scope
  --> src/db.rs:27:9
   |
27 |     pc: PageCache<LEAF_FANOUT>,
   |         ^^^^^^^^^ not found in this scope
   |
note: struct `crate::pagecache::PageCache` exists but is inaccessible
  --> src/pagecache.rs:25:1
   |
25 | struct PageCache<const LEAF_FANOUT: usize> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not accessible

error[E0412]: cannot find type `PageCache` in this scope
  --> src/db.rs:88:9
   |
88 |     pc: PageCache<LEAF_FANOUT>,
   |         ^^^^^^^^^ not found in this scope
   |
note: struct `crate::pagecache::PageCache` exists but is inaccessible
  --> src/pagecache.rs:25:1
   |
25 | struct PageCache<const LEAF_FANOUT: usize> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not accessible

error[E0423]: expected value, found module `io`
   --> src/db.rs:100:18
    |
100 |             drop(io);
    |                  ^^ not a value

error[E0423]: expected value, found module `io`
   --> src/db.rs:114:28
    |
114 |         let flush_result = io.flush();
    |                            ^^- help: use the path separator to refer to an item: `::`

error[E0423]: expected value, found module `io`
   --> src/db.rs:123:17
    |
123 |                 io.set_error(&e);
    |                 ^^- help: use the path separator to refer to an item: `::`

error[E0422]: cannot find struct, variant or union type `PageCache` in this scope
   --> src/db.rs:515:18
    |
515 |         let pc = PageCache {
    |                  ^^^^^^^^^ not found in this scope
    |
note: struct `crate::pagecache::PageCache` exists but is inaccessible
   --> src/pagecache.rs:25:1
    |
25  | struct PageCache<const LEAF_FANOUT: usize> {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not accessible

error[E0412]: cannot find type `Dirty` in this scope
  --> src/pagecache.rs:37:48
   |
37 |     dirty: ConcurrentMap<(FlushEpoch, NodeId), Dirty<LEAF_FANOUT>>,
   |                                                ^^^^^ not found in this scope
   |
note: enum `crate::db::Dirty` exists but is inaccessible
  --> src/db.rs:62:1
   |
62 | enum Dirty<const LEAF_FANOUT: usize> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not accessible

error[E0433]: failed to resolve: use of undeclared type `Dirty`
   --> src/pagecache.rs:149:20
    |
149 |             if let Dirty::NotYetSerialized { .. } = &dirty_value {
    |                    ^^^^^ use of undeclared type `Dirty`
    |
note: enum `crate::db::Dirty` exists but is inaccessible
   --> src/db.rs:62:1
    |
62  | enum Dirty<const LEAF_FANOUT: usize> {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not accessible

error[E0433]: failed to resolve: use of undeclared type `Dirty`
   --> src/pagecache.rs:170:17
    |
170 |                 Dirty::MergedAndDeleted { node_id } => {
    |                 ^^^^^ use of undeclared type `Dirty`
    |
note: enum `crate::db::Dirty` exists but is inaccessible
   --> src/db.rs:62:1
    |
62  | enum Dirty<const LEAF_FANOUT: usize> {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not accessible

error[E0433]: failed to resolve: use of undeclared type `Dirty`
   --> src/pagecache.rs:180:17
    |
180 |                 Dirty::CooperativelySerialized {
    |                 ^^^^^ use of undeclared type `Dirty`
    |
note: enum `crate::db::Dirty` exists but is inaccessible
   --> src/db.rs:62:1
    |
62  | enum Dirty<const LEAF_FANOUT: usize> {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not accessible

error[E0433]: failed to resolve: use of undeclared type `Dirty`
   --> src/pagecache.rs:194:17
    |
194 |                 Dirty::NotYetSerialized { low_key, node } => {
    |                 ^^^^^ use of undeclared type `Dirty`
    |
note: enum `crate::db::Dirty` exists but is inaccessible
   --> src/db.rs:62:1
    |
62  | enum Dirty<const LEAF_FANOUT: usize> {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not accessible

error[E0433]: failed to resolve: use of undeclared type `Dirty`
   --> src/pagecache.rs:232:32
    |
232 |                         if let Dirty::CooperativelySerialized {
    |                                ^^^^^ use of undeclared type `Dirty`
    |
note: enum `crate::db::Dirty` exists but is inaccessible
   --> src/db.rs:62:1
    |
62  | enum Dirty<const LEAF_FANOUT: usize> {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not accessible

warning: unused imports: `AtomicPtr`, `Ordering`
 --> src/db.rs:9:25
  |
9 | use std::sync::atomic::{AtomicPtr, Ordering};
  |                         ^^^^^^^^^  ^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unused import: `RwLock`
  --> src/db.rs:18:16
   |
18 |     RawRwLock, RwLock,
   |                ^^^^^^

warning: unused imports: `BTreeMap`, `VecDeque`
 --> src/pagecache.rs:2:24
  |
2 | use std::collections::{BTreeMap, VecDeque};
  |                        ^^^^^^^^  ^^^^^^^^

warning: unused import: `std::fmt`
 --> src/pagecache.rs:3:5
  |
3 | use std::fmt;
  |     ^^^^^^^^

warning: unused imports: `ManuallyDrop`, `self`
 --> src/pagecache.rs:5:16
  |
5 | use std::mem::{self, ManuallyDrop};
  |                ^^^^  ^^^^^^^^^^^^

warning: unused import: `std::ops`
 --> src/pagecache.rs:6:5
  |
6 | use std::ops;
  |     ^^^^^^^^

warning: unused import: `std::ops::Bound`
 --> src/pagecache.rs:7:5
  |
7 | use std::ops::Bound;
  |     ^^^^^^^^^^^^^^^

warning: unused import: `std::ops::RangeBounds`
 --> src/pagecache.rs:8:5
  |
8 | use std::ops::RangeBounds;
  |     ^^^^^^^^^^^^^^^^^^^^^

warning: unused import: `mpsc`
  --> src/pagecache.rs:10:17
   |
10 | use std::sync::{mpsc, Arc};
   |                 ^^^^

warning: unused imports: `Duration`, `Instant`
  --> src/pagecache.rs:11:17
   |
11 | use std::time::{Duration, Instant};
   |                 ^^^^^^^^  ^^^^^^^

warning: unused import: `inline_array::InlineArray`
  --> src/pagecache.rs:15:5
   |
15 | use inline_array::InlineArray;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^

warning: unused imports: `ArcRwLockReadGuard`, `ArcRwLockWriteGuard`, `RawRwLock`, `RwLock`
  --> src/pagecache.rs:17:16
   |
17 |     lock_api::{ArcRwLockReadGuard, ArcRwLockWriteGuard},
   |                ^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^^
18 |     RawRwLock, RwLock,
   |     ^^^^^^^^^  ^^^^^^

warning: unused import: `stack_map::StackMap`
  --> src/pagecache.rs:20:5
   |
20 | use stack_map::StackMap;
   |     ^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at 'Failed to extract DefId: opt_local_def_id_to_hir_id 9a13619a56d9c890-f8da1f95cf1f9fcf', compiler/rustc_middle/src/dep_graph/dep_node.rs:181:17
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: <rustc_query_system::dep_graph::dep_node::DepNode<rustc_middle::dep_graph::dep_node::DepKind> as rustc_middle::dep_graph::dep_node::DepNodeExt>::extract_def_id::{closure#0}
   3: <rustc_middle::ty::context::TyCtxt>::def_path_hash_to_def_id
   4: <rustc_query_system::dep_graph::dep_node::DepNode<rustc_middle::dep_graph::dep_node::DepKind> as rustc_middle::dep_graph::dep_node::DepNodeExt>::extract_def_id
   5: <rustc_query_impl::plumbing::query_callback<rustc_query_impl::query_impl::opt_local_def_id_to_hir_id::QueryType>::{closure#0} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_query_system::dep_graph::dep_node::DepNode<rustc_middle::dep_graph::dep_node::DepKind>)>>::call_once
   6: <rustc_query_system::dep_graph::graph::DepGraphData<rustc_middle::dep_graph::dep_node::DepKind>>::try_mark_previous_green::<rustc_query_impl::plumbing::QueryCtxt>
   7: <rustc_query_system::dep_graph::graph::DepGraphData<rustc_middle::dep_graph::dep_node::DepKind>>::try_mark_previous_green::<rustc_query_impl::plumbing::QueryCtxt>
   8: <rustc_query_system::dep_graph::graph::DepGraphData<rustc_middle::dep_graph::dep_node::DepKind>>::try_mark_green::<rustc_query_impl::plumbing::QueryCtxt>
   9: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
  10: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, rustc_middle::query::erase::Erased<[u8; 8]>>>
  11: rustc_hir_typeck::typeck
  12: rustc_hir_analysis::check_crate
  13: rustc_interface::passes::analysis
  14: <rustc_interface::queries::QueryResult<&rustc_middle::ty::context::GlobalCtxt>>::enter::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#4}>
  15: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
  16: rustc_span::set_source_map::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  17: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: 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.71.0 (8ede3aae2 2023-07-12) running on aarch64-apple-darwin

note: compiler flags: --crate-type lib -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C incremental=[REDACTED] -C target-cpu=native

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [type_of] computing type of `db::Db::{constant#1}`
#1 [typeck] type-checking `db::Db::{constant#1}`
#2 [used_trait_imports] finding used_trait_imports `db::Db::{constant#1}`
#3 [analysis] running analysis passes on this crate
end of query stack
there was a panic while trying to force a dep node
try_mark_green dep node stack:
#0 opt_def_kind(thread 'rustc' panicked at 'Failed to extract DefId: opt_def_kind 9a13619a56d9c890-f8da1f95cf1f9fcf', compiler/rustc_middle/src/dep_graph/dep_node.rs:181:17
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: <rustc_query_system::dep_graph::dep_node::DepNode<rustc_middle::dep_graph::dep_node::DepKind> as rustc_middle::dep_graph::dep_node::DepNodeExt>::extract_def_id::{closure#0}
   3: <rustc_middle::ty::context::TyCtxt>::def_path_hash_to_def_id
   4: <rustc_middle::dep_graph::dep_node::DepKind as rustc_query_system::dep_graph::DepKind>::debug_node
   5: core::fmt::write
   6: <&std::io::stdio::Stderr as std::io::Write>::write_fmt
   7: std::io::stdio::_eprint
   8: rustc_query_system::dep_graph::graph::print_markframe_trace::<rustc_middle::dep_graph::dep_node::DepKind>
   9: <rustc_query_system::dep_graph::graph::DepGraphData<rustc_middle::dep_graph::dep_node::DepKind>>::try_mark_previous_green::<rustc_query_impl::plumbing::QueryCtxt>
  10: <rustc_query_system::dep_graph::graph::DepGraphData<rustc_middle::dep_graph::dep_node::DepKind>>::try_mark_previous_green::<rustc_query_impl::plumbing::QueryCtxt>
  11: <rustc_query_system::dep_graph::graph::DepGraphData<rustc_middle::dep_graph::dep_node::DepKind>>::try_mark_green::<rustc_query_impl::plumbing::QueryCtxt>
  12: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
  13: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, rustc_middle::query::erase::Erased<[u8; 8]>>>
  14: rustc_hir_typeck::typeck
  15: rustc_hir_analysis::check_crate
  16: rustc_interface::passes::analysis
  17: <rustc_interface::queries::QueryResult<&rustc_middle::ty::context::GlobalCtxt>>::enter::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#4}>
  18: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
  19: rustc_span::set_source_map::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  20: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: 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.71.0 (8ede3aae2 2023-07-12) running on aarch64-apple-darwin

note: compiler flags: --crate-type lib -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C incremental=[REDACTED] -C target-cpu=native

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [type_of] computing type of `db::Db::{constant#1}`
#1 [typeck] type-checking `db::Db::{constant#1}`
#2 [used_trait_imports] finding used_trait_imports `db::Db::{constant#1}`
#3 [analysis] running analysis passes on this crate
end of query stack
there was a panic while trying to force a dep node
try_mark_green dep node stack:
#0 used_trait_imports(sled[9a13]::db::Db::{constant#1})
end of try_mark_green dep node stack
Some errors have detailed explanations: E0412, E0422, E0423, E0433.
For more information about an error, try `rustc --explain E0412`.
warning: `sled` (lib) generated 13 warnings
error: could not compile `sled` (lib) due to 12 previous errors; 13 warnings emitted
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary><strong>Backtrace</strong></summary>
<p>

```

```

</p>
</details>