rust-lang / rust

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

ice: rustdoc: expect tcx.sess.has_errors return true #104237

Open matthiaskrgr opened 1 year ago

matthiaskrgr commented 1 year ago

Code

// Regression test for #75889.

const FOO: dyn Fn() -> _ = ""; //~ ERROR E0121
static BOO: dyn Fn() -> _ = ""; //~ ERROR E0121

fn main() {}

Meta

rustc --version --verbose:

rustdoc 1.67.0-nightly (5eef9b2c5 2022-11-10)
binary: rustdoc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4

Error output

rustdoc issue-75889.rs -Zunstable-options --document-private-items

<output>
Backtrace

``` error: internal compiler error: /rustc/5eef9b2c50ddd4e445c10043908f785b08456489/compiler/rustc_middle/src/ty/visit.rs:103:17: expect tcx.sess.has_errors return true thread '' panicked at 'Box', /rustc/5eef9b2c50ddd4e445c10043908f785b08456489/compiler/rustc_errors/src/lib.rs:1551:9 stack backtrace: 0: 0x7fba466b3300 - std::backtrace_rs::backtrace::libunwind::trace::hf90d3c31e5728665 at /rustc/5eef9b2c50ddd4e445c10043908f785b08456489/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5 1: 0x7fba466b3300 - std::backtrace_rs::backtrace::trace_unsynchronized::hbab0ef678a04f1e2 at /rustc/5eef9b2c50ddd4e445c10043908f785b08456489/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7fba466b3300 - std::sys_common::backtrace::_print_fmt::h4d16d8ef766d8253 at /rustc/5eef9b2c50ddd4e445c10043908f785b08456489/library/std/src/sys_common/backtrace.rs:65:5 3: 0x7fba466b3300 - ::fmt::h1d61edf4523165f1 at /rustc/5eef9b2c50ddd4e445c10043908f785b08456489/library/std/src/sys_common/backtrace.rs:44:22 4: 0x7fba427c863e - core::fmt::write::hda6d5666579bcc93 at /rustc/5eef9b2c50ddd4e445c10043908f785b08456489/library/core/src/fmt/mod.rs:1209:17 5: 0x7fba466a73e5 - std::io::Write::write_fmt::had72db0737f63719 at /rustc/5eef9b2c50ddd4e445c10043908f785b08456489/library/std/src/io/mod.rs:1682:15 6: 0x7fba466b30c5 - std::sys_common::backtrace::_print::h0ab12a7c0910ab0b at /rustc/5eef9b2c50ddd4e445c10043908f785b08456489/library/std/src/sys_common/backtrace.rs:47:5 7: 0x7fba466b30c5 - std::sys_common::backtrace::print::h61e08ac350041552 at /rustc/5eef9b2c50ddd4e445c10043908f785b08456489/library/std/src/sys_common/backtrace.rs:34:9 8: 0x7fba466b53df - std::panicking::default_hook::{{closure}}::h5fda3e54fd0cb500 at /rustc/5eef9b2c50ddd4e445c10043908f785b08456489/library/std/src/panicking.rs:267:22 9: 0x7fba466b511a - std::panicking::default_hook::he7b2cf794e8de8e1 at /rustc/5eef9b2c50ddd4e445c10043908f785b08456489/library/std/src/panicking.rs:286:9 10: 0x7fba4595b481 - rustc_driver[8c14da3932bf1b54]::DEFAULT_HOOK::{closure#0}::{closure#0} 11: 0x7fba466b5bcd - as core::ops::function::Fn>::call::hf4b4edb294103c3e at /rustc/5eef9b2c50ddd4e445c10043908f785b08456489/library/alloc/src/boxed.rs:2032:9 12: 0x7fba466b5bcd - std::panicking::rust_panic_with_hook::hf0337eb6a5079595 at /rustc/5eef9b2c50ddd4e445c10043908f785b08456489/library/std/src/panicking.rs:692:13 13: 0x7fba45d90571 - std[b90f83ae643d2861]::panicking::begin_panic::::{closure#0} 14: 0x7fba45d8f636 - std[b90f83ae643d2861]::sys_common::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 15: 0x7fba45dee026 - std[b90f83ae643d2861]::panicking::begin_panic:: 16: 0x7fba45d8f626 - std[b90f83ae643d2861]::panic::panic_any:: 17: 0x7fba45d8ca14 - ::bug::<&alloc[d3ac23732d419968]::string::String> 18: 0x7fba45d89e20 - ::bug::<&alloc[d3ac23732d419968]::string::String> 19: 0x7fba45e5a13d - rustc_middle[84b512bc76e563e5]::ty::context::tls::with_context_opt::::{closure#0}, ()>::{closure#0}, ()> 20: 0x7fba45e5a2c6 - rustc_middle[84b512bc76e563e5]::util::bug::opt_span_bug_fmt:: 21: 0x7fba43b9f1d3 - rustc_middle[84b512bc76e563e5]::util::bug::bug_fmt 22: 0x7fba445aa5f1 - ::run_pass 23: 0x7fba447e2cf1 - rustc_mir_transform[373e00c3de166c9d]::mir_promoted 24: 0x7fba447e0b75 - rustc_query_system[f583c64c09f9213]::query::plumbing::try_execute_query::, (&rustc_data_structures[a7565d3d7b46a317]::steal::Steal, &rustc_data_structures[a7565d3d7b46a317]::steal::Steal>)>> 25: 0x7fba447df140 - rustc_borrowck[d149f101a9598a66]::mir_borrowck 26: 0x7fba44abaa5c - rustc_query_system[f583c64c09f9213]::query::plumbing::try_execute_query::> 27: 0x7fba45370246 - ::mir_borrowck 28: 0x7fba43bfad7c - rustc_mir_transform[373e00c3de166c9d]::mir_drops_elaborated_and_const_checked 29: 0x7fba44300819 - rustc_query_system[f583c64c09f9213]::query::plumbing::try_execute_query::, &rustc_data_structures[a7565d3d7b46a317]::steal::Steal>> 30: 0x7fba4536ea3e - ::mir_drops_elaborated_and_const_checked 31: 0x7fba44d72fb7 - rustc_mir_transform[373e00c3de166c9d]::inner_mir_for_ctfe 32: 0x7fba44d728c2 - rustc_mir_transform[373e00c3de166c9d]::mir_for_ctfe 33: 0x7fba4431f776 - rustc_query_system[f583c64c09f9213]::query::plumbing::try_execute_query::> 34: 0x7fba4536eb6f - ::mir_for_ctfe 35: 0x7fba4497cfeb - >::load_mir 36: 0x7fba4497a031 - rustc_const_eval[548a7d13fc1a0dc7]::const_eval::eval_queries::eval_to_allocation_raw_provider 37: 0x7fba44d8f59b - rustc_query_system[f583c64c09f9213]::query::plumbing::try_execute_query::, core[72eb066edf3a3837]::result::Result>> 38: 0x7fba453704f6 - ::eval_to_allocation_raw 39: 0x7fba44d2665a - rustc_const_eval[548a7d13fc1a0dc7]::const_eval::eval_queries::eval_to_const_value_raw_provider 40: 0x7fba445f2f8c - rustc_query_system[f583c64c09f9213]::query::plumbing::try_execute_query::, core[72eb066edf3a3837]::result::Result>> 41: 0x7fba45370689 - ::eval_to_const_value_raw 42: 0x7fba44d26a92 - rustc_const_eval[548a7d13fc1a0dc7]::const_eval::eval_queries::eval_to_const_value_raw_provider 43: 0x7fba445f2f8c - rustc_query_system[f583c64c09f9213]::query::plumbing::try_execute_query::, core[72eb066edf3a3837]::result::Result>> 44: 0x7fba45370689 - ::eval_to_const_value_raw 45: 0x7fba449508a0 - ::const_eval_global_id 46: 0x7fba4494fb44 - ::const_eval_poly 47: 0x55f08412cdfa - rustdoc[bcfe119e2278b5a]::clean::utils::print_evaluated_const 48: 0x55f084282ecd - rustdoc[bcfe119e2278b5a]::html::render::print_item::print_item 49: 0x55f0842c6dca - ::render_item 50: 0x55f0842ceeb9 - ::item 51: 0x55f0842c4d92 - rustdoc[bcfe119e2278b5a]::formats::renderer::run_format:: 52: 0x55f0840304e5 - rustdoc[bcfe119e2278b5a]::run_renderer:: 53: 0x55f0841e2557 - ::enter::> 54: 0x55f083fd3394 - ::enter::> 55: 0x55f08415a4d3 - std[b90f83ae643d2861]::sys_common::backtrace::__rust_begin_short_backtrace::, rustdoc[bcfe119e2278b5a]::main_args::{closure#1}>::{closure#0}, core[72eb066edf3a3837]::result::Result<(), rustc_errors[f44e14d7b3f4d813]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[72eb066edf3a3837]::result::Result<(), rustc_errors[f44e14d7b3f4d813]::ErrorGuaranteed>> 56: 0x55f0842b8d5a - <::spawn_unchecked_, rustdoc[bcfe119e2278b5a]::main_args::{closure#1}>::{closure#0}, core[72eb066edf3a3837]::result::Result<(), rustc_errors[f44e14d7b3f4d813]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[72eb066edf3a3837]::result::Result<(), rustc_errors[f44e14d7b3f4d813]::ErrorGuaranteed>>::{closure#1} as core[72eb066edf3a3837]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 57: 0x7fba42773363 - as core::ops::function::FnOnce>::call_once::hcdbd49f670947111 at /rustc/5eef9b2c50ddd4e445c10043908f785b08456489/library/alloc/src/boxed.rs:2000:9 58: 0x7fba42773363 - as core::ops::function::FnOnce>::call_once::hf6aaa6fa23bce9ec at /rustc/5eef9b2c50ddd4e445c10043908f785b08456489/library/alloc/src/boxed.rs:2000:9 59: 0x7fba42773363 - std::sys::unix::thread::Thread::new::thread_start::h7c893f5c1c829598 at /rustc/5eef9b2c50ddd4e445c10043908f785b08456489/library/std/src/sys/unix/thread.rs:108:17 60: 0x7fba4250a8fd - 61: 0x7fba4258ca60 - 62: 0x0 - 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.67.0-nightly (5eef9b2c5 2022-11-10) running on x86_64-unknown-linux-gnu note: compiler flags: -Z unstable-options query stack during panic: #0 [mir_promoted] processing MIR for `FOO` #1 [mir_borrowck] borrow-checking `FOO` #2 [mir_drops_elaborated_and_const_checked] elaborating drops for `FOO` #3 [mir_for_ctfe] caching mir of `FOO` for CTFE #4 [eval_to_allocation_raw] const-evaluating + checking `FOO` #5 [eval_to_const_value_raw] simplifying constant for the type system `FOO` #6 [eval_to_const_value_raw] simplifying constant for the type system `FOO` end of query stack error: aborting due to previous error ```

