rust-lang / rust

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

ICE: `unwrap` on `None` in `find_cycle_in_stack` #105321

Closed jruderman closed 1 year ago

jruderman commented 1 year ago

Found with a modified fuzz-rustc

Code

fn hof<F>(_: F)
where
    F: FnMut() -> (),
{
}

fn f() -> _ {
    hof(f);
}

fn main() {}

Error output

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', [compiler/rustc_query_system/src/query/job.rs:137](https://github.com/rust-lang/rust/blob/53e4b9dd74c29cc9308b8d0f10facac70bb101a7/compiler/rustc_query_system/src/query/job.rs#L137)

error: internal compiler error: unexpected panic

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

error: internal compiler error[[E0391](https://doc.rust-lang.org/error_codes/E0391.html)]: cycle detected when computing function signature of `f`

error: internal compiler error: `TyKind::Error` constructed but no error reported
  |
  = note: delayed at [compiler/rustc_middle/src/values.rs:36](https://github.com/rust-lang/rust/blob/53e4b9dd74c29cc9308b8d0f10facac70bb101a7/compiler/rustc_middle/src/values.rs#L36)
Full output including two backtraces ``` thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler/rustc_query_system/src/query/job.rs:137:24 stack backtrace: 0: 0x110214b76 - ::fmt::h4fbf7f9506d0d7e9 1: 0x1102735ba - core::fmt::write::h99e5c56cbde66a79 2: 0x110206f4c - std::io::Write::write_fmt::h898a203805a2f0c7 3: 0x11021495a - std::sys_common::backtrace::print::h9e2881390d902908 4: 0x110217cc3 - std::panicking::default_hook::{{closure}}::h46869a929ac7ef1e 5: 0x110217a18 - std::panicking::default_hook::h9fcd367a8b22b0ea 6: 0x11cb2796d - rustc_driver[c92f8c32e51f19c4]::DEFAULT_HOOK::{closure#0}::{closure#0} 7: 0x1102184a7 - std::panicking::rust_panic_with_hook::h8cbaa9a506f5110c 8: 0x110218213 - std::panicking::begin_panic_handler::{{closure}}::h84be22477d41ec61 9: 0x110215018 - std::sys_common::backtrace::__rust_end_short_backtrace::h9f0abd4aedd5a88e 10: 0x110217f1d - _rust_begin_unwind 11: 0x11029fa43 - core::panicking::panic_fmt::hd6b0bfc3dbc6745d 12: 0x11029fb17 - core::panicking::panic::h88ce25cb0ff92a1c 13: 0x121a221e3 - ::find_cycle_in_stack 14: 0x120377343 - rustc_query_system[e953eb575b1af2ed]::query::plumbing::try_execute_query::>> 15: 0x1204a3b22 - rustc_query_system[e953eb575b1af2ed]::query::plumbing::get_query:: 16: 0x120554ef5 - ::fn_sig 17: 0x12141e164 - ::bound_fn_sig 18: 0x1214798ce - ::pretty_print_type 19: 0x121349a77 - >::print 20: 0x121349d34 - >::print 21: 0x12148ab17 - ::in_binder:: 22: 0x12134ab74 - ::fmt 23: 0x1102735ba - core::fmt::write::h99e5c56cbde66a79 24: 0x110265959 - alloc::fmt::format::format_inner::h02036a78709044df 25: 0x121318270 - rustc_middle[ebe25b18dd1c0827]::query::descs::evaluate_obligation 26: 0x1206a5036 - rustc_query_impl[5215ea03a65f0d15]::plumbing::create_query_frame::>> 27: 0x1206eb8aa - >)>>::call_once 28: 0x1203772a9 - rustc_query_system[e953eb575b1af2ed]::query::plumbing::try_execute_query::>> 29: 0x1204a3b22 - rustc_query_system[e953eb575b1af2ed]::query::plumbing::get_query:: 30: 0x120554ef5 - ::fn_sig 31: 0x12141e164 - ::bound_fn_sig 32: 0x121345f82 - ::fn_sig 33: 0x12113f684 - ::assemble_fn_pointer_candidates 34: 0x121147162 - ::assemble_candidates 35: 0x1211417b2 - ::candidate_from_obligation_no_cache 36: 0x12116438d - >::with_anon_task::::in_task<::candidate_from_obligation::{closure#0}::{closure#0}, core[888d5284bcc5795e]::result::Result, rustc_middle[ebe25b18dd1c0827]::traits::SelectionError>>::{closure#0}, core[888d5284bcc5795e]::result::Result, rustc_middle[ebe25b18dd1c0827]::traits::SelectionError>> 37: 0x121151483 - ::candidate_from_obligation 38: 0x12114389c - ::evaluate_stack 39: 0x121164729 - >::with_anon_task::::in_task<::evaluate_trait_predicate_recursively::{closure#0}::{closure#2}, core[888d5284bcc5795e]::result::Result>::{closure#0}, core[888d5284bcc5795e]::result::Result> 40: 0x121153b40 - ::evaluate_trait_predicate_recursively 41: 0x1211523ec - ::evaluate_predicate_recursively 42: 0x1210d7e87 - ::probe::, ::evaluation_probe<::evaluate_root_obligation::{closure#0}>::{closure#0}> 43: 0x1211436a0 - ::evaluate_root_obligation 44: 0x1200b9a10 - rustc_traits[732533c0770d89a6]::evaluate_obligation::evaluate_obligation 45: 0x12034b129 - rustc_query_system[e953eb575b1af2ed]::query::plumbing::try_execute_query::>, core[888d5284bcc5795e]::result::Result>> 46: 0x1204977d2 - rustc_query_system[e953eb575b1af2ed]::query::plumbing::get_query:: 47: 0x120556cc9 - ::evaluate_obligation 48: 0x1210f862f - ::evaluate_obligation 49: 0x1210f872f - ::evaluate_obligation_no_overflow 50: 0x121193a9d - ::process_trait_obligation 51: 0x121192b96 - ::process_obligation 52: 0x1210982f0 - >::process_obligations:: 53: 0x12118f458 - ::select_where_possible 54: 0x11f32a423 - ::check_argument_types 55: 0x11f308d73 - ::confirm_builtin_call 56: 0x11f305da7 - ::check_call 57: 0x11f375f0e - ::check_expr_kind 58: 0x11f319cdf - ::check_expr_with_expectation_and_args 59: 0x11f3323a5 - ::check_stmt 60: 0x11f332b2f - ::check_block_with_expected 61: 0x11f3762de - ::check_expr_kind 62: 0x11f319cdf - ::check_expr_with_expectation_and_args 63: 0x11f31b420 - ::check_return_expr 64: 0x11f454ba0 - rustc_hir_typeck[54d69da23aab2155]::check::check_fn 65: 0x11f415ef9 - rustc_hir_typeck[54d69da23aab2155]::typeck 66: 0x12041db82 - rustc_query_system[e953eb575b1af2ed]::query::plumbing::try_execute_query::> 67: 0x1204a3e14 - rustc_query_system[e953eb575b1af2ed]::query::plumbing::get_query:: 68: 0x11f5d8950 - rustc_hir_analysis[a5ba6f320bd8c4ca]::collect::infer_return_ty_for_fn_sig 69: 0x11f5e359d - rustc_hir_analysis[a5ba6f320bd8c4ca]::collect::fn_sig 70: 0x12037770d - rustc_query_system[e953eb575b1af2ed]::query::plumbing::try_execute_query::>> 71: 0x1204a3b22 - rustc_query_system[e953eb575b1af2ed]::query::plumbing::get_query:: 72: 0x120554ef5 - ::fn_sig 73: 0x11f5d6080 - rustc_hir_analysis[a5ba6f320bd8c4ca]::collect::convert_item 74: 0x11f5cd93c - ::visit_item 75: 0x11f5039f9 - ::visit_item_likes_in_module:: 76: 0x11f5ccf55 - rustc_hir_analysis[a5ba6f320bd8c4ca]::collect::collect_mod_item_types 77: 0x120423282 - rustc_query_system[e953eb575b1af2ed]::query::plumbing::try_execute_query::> 78: 0x12049c0f1 - rustc_query_system[e953eb575b1af2ed]::query::plumbing::get_query:: 79: 0x11f5032ca - ::for_each_module:: 80: 0x11f598051 - ::track_errors:: 81: 0x11f6a2168 - rustc_hir_analysis[a5ba6f320bd8c4ca]::check_crate 82: 0x11cbd04ca - rustc_interface[857b37ce07fbf291]::passes::analysis 83: 0x1203d9af4 - rustc_query_system[e953eb575b1af2ed]::query::plumbing::try_execute_query::>> 84: 0x1204a41f1 - rustc_query_system[e953eb575b1af2ed]::query::plumbing::get_query:: 85: 0x11cab92f7 - ::enter::> 86: 0x11caffe25 - ::enter::, rustc_errors[e5253effe2ad2635]::ErrorGuaranteed>> 87: 0x11ca9a42d - rustc_span[fb6f3bfe63cfc4d8]::with_source_map::, rustc_interface[857b37ce07fbf291]::interface::run_compiler, rustc_driver[c92f8c32e51f19c4]::run_compiler::{closure#1}>::{closure#0}::{closure#0}> 88: 0x11caf2d5d - >::set::, rustc_driver[c92f8c32e51f19c4]::run_compiler::{closure#1}>::{closure#0}, core[888d5284bcc5795e]::result::Result<(), rustc_errors[e5253effe2ad2635]::ErrorGuaranteed>> 89: 0x11cac224a - std[af48a373fa65f370]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver[c92f8c32e51f19c4]::run_compiler::{closure#1}>::{closure#0}, core[888d5284bcc5795e]::result::Result<(), rustc_errors[e5253effe2ad2635]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[888d5284bcc5795e]::result::Result<(), rustc_errors[e5253effe2ad2635]::ErrorGuaranteed>> 90: 0x11caa4165 - <::spawn_unchecked_, rustc_driver[c92f8c32e51f19c4]::run_compiler::{closure#1}>::{closure#0}, core[888d5284bcc5795e]::result::Result<(), rustc_errors[e5253effe2ad2635]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[888d5284bcc5795e]::result::Result<(), rustc_errors[e5253effe2ad2635]::ErrorGuaranteed>>::{closure#1} as core[888d5284bcc5795e]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 91: 0x110221797 - std::sys::unix::thread::Thread::new::thread_start::h90404ce6cd9b7cbc 92: 0x7ff8083354e1 - __pthread_start 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.67.0-nightly (53e4b9dd7 2022-12-04) running on x86_64-apple-darwin query stack during panic: end of query stack error: internal compiler error: no errors encountered even though `delay_span_bug` issued error: internal compiler error[E0391]: cycle detected when computing function signature of `f` --> oing.rs:7:1 | 7 | fn f() -> _ { | ^^^^^^^^^^^ | note: ...which requires type-checking `f`... --> oing.rs:7:1 | 7 | fn f() -> _ { | ^^^^^^^^^^^ = note: ...which again requires computing function signature of `f`, completing the cycle note: cycle used when collecting item types in top-level module --> oing.rs:1:1 | 1 | / fn hof(_: F) 2 | | where 3 | | F: FnMut() -> (), 4 | | { ... | 10 | | 11 | | fn main() {} | |____________^ error: internal compiler error: TyKind::Error constructed but no error reported | = note: delayed at compiler/rustc_middle/src/values.rs:36:23 thread 'rustc' panicked at 'Box', compiler/rustc_errors/src/lib.rs:1610:13 stack backtrace: 0: 0x110214b76 - ::fmt::h4fbf7f9506d0d7e9 1: 0x1102735ba - core::fmt::write::h99e5c56cbde66a79 2: 0x110206f4c - std::io::Write::write_fmt::h898a203805a2f0c7 3: 0x11021495a - std::sys_common::backtrace::print::h9e2881390d902908 4: 0x110217cc3 - std::panicking::default_hook::{{closure}}::h46869a929ac7ef1e 5: 0x110217a18 - std::panicking::default_hook::h9fcd367a8b22b0ea 6: 0x11cb2796d - rustc_driver[c92f8c32e51f19c4]::DEFAULT_HOOK::{closure#0}::{closure#0} 7: 0x1102184a7 - std::panicking::rust_panic_with_hook::h8cbaa9a506f5110c 8: 0x121609147 - std[af48a373fa65f370]::panicking::begin_panic::::{closure#0} 9: 0x1216074c9 - std[af48a373fa65f370]::sys_common::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 10: 0x121a2dae9 - std[af48a373fa65f370]::panicking::begin_panic:: 11: 0x1215f8a59 - std[af48a373fa65f370]::panic::panic_any:: 12: 0x1215ffe02 - ::flush_delayed::, &str> 13: 0x1215fb7a1 - ::drop 14: 0x11caaea53 - core[888d5284bcc5795e]::ptr::drop_in_place:: 15: 0x11cab01b2 - core[888d5284bcc5795e]::ptr::drop_in_place:: 16: 0x11ca9dcb2 - core[888d5284bcc5795e]::ptr::drop_in_place:: 17: 0x11ca9a98c - rustc_span[fb6f3bfe63cfc4d8]::with_source_map::, rustc_interface[857b37ce07fbf291]::interface::run_compiler, rustc_driver[c92f8c32e51f19c4]::run_compiler::{closure#1}>::{closure#0}::{closure#0}> 18: 0x11caf2d5d - >::set::, rustc_driver[c92f8c32e51f19c4]::run_compiler::{closure#1}>::{closure#0}, core[888d5284bcc5795e]::result::Result<(), rustc_errors[e5253effe2ad2635]::ErrorGuaranteed>> 19: 0x11cac224a - std[af48a373fa65f370]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver[c92f8c32e51f19c4]::run_compiler::{closure#1}>::{closure#0}, core[888d5284bcc5795e]::result::Result<(), rustc_errors[e5253effe2ad2635]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[888d5284bcc5795e]::result::Result<(), rustc_errors[e5253effe2ad2635]::ErrorGuaranteed>> 20: 0x11caa4165 - <::spawn_unchecked_, rustc_driver[c92f8c32e51f19c4]::run_compiler::{closure#1}>::{closure#0}, core[888d5284bcc5795e]::result::Result<(), rustc_errors[e5253effe2ad2635]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[888d5284bcc5795e]::result::Result<(), rustc_errors[e5253effe2ad2635]::ErrorGuaranteed>>::{closure#1} as core[888d5284bcc5795e]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 21: 0x110221797 - std::sys::unix::thread::Thread::new::thread_start::h90404ce6cd9b7cbc 22: 0x7ff8083354e1 - __pthread_start 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 (53e4b9dd7 2022-12-04) running on x86_64-apple-darwin query stack during panic: end of query stack thread panicked while panicking. aborting. Abort trap: 6 ```

Regression

Regression in nightly-2022-08-18, somewhere in rollup 9c20b2a8cc7588decb6de25ac6a7912dcef24d65. I suspect #100389 (@compiler-errors)

Version

rustc 1.67.0-nightly (53e4b9dd7 2022-12-04)
binary: rustc
commit-hash: 53e4b9dd74c29cc9308b8d0f10facac70bb101a7
commit-date: 2022-12-04
host: x86_64-apple-darwin
release: 1.67.0-nightly
LLVM version: 15.0.4
TaKO8Ki commented 1 year ago

Regression in #100389

Alexendoo commented 1 year ago

Fixed by #107585