rust-lang / rust

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

Failed to extract DefId: opt_local_def_id_to_hir_id on sqlx-postgres crate #114970

Open Flowneee opened 1 year ago

Flowneee commented 1 year ago

Code

I was not unable (yet) produce a minimal example. I used a https://github.com/launchbadge/sqlx (master branch), and applied following diff (just comment out one structure field):

$ g diff @
diff --git a/sqlx-postgres/src/options/mod.rs b/sqlx-postgres/src/options/mod.rs
index 581880a3..dcac1a5a 100644
--- a/sqlx-postgres/src/options/mod.rs
+++ b/sqlx-postgres/src/options/mod.rs
@@ -87,7 +87,7 @@ mod ssl_mode;
 /// ```
 #[derive(Debug, Clone)]
 pub struct PgConnectOptions {
-    pub(crate) host: String,
+    //pub(crate) host: String,
     pub(crate) port: u16,
     pub(crate) socket: Option<PathBuf>,
     pub(crate) username: String,

Even after I resolved all problems with code (making this field unused), panic still occur.

Meta

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: x86_64-unknown-linux-gnu
release: 1.71.0
LLVM version: 16.0.5

This bug not present on beta or nightly compilers.

Error output

error: could not compile `sqlx-postgres` (lib)
Backtrace

``` $ RUST_BACKTRACE=1 c c -p sqlx-postgres Checking sqlx-postgres v0.7.1 (/home/.../sqlx/sqlx-postgres) thread 'rustc' panicked at 'Failed to extract DefId: opt_local_def_id_to_hir_id 9ecebc817eb23e30-a5d060b145ccfcc0', compiler/rustc_middle/src/dep_graph/dep_node.rs:181:17 stack backtrace: 0: rust_begin_unwind at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/panicking.rs:593:5 1: core::panicking::panic_fmt at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/panicking.rs:67:14 2: as rustc_middle::dep_graph::dep_node::DepNodeExt>::extract_def_id::{closure#0} 3: as rustc_middle::dep_graph::dep_node::DepNodeExt>::extract_def_id 4: ::{closure#0} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_query_system::dep_graph::dep_node::DepNode)>>::call_once 5: >::try_mark_previous_green:: 6: >::try_mark_previous_green:: 7: >::try_mark_previous_green:: 8: >::try_mark_previous_green:: 9: >::try_mark_previous_green:: 10: >::try_mark_previous_green:: 11: >::try_mark_previous_green:: 12: rustc_query_system::query::plumbing::try_execute_query::>, rustc_middle::query::erase::Erased<[u8; 2]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true> 13: ::process_obligation 14: >::process_obligations:: 15: ::select_all_or_error 16: rustc_hir_analysis::check::wfcheck::check_well_formed 17: rustc_data_structures::sync::par_for_each_in::<&[rustc_hir::hir_id::OwnerId], ::par_for_each_module::{closure#0}> 18: ::track_errors:: 19: rustc_hir_analysis::check_crate 20: rustc_interface::passes::analysis 21: >::enter::, rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#4}> 22: ::enter::, 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 x86_64-unknown-linux-gnu note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED] -C link-arg=-fuse-ld=lld note: some of the compiler flags provided by cargo are hidden query stack during panic: #0 [evaluate_obligation] evaluating trait selection obligation `sqlx_core::pool::inner::PoolInner: core::marker::Send` #1 [check_well_formed] checking that `listener::` is well-formed #2 [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 9ecebc817eb23e30-a5d060b145ccfcc0', compiler/rustc_middle/src/dep_graph/dep_node.rs:181:17 stack backtrace: 0: rust_begin_unwind at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/panicking.rs:593:5 1: core::panicking::panic_fmt at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/panicking.rs:67:14 2: as rustc_middle::dep_graph::dep_node::DepNodeExt>::extract_def_id::{closure#0} 3: as rustc_middle::dep_graph::dep_node::DepNodeExt>::extract_def_id 4: ::debug_node 5: core::fmt::rt::Argument::fmt at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/fmt/rt.rs:138:9 6: core::fmt::write at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/fmt/mod.rs:1094:21 7: std::io::Write::write_fmt at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/io/mod.rs:1713:15 8: <&std::io::stdio::Stderr as std::io::Write>::write_fmt at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/io/stdio.rs:945:9 9: ::write_fmt at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/io/stdio.rs:919:9 10: std::io::stdio::print_to at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/io/stdio.rs:1018:21 11: std::io::stdio::_eprint at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/io/stdio.rs:1106:5 12: rustc_query_system::dep_graph::graph::print_markframe_trace:: 13: >::try_mark_previous_green:: 14: >::try_mark_previous_green:: 15: >::try_mark_previous_green:: 16: >::try_mark_previous_green:: 17: >::try_mark_previous_green:: 18: >::try_mark_previous_green:: 19: >::try_mark_previous_green:: 20: rustc_query_system::query::plumbing::try_execute_query::>, rustc_middle::query::erase::Erased<[u8; 2]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true> 21: ::process_obligation 22: >::process_obligations:: 23: ::select_all_or_error 24: rustc_hir_analysis::check::wfcheck::check_well_formed 25: rustc_data_structures::sync::par_for_each_in::<&[rustc_hir::hir_id::OwnerId], ::par_for_each_module::{closure#0}> 26: ::track_errors:: 27: rustc_hir_analysis::check_crate 28: rustc_interface::passes::analysis 29: >::enter::, rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#4}> 30: ::enter::, 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 x86_64-unknown-linux-gnu note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED] -C link-arg=-fuse-ld=lld note: some of the compiler flags provided by cargo are hidden query stack during panic: #0 [evaluate_obligation] evaluating trait selection obligation `sqlx_core::pool::inner::PoolInner: core::marker::Send` #1 [check_well_formed] checking that `listener::` is well-formed #2 [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 check_mod_type_wf(sqlx_postgres[9ece]::listener) end of try_mark_green dep node stack ```

Flowneee commented 1 year ago

Cleaning target dir removed problem for me. This is also probably reason why beta and nightly had no problems - they didn't have existing target/ files. I'll dig a bit further and post here how cleaning affects this case.