compiler-errors commented 1 year ago

This regressed in 465ac26405d32cc1dd73460fa465c9303f40ea43 / #103928, cc @chenyukang

Rustdoc is special because it's more forgiving with errors than rustc. I'm curious to understand where we're suppressing an error in rustdoc due to _ infer types being present outside of an typeck body, and whether it should just be reporting an error...

matthiaskrgr commented 1 year ago

Bug still exists but the errors changed:

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: bad placeholder type
 --> rd.rs:2:24
  |
2 | const FOO: dyn Fn() -> _ = ""; //~ ERROR E0121
  |                        ^
  |
  = note: delayed at compiler/rustc_hir_analysis/src/collect.rs:403:20

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_hir_typeck/src/coercion.rs:176:49

error: internal compiler error: bad placeholder type
 --> rd.rs:3:25
  |
3 | static BOO: dyn Fn() -> _ = ""; //~ ERROR E0121
  |                         ^
  |
  = note: delayed at compiler/rustc_hir_analysis/src/collect.rs:403:20

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_mir_build/src/build/mod.rs:637:18

error: internal compiler error: mir_const_qualif: MIR had errors
 --> rd.rs:2:1
  |
2 | const FOO: dyn Fn() -> _ = ""; //~ ERROR E0121
  | ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: delayed at compiler/rustc_mir_transform/src/lib.rs:254:18

error: internal compiler error: broken MIR in DefId(0:3 ~ rd[d0c3]::FOO) ("return type"): bad type [type error]
 --> rd.rs:2:1
  |
2 | const FOO: dyn Fn() -> _ = ""; //~ ERROR E0121
  | ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:520:13

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:768:20

error: internal compiler error: broken MIR in DefId(0:3 ~ rd[d0c3]::FOO) (LocalDecl { mutability: Mut, local_info: None, internal: false, is_block_tail: None, ty: [type error], user_ty: None, source_info: SourceInfo { span: rd.rs:2:1: 2:25 (#0), scope: scope[0] } }): bad type [type error]
 --> rd.rs:2:1
  |
2 | const FOO: dyn Fn() -> _ = ""; //~ ERROR E0121
  | ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:520:13

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at /rustc/5fa44b54641cac7dc47964870d08b4ec82fc8157/compiler/rustc_middle/src/ty/relate.rs:425:59

thread '<unnamed>' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1609:13
stack backtrace:
   0:     0x7fc2eb62658a - std::backtrace_rs::backtrace::libunwind::trace::hc8e994fd046b5ea0
                               at /rustc/5fa44b54641cac7dc47964870d08b4ec82fc8157/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7fc2eb62658a - std::backtrace_rs::backtrace::trace_unsynchronized::h89d598f4e35d7c6d
                               at /rustc/5fa44b54641cac7dc47964870d08b4ec82fc8157/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fc2eb62658a - std::sys_common::backtrace::_print_fmt::heb8b816127c575ac
                               at /rustc/5fa44b54641cac7dc47964870d08b4ec82fc8157/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7fc2eb62658a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hc6d5a81fe9ae4944
                               at /rustc/5fa44b54641cac7dc47964870d08b4ec82fc8157/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fc2e75c8bae - core::fmt::write::hcafa8b859a98872c
                               at /rustc/5fa44b54641cac7dc47964870d08b4ec82fc8157/library/core/src/fmt/mod.rs:1208:17
   5:     0x7fc2eb61a855 - std::io::Write::write_fmt::h6673a9b6e958ba8f
                               at /rustc/5fa44b54641cac7dc47964870d08b4ec82fc8157/library/std/src/io/mod.rs:1682:15
   6:     0x7fc2eb626355 - std::sys_common::backtrace::_print::h354a664bdeea14b1
                               at /rustc/5fa44b54641cac7dc47964870d08b4ec82fc8157/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7fc2eb626355 - std::sys_common::backtrace::print::h4d0bbca313a44919
                               at /rustc/5fa44b54641cac7dc47964870d08b4ec82fc8157/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7fc2eb6286bf - std::panicking::default_hook::{{closure}}::h7a27de504bd62dbf
                               at /rustc/5fa44b54641cac7dc47964870d08b4ec82fc8157/library/std/src/panicking.rs:267:22
   9:     0x7fc2eb6283fb - std::panicking::default_hook::hbb70baf900f6c2f3
                               at /rustc/5fa44b54641cac7dc47964870d08b4ec82fc8157/library/std/src/panicking.rs:286:9
  10:     0x7fc2ea8692a4 - rustc_driver[3baf39caff1a6c1c]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7fc2eb628ebd - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hfcf54b530484d26c
                               at /rustc/5fa44b54641cac7dc47964870d08b4ec82fc8157/library/alloc/src/boxed.rs:2032:9
  12:     0x7fc2eb628ebd - std::panicking::rust_panic_with_hook::h77d2e8b96839df52
                               at /rustc/5fa44b54641cac7dc47964870d08b4ec82fc8157/library/std/src/panicking.rs:692:13
  13:     0x7fc2ea8a1d51 - std[e181dace32bc9e68]::panicking::begin_panic::<rustc_errors[a8c29d7197cd76e7]::ExplicitBug>::{closure#0}
  14:     0x7fc2ea8a0686 - std[e181dace32bc9e68]::sys_common::backtrace::__rust_end_short_backtrace::<std[e181dace32bc9e68]::panicking::begin_panic<rustc_errors[a8c29d7197cd76e7]::ExplicitBug>::{closure#0}, !>
  15:     0x7fc2ea899276 - std[e181dace32bc9e68]::panicking::begin_panic::<rustc_errors[a8c29d7197cd76e7]::ExplicitBug>
  16:     0x7fc2ea89cae6 - std[e181dace32bc9e68]::panic::panic_any::<rustc_errors[a8c29d7197cd76e7]::ExplicitBug>
  17:     0x7fc2e9d7c426 - <rustc_errors[a8c29d7197cd76e7]::HandlerInner>::flush_delayed::<alloc[6669983853ed71da]::vec::Vec<rustc_errors[a8c29d7197cd76e7]::diagnostic::Diagnostic>, &str>
  18:     0x7fc2e9d7b72b - <rustc_errors[a8c29d7197cd76e7]::HandlerInner as core[272b256b08fe9f3e]::ops::drop::Drop>::drop
  19:     0x55f191ddd4fe - core[272b256b08fe9f3e]::ptr::drop_in_place::<rustc_session[e9234f890d84fb2b]::parse::ParseSess>
  20:     0x55f191dded9f - core[272b256b08fe9f3e]::ptr::drop_in_place::<rustc_session[e9234f890d84fb2b]::session::Session>
  21:     0x55f191a9c06d - core[272b256b08fe9f3e]::ptr::drop_in_place::<rustc_interface[d49f2a515602384d]::interface::Compiler>
  22:     0x55f191a897ea - <scoped_tls[761487f81bd1504c]::ScopedKey<rustc_span[86a07044cd7a2b96]::SessionGlobals>>::set::<rustc_interface[d49f2a515602384d]::interface::run_compiler<core[272b256b08fe9f3e]::result::Result<(), rustc_errors[a8c29d7197cd76e7]::ErrorGuaranteed>, rustdoc[362a79a2860e7de9]::main_args::{closure#1}>::{closure#0}, core[272b256b08fe9f3e]::result::Result<(), rustc_errors[a8c29d7197cd76e7]::ErrorGuaranteed>>
  23:     0x55f191c70ee0 - std[e181dace32bc9e68]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[d49f2a515602384d]::util::run_in_thread_pool_with_globals<rustc_interface[d49f2a515602384d]::interface::run_compiler<core[272b256b08fe9f3e]::result::Result<(), rustc_errors[a8c29d7197cd76e7]::ErrorGuaranteed>, rustdoc[362a79a2860e7de9]::main_args::{closure#1}>::{closure#0}, core[272b256b08fe9f3e]::result::Result<(), rustc_errors[a8c29d7197cd76e7]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[272b256b08fe9f3e]::result::Result<(), rustc_errors[a8c29d7197cd76e7]::ErrorGuaranteed>>
  24:     0x55f191da485d - <<std[e181dace32bc9e68]::thread::Builder>::spawn_unchecked_<rustc_interface[d49f2a515602384d]::util::run_in_thread_pool_with_globals<rustc_interface[d49f2a515602384d]::interface::run_compiler<core[272b256b08fe9f3e]::result::Result<(), rustc_errors[a8c29d7197cd76e7]::ErrorGuaranteed>, rustdoc[362a79a2860e7de9]::main_args::{closure#1}>::{closure#0}, core[272b256b08fe9f3e]::result::Result<(), rustc_errors[a8c29d7197cd76e7]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[272b256b08fe9f3e]::result::Result<(), rustc_errors[a8c29d7197cd76e7]::ErrorGuaranteed>>::{closure#1} as core[272b256b08fe9f3e]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  25:     0x7fc2e75731f3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h6e99d9d46328d005
                               at /rustc/5fa44b54641cac7dc47964870d08b4ec82fc8157/library/alloc/src/boxed.rs:2000:9
  26:     0x7fc2e75731f3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc5c184713c4141ec
                               at /rustc/5fa44b54641cac7dc47964870d08b4ec82fc8157/library/alloc/src/boxed.rs:2000:9
  27:     0x7fc2e75731f3 - std::sys::unix::thread::Thread::new::thread_start::h18a504b023c5c43d
                               at /rustc/5fa44b54641cac7dc47964870d08b4ec82fc8157/library/std/src/sys/unix/thread.rs:108:17
  28:     0x7fc2e72e78fd - <unknown>
  29:     0x7fc2e7369a60 - <unknown>
  30:                0x0 - <unknown>

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.67.0-nightly (5fa44b546 2022-11-26) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z unstable-options

query stack during panic:
end of query stack
fmease commented 2 months ago

Triage: No longer ICEs (ice→errors). Might need a regression test, no sure.