Skip to content

Fix regression introduced with #99383 #99714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions compiler/rustc_traits/src/evaluate_obligation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustc_infer::infer::TyCtxtInferExt;
use rustc_infer::infer::{DefiningAnchor, TyCtxtInferExt};
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::{ParamEnvAnd, TyCtxt};
use rustc_span::source_map::DUMMY_SP;
Expand All @@ -16,7 +16,9 @@ fn evaluate_obligation<'tcx>(
canonical_goal: CanonicalPredicateGoal<'tcx>,
) -> Result<EvaluationResult, OverflowError> {
debug!("evaluate_obligation(canonical_goal={:#?})", canonical_goal);
tcx.infer_ctxt().enter_with_canonical(
// HACK This bubble is required for this tests to pass:
// impl-trait/issue99642.rs
tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bubble).enter_with_canonical(
DUMMY_SP,
&canonical_goal,
|ref infcx, goal, _canonical_inference_vars| {
Expand Down
15 changes: 10 additions & 5 deletions compiler/rustc_traits/src/type_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_infer::infer::at::ToTrace;
use rustc_infer::infer::canonical::{Canonical, QueryResponse};
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
use rustc_infer::infer::{DefiningAnchor, InferCtxt, TyCtxtInferExt};
use rustc_infer::traits::TraitEngineExt as _;
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::subst::{GenericArg, Subst, UserSelfTy, UserSubsts};
Expand Down Expand Up @@ -258,10 +258,15 @@ fn type_op_prove_predicate<'tcx>(
tcx: TyCtxt<'tcx>,
canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, ProvePredicate<'tcx>>>,
) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, ()>>, NoSolution> {
tcx.infer_ctxt().enter_canonical_trait_query(&canonicalized, |infcx, fulfill_cx, key| {
type_op_prove_predicate_with_cause(infcx, fulfill_cx, key, ObligationCause::dummy());
Ok(())
})
// HACK This bubble is required for this test to pass:
// impl-trait/issue-99642.rs
tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bubble).enter_canonical_trait_query(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one seems odd. The only change from adding this that I can envision is moving from an error to an ICE (via delay_span_bug due to take_opaque_types not getting called.)

Copy link
Contributor Author

@ouz-a ouz-a Jul 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remove that we get this:

Backtrace
thread 'rustc' panicked at 'assertion failed: sentinel == STR_SENTINEL',
stack backtrace:
   0:        0x10163a3c0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h726e647852e3d24f
   1:        0x1016b044c - core::fmt::write::hf6491a9cad4237ce
   2:        0x10164608c - std::io::Write::write_fmt::h2b59a831d3620ba3
   3:        0x10163a26c - std::sys_common::backtrace::print::h77f56e81b084f8f6
   4:        0x1016615ac - std::panicking::default_hook::{{closure}}::h389eb9e26b1a1de6
   5:        0x1016613a0 - std::panicking::default_hook::h6ee0c479a40c963f
   6:        0x109a6d39c - rustc_driver[7797c2389d089e8d]::DEFAULT_HOOK::{closure#0}::{closure#0}
   7:        0x101661a48 - std::panicking::rust_panic_with_hook::hbaf9f93c32f27862
   8:        0x101665540 - std::panicking::begin_panic_handler::{{closure}}::h147e22b5166ea195
   9:        0x1016654b8 - std::sys_common::backtrace::__rust_end_short_backtrace::h59d7af32b4887345
  10:        0x10166160c - _rust_begin_unwind
  11:        0x1016cc4d4 - core::panicking::panic_fmt::hbf3a6aa2f4e5afde
  12:        0x1016cc3f4 - core::panicking::panic::h99899b97fa606673
  13:        0x10cecf7d8 - <rustc_span[931268512525c026]::symbol::Symbol as rustc_serialize[63e114cd219d5a04]::serialize::Decodable<rustc_metadata[8d02725da31e47b2]::rmeta::decoder::DecodeContext>>::decode
  14:        0x10cecef84 - <rustc_attr[2c11b0af6e4e6575]::builtin::Stability as rustc_serialize[63e114cd219d5a04]::serialize::Decodable<rustc_metadata[8d02725da31e47b2]::rmeta::decoder::DecodeContext>>::decode
  15:        0x10ce85684 - <rustc_metadata[8d02725da31e47b2]::rmeta::LazyValue<rustc_attr[2c11b0af6e4e6575]::builtin::Stability>>::decode::<(rustc_metadata[8d02725da31e47b2]::creader::CrateMetadataRef, rustc_middle[690a795738a1840c]::ty::context::TyCtxt)>
  16:        0x10ce9ab78 - rustc_metadata[8d02725da31e47b2]::rmeta::decoder::cstore_impl::provide_extern::lookup_stability
  17:        0x10c9ba0b4 - rustc_query_system[7d8e326128972c4d]::query::plumbing::try_execute_query::<rustc_query_impl[5cb324285e2f04b9]::plumbing::QueryCtxt, rustc_query_system[7d8e326128972c4d]::query::caches::DefaultCache<rustc_span[931268512525c026]::def_id::DefId, core[32111c0fccea723b]::option::Option<rustc_attr[2c11b0af6e4e6575]::builtin::Stability>>>
  18:        0x10ca448f4 - rustc_query_system[7d8e326128972c4d]::query::plumbing::get_query::<rustc_query_impl[5cb324285e2f04b9]::queries::lookup_stability, rustc_query_impl[5cb324285e2f04b9]::plumbing::QueryCtxt>
  19:        0x10c88a930 - <rustc_query_impl[5cb324285e2f04b9]::Queries as rustc_middle[690a795738a1840c]::ty::query::QueryEngine>::lookup_stability
  20:        0x10d562164 - <rustc_middle[690a795738a1840c]::ty::context::TyCtxt>::eval_stability_allow_unstable
  21:        0x10d5082fc - <rustc_middle[690a795738a1840c]::ty::context::TyCtxt>::check_optional_stability::<<rustc_middle[690a795738a1840c]::ty::context::TyCtxt>::check_stability_allow_unstable::{closure#0}>
  22:        0x10d56270c - <rustc_middle[690a795738a1840c]::ty::context::TyCtxt>::check_stability
  23:        0x10c2f6e9c - <rustc_passes[24b8be219ca9cd7a]::stability::Checker as rustc_hir[f54d7568531f9ef0]::intravisit::Visitor>::visit_item
  24:        0x10c308b28 - <rustc_middle[690a795738a1840c]::hir::map::Map>::visit_item_likes_in_module::<rustc_passes[24b8be219ca9cd7a]::stability::Checker>
  25:        0x10c2f6ae4 - rustc_passes[24b8be219ca9cd7a]::stability::check_mod_unstable_api_usage
  26:        0x10c9b7b60 - rustc_query_system[7d8e326128972c4d]::query::plumbing::try_execute_query::<rustc_query_impl[5cb324285e2f04b9]::plumbing::QueryCtxt, rustc_query_system[7d8e326128972c4d]::query::caches::DefaultCache<rustc_span[931268512525c026]::def_id::LocalDefId, ()>>
  27:        0x10ca690bc - rustc_query_system[7d8e326128972c4d]::query::plumbing::get_query::<rustc_query_impl[5cb324285e2f04b9]::queries::check_mod_unstable_api_usage, rustc_query_impl[5cb324285e2f04b9]::plumbing::QueryCtxt>
  28:        0x10c8827d4 - <rustc_query_impl[5cb324285e2f04b9]::Queries as rustc_middle[690a795738a1840c]::ty::query::QueryEngine>::check_mod_unstable_api_usage
  29:        0x109b68410 - <rustc_middle[690a795738a1840c]::hir::map::Map>::for_each_module::<rustc_interface[c52c57c685108550]::passes::analysis::{closure#0}::{closure#1}::{closure#0}>
  30:        0x109b619f4 - std[5bc8614f64c760b6]::panicking::try::<(), core[32111c0fccea723b]::panic::unwind_safe::AssertUnwindSafe<rustc_interface[c52c57c685108550]::passes::analysis::{closure#0}::{closure#1}>>
  31:        0x109b60254 - <rustc_session[c448c0a5dec433c3]::session::Session>::time::<(), rustc_interface[c52c57c685108550]::passes::analysis::{closure#0}>
  32:        0x109b6efc4 - rustc_interface[c52c57c685108550]::passes::analysis
  33:        0x10c9dc124 - rustc_query_system[7d8e326128972c4d]::query::plumbing::try_execute_query::<rustc_query_impl[5cb324285e2f04b9]::plumbing::QueryCtxt, rustc_query_system[7d8e326128972c4d]::query::caches::DefaultCache<(), core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>>>
  34:        0x10ca73fa0 - rustc_query_system[7d8e326128972c4d]::query::plumbing::get_query::<rustc_query_impl[5cb324285e2f04b9]::queries::analysis, rustc_query_impl[5cb324285e2f04b9]::plumbing::QueryCtxt>
  35:        0x10c87677c - <rustc_query_impl[5cb324285e2f04b9]::Queries as rustc_middle[690a795738a1840c]::ty::query::QueryEngine>::analysis
  36:        0x109ac5460 - <rustc_interface[c52c57c685108550]::passes::QueryContext>::enter::<rustc_driver[7797c2389d089e8d]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>>
  37:        0x109a539a0 - <rustc_interface[c52c57c685108550]::interface::Compiler>::enter::<rustc_driver[7797c2389d089e8d]::run_compiler::{closure#1}::{closure#2}, core[32111c0fccea723b]::result::Result<core[32111c0fccea723b]::option::Option<rustc_interface[c52c57c685108550]::queries::Linker>, rustc_errors[c9670795598baa39]::ErrorGuaranteed>>
  38:        0x109a6ebac - rustc_span[931268512525c026]::with_source_map::<core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>, rustc_interface[c52c57c685108550]::interface::create_compiler_and_run<core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>, rustc_driver[7797c2389d089e8d]::run_compiler::{closure#1}>::{closure#1}>
  39:        0x109a542d8 - rustc_interface[c52c57c685108550]::interface::create_compiler_and_run::<core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>, rustc_driver[7797c2389d089e8d]::run_compiler::{closure#1}>
  40:        0x109a7774c - <scoped_tls[a90f9c0771ff865f]::ScopedKey<rustc_span[931268512525c026]::SessionGlobals>>::set::<rustc_interface[c52c57c685108550]::interface::run_compiler<core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>, rustc_driver[7797c2389d089e8d]::run_compiler::{closure#1}>::{closure#0}, core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>>
  41:        0x109a5fec4 - std[5bc8614f64c760b6]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[c52c57c685108550]::util::run_in_thread_pool_with_globals<rustc_interface[c52c57c685108550]::interface::run_compiler<core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>, rustc_driver[7797c2389d089e8d]::run_compiler::{closure#1}>::{closure#0}, core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>>::{closure#0}, core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>>
  42:        0x109a60cec - std[5bc8614f64c760b6]::panicking::try::<core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>, core[32111c0fccea723b]::panic::unwind_safe::AssertUnwindSafe<<std[5bc8614f64c760b6]::thread::Builder>::spawn_unchecked_<rustc_interface[c52c57c685108550]::util::run_in_thread_pool_with_globals<rustc_interface[c52c57c685108550]::interface::run_compiler<core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>, rustc_driver[7797c2389d089e8d]::run_compiler::{closure#1}>::{closure#0}, core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>>::{closure#0}, core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>>::{closure#1}::{closure#0}>>
  43:        0x109a7f90c - <<std[5bc8614f64c760b6]::thread::Builder>::spawn_unchecked_<rustc_interface[c52c57c685108550]::util::run_in_thread_pool_with_globals<rustc_interface[c52c57c685108550]::interface::run_compiler<core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>, rustc_driver[7797c2389d089e8d]::run_compiler::{closure#1}>::{closure#0}, core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>>::{closure#0}, core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>>::{closure#1} as core[32111c0fccea723b]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  44:        0x101625ba4 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hb5035c6767426fbd
  45:        0x10164f058 - std::sys::unix::thread::Thread::new::thread_start::h8d70e3925da0bc3f
  46:        0x19614826c - __pthread_deallocate

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.64.0-dev running on aarch64-apple-darwin

query stack during panic:
#0 [lookup_stability] looking up stability of `std`
#1 [check_mod_unstable_api_usage] checking for unstable API usage in top-level module
#2 [analysis] running analysis passes on this crate
end of query stack

Copy link
Contributor

@oli-obk oli-obk Jul 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uuuh... huh. that's super weird. I don't see how that relates to opaque types at all. Or how it relates to this function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I inquire further or leave this as it is

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, please investigate. During which test is this? The new one?

Copy link
Contributor Author

@ouz-a ouz-a Jul 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, the backtrace I posted above is completely wrong... here is the new one (it's the same error as the original one). Code I am testing is this :

fn test() -> impl Iterator<Item = impl Sized> {
    Box::new(0..) as Box<dyn Iterator<Item = _>>
}
Backtrace
warning: 1 warning emitted

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

error: internal compiler error: broken MIR in DefId(0:3 ~ tabula[475d]::test) (NoSolution): could not prove Binder(TraitPredicate(<std::boxed::Box<std::ops::RangeFrom<i32>> as std::ops::CoerceUnsized<std::boxed::Box<dyn std::iter::Iterator<Item = impl Sized>>>>, polarity:Positive), [])
 --> tabula.rs:2:5
  |
2 |     Box::new(0..) as Box<dyn Iterator<Item = _>>
  |     ^^^^^^^^^^^^^
  |
  = note: delayed at compiler/rustc_borrowck/src/type_check/canonical.rs:151:13

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1426:13
stack backtrace:
   0:        0x104a2a3c0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h726e647852e3d24f
   1:        0x104aa044c - core::fmt::write::hf6491a9cad4237ce
   2:        0x104a3608c - std::io::Write::write_fmt::h2b59a831d3620ba3
   3:        0x104a2a26c - std::sys_common::backtrace::print::h77f56e81b084f8f6
   4:        0x104a515ac - std::panicking::default_hook::{{closure}}::h389eb9e26b1a1de6
   5:        0x104a513a0 - std::panicking::default_hook::h6ee0c479a40c963f
   6:        0x10ce5d39c - rustc_driver[7797c2389d089e8d]::DEFAULT_HOOK::{closure#0}::{closure#0}
   7:        0x104a51a48 - std::panicking::rust_panic_with_hook::hbaf9f93c32f27862
   8:        0x110a5da64 - std[5bc8614f64c760b6]::panicking::begin_panic::<rustc_errors[c9670795598baa39]::ExplicitBug>::{closure#0}
   9:        0x110a5da1c - std[5bc8614f64c760b6]::sys_common::backtrace::__rust_end_short_backtrace::<std[5bc8614f64c760b6]::panicking::begin_panic<rustc_errors[c9670795598baa39]::ExplicitBug>::{closure#0}, !>
  10:        0x110d85654 - std[5bc8614f64c760b6]::panicking::begin_panic::<rustc_errors[c9670795598baa39]::ExplicitBug>
  11:        0x110a429b8 - std[5bc8614f64c760b6]::panic::panic_any::<rustc_errors[c9670795598baa39]::ExplicitBug>
  12:        0x110a44a6c - <rustc_errors[c9670795598baa39]::HandlerInner>::flush_delayed::<alloc[c821cbb61612a45e]::vec::Vec<rustc_errors[c9670795598baa39]::diagnostic::Diagnostic>, &str>
  13:        0x110a4f778 - <rustc_errors[c9670795598baa39]::HandlerInner as core[32111c0fccea723b]::ops::drop::Drop>::drop
  14:        0x10ce9e240 - core[32111c0fccea723b]::ptr::drop_in_place::<rustc_errors[c9670795598baa39]::Handler>
  15:        0x10cea91e4 - core[32111c0fccea723b]::ptr::drop_in_place::<rustc_session[c448c0a5dec433c3]::parse::ParseSess>
  16:        0x10ce86018 - core[32111c0fccea723b]::ptr::drop_in_place::<alloc[c821cbb61612a45e]::rc::Rc<rustc_session[c448c0a5dec433c3]::session::Session>>
  17:        0x10ceab1a8 - core[32111c0fccea723b]::ptr::drop_in_place::<rustc_interface[c52c57c685108550]::interface::Compiler>
  18:        0x10ce5ee10 - rustc_span[931268512525c026]::with_source_map::<core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>, rustc_interface[c52c57c685108550]::interface::create_compiler_and_run<core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>, rustc_driver[7797c2389d089e8d]::run_compiler::{closure#1}>::{closure#1}>
  19:        0x10ce442d8 - rustc_interface[c52c57c685108550]::interface::create_compiler_and_run::<core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>, rustc_driver[7797c2389d089e8d]::run_compiler::{closure#1}>
  20:        0x10ce6774c - <scoped_tls[a90f9c0771ff865f]::ScopedKey<rustc_span[931268512525c026]::SessionGlobals>>::set::<rustc_interface[c52c57c685108550]::interface::run_compiler<core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>, rustc_driver[7797c2389d089e8d]::run_compiler::{closure#1}>::{closure#0}, core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>>
  21:        0x10ce4fec4 - std[5bc8614f64c760b6]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[c52c57c685108550]::util::run_in_thread_pool_with_globals<rustc_interface[c52c57c685108550]::interface::run_compiler<core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>, rustc_driver[7797c2389d089e8d]::run_compiler::{closure#1}>::{closure#0}, core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>>::{closure#0}, core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>>
  22:        0x10ce50cec - std[5bc8614f64c760b6]::panicking::try::<core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>, core[32111c0fccea723b]::panic::unwind_safe::AssertUnwindSafe<<std[5bc8614f64c760b6]::thread::Builder>::spawn_unchecked_<rustc_interface[c52c57c685108550]::util::run_in_thread_pool_with_globals<rustc_interface[c52c57c685108550]::interface::run_compiler<core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>, rustc_driver[7797c2389d089e8d]::run_compiler::{closure#1}>::{closure#0}, core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>>::{closure#0}, core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>>::{closure#1}::{closure#0}>>
  23:        0x10ce6f90c - <<std[5bc8614f64c760b6]::thread::Builder>::spawn_unchecked_<rustc_interface[c52c57c685108550]::util::run_in_thread_pool_with_globals<rustc_interface[c52c57c685108550]::interface::run_compiler<core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>, rustc_driver[7797c2389d089e8d]::run_compiler::{closure#1}>::{closure#0}, core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>>::{closure#0}, core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>>::{closure#1} as core[32111c0fccea723b]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  24:        0x104a15ba4 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hb5035c6767426fbd
  25:        0x104a3f058 - std::sys::unix::thread::Thread::new::thread_start::h8d70e3925da0bc3f
  26:        0x19614826c - __pthread_deallocate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one:

#![feature(type_alias_impl_trait)]
type Opq = impl Sized;
fn test() -> impl Iterator<Item = Opq> {
    Box::new(0..) as Box<dyn Iterator<Item = _>>
}

just gives error: unconstrained opaque type error when I remove with_opaque_type_inference.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which query is that happening in? Use -Ztreat-err-as-bug to get a useful backtrace as well as a query backtrace.

If we're using the bubble scheme, I'd expect not using take_opaque_type to also ICE. If that doesn't happen, something is either broken, or... oh probably probe is involved, just like with evaluate_obligation. If that is the case, using with_..inference is ok, but both cases should have a comment and the non-evaluate_obligations case needs to be set up to fail less extremely than with a type mismatch error (idk if that's possible easily, so we may have to leave that to a follow up)

Copy link
Contributor Author

@ouz-a ouz-a Jul 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the backtrace:

Backtrace
error: internal compiler error: broken MIR in DefId(0:5 ~ tabula[475d]::test) (NoSolution): could not prove Binder(TraitPredicate(<std::boxed::Box<std::ops::RangeFrom<i32>> as std::ops::CoerceUnsized<std::boxed::Box<dyn std::iter::Iterator<Item = Opq>>>>, polarity:Positive), [])
 --> tabula.rs:4:5
  |
4 |     Box::new(0..) as Box<dyn Iterator<Item = _>>
  |     ^^^^^^^^^^^^^

thread 'rustc' panicked at 'aborting due to `-Z treat-err-as-bug=1`', compiler/rustc_errors/src/lib.rs:1450:27
stack backtrace:
   0:        0x10373a3c0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h726e647852e3d24f
   1:        0x1037b044c - core::fmt::write::hf6491a9cad4237ce
   2:        0x10374608c - std::io::Write::write_fmt::h2b59a831d3620ba3
   3:        0x10373a26c - std::sys_common::backtrace::print::h77f56e81b084f8f6
   4:        0x1037615ac - std::panicking::default_hook::{{closure}}::h389eb9e26b1a1de6
   5:        0x1037613a0 - std::panicking::default_hook::h6ee0c479a40c963f
   6:        0x10bb6d380 - rustc_driver[7797c2389d089e8d]::DEFAULT_HOOK::{closure#0}::{closure#0}
   7:        0x103761a48 - std::panicking::rust_panic_with_hook::hbaf9f93c32f27862
   8:        0x103765540 - std::panicking::begin_panic_handler::{{closure}}::h147e22b5166ea195
   9:        0x1037654b8 - std::sys_common::backtrace::__rust_end_short_backtrace::h59d7af32b4887345
  10:        0x10376160c - _rust_begin_unwind
  11:        0x1037cc4d4 - core::panicking::panic_fmt::hbf3a6aa2f4e5afde
  12:        0x10f77d674 - <rustc_errors[c9670795598baa39]::HandlerInner>::emit_diagnostic
  13:        0x10e682cb8 - <rustc_errors[c9670795598baa39]::HandlerInner>::emit_diag_at_span::<rustc_span[931268512525c026]::span_encoding::Span>
  14:        0x10e682e28 - <rustc_errors[c9670795598baa39]::HandlerInner>::span_bug::<rustc_span[931268512525c026]::span_encoding::Span, &str>
  15:        0x10e682974 - <rustc_errors[c9670795598baa39]::Handler>::delay_span_bug::<rustc_span[931268512525c026]::span_encoding::Span, &str>
  16:        0x10e5eed30 - <rustc_borrowck[2092e3d75964856]::type_check::TypeChecker>::prove_predicate
  17:        0x10e619b98 - <rustc_borrowck[2092e3d75964856]::type_check::TypeChecker>::prove_predicates::<rustc_middle[690a795738a1840c]::ty::sty::Binder<rustc_middle[690a795738a1840c]::ty::PredicateKind>, core[32111c0fccea723b]::option::Option<rustc_middle[690a795738a1840c]::ty::sty::Binder<rustc_middle[690a795738a1840c]::ty::PredicateKind>>>
  18:        0x10e5ee96c - <rustc_borrowck[2092e3d75964856]::type_check::TypeChecker>::prove_trait_ref
  19:        0x10e5f3c58 - <rustc_borrowck[2092e3d75964856]::type_check::TypeChecker>::check_rvalue
  20:        0x10e5f5844 - <rustc_borrowck[2092e3d75964856]::type_check::TypeChecker>::typeck_mir
  21:        0x10e61d310 - rustc_borrowck[2092e3d75964856]::type_check::type_check_internal::<rustc_data_structures[ca0b50c5610ae1ab]::vec_map::VecMap<rustc_middle[690a795738a1840c]::ty::OpaqueTypeKey, (rustc_middle[690a795738a1840c]::ty::OpaqueHiddenType, rustc_hir[f54d7568531f9ef0]::hir::OpaqueTyOrigin)>, rustc_borrowck[2092e3d75964856]::type_check::type_check::{closure#0}>
  22:        0x10e5e9db8 - rustc_borrowck[2092e3d75964856]::type_check::type_check
  23:        0x10e59edb0 - rustc_borrowck[2092e3d75964856]::nll::compute_regions
  24:        0x10e5695d0 - rustc_borrowck[2092e3d75964856]::do_mir_borrowck
  25:        0x10e63b850 - <rustc_infer[c719091ac778a625]::infer::InferCtxtBuilder>::enter::<rustc_middle[690a795738a1840c]::mir::query::BorrowCheckResult, rustc_borrowck[2092e3d75964856]::mir_borrowck::{closure#0}>
  26:        0x10e563680 - rustc_borrowck[2092e3d75964856]::mir_borrowck
  27:        0x10e5435ec - <rustc_borrowck[2092e3d75964856]::provide::{closure#0} as core[32111c0fccea723b]::ops::function::FnOnce<(rustc_middle[690a795738a1840c]::ty::context::TyCtxt, rustc_span[931268512525c026]::def_id::LocalDefId)>>::call_once
  28:        0x10eab60d0 - rustc_query_system[7d8e326128972c4d]::query::plumbing::try_execute_query::<rustc_query_impl[5cb324285e2f04b9]::plumbing::QueryCtxt, rustc_query_system[7d8e326128972c4d]::query::caches::DefaultCache<rustc_span[931268512525c026]::def_id::LocalDefId, &rustc_middle[690a795738a1840c]::mir::query::BorrowCheckResult>>
  29:        0x10eb399d8 - rustc_query_system[7d8e326128972c4d]::query::plumbing::get_query::<rustc_query_impl[5cb324285e2f04b9]::queries::mir_borrowck, rustc_query_impl[5cb324285e2f04b9]::plumbing::QueryCtxt>
  30:        0x10e985e4c - <rustc_query_impl[5cb324285e2f04b9]::Queries as rustc_middle[690a795738a1840c]::ty::query::QueryEngine>::mir_borrowck
  31:        0x10e0956d4 - <rustc_typeck[4262d7238d3240f8]::collect::type_of::find_opaque_ty_constraints::ConstraintLocator>::check
  32:        0x10e094dac - <rustc_typeck[4262d7238d3240f8]::collect::type_of::find_opaque_ty_constraints::ConstraintLocator as rustc_hir[f54d7568531f9ef0]::intravisit::Visitor>::visit_item
  33:        0x10e1c2ce0 - rustc_hir[f54d7568531f9ef0]::intravisit::walk_mod::<rustc_typeck[4262d7238d3240f8]::collect::type_of::find_opaque_ty_constraints::ConstraintLocator>
  34:        0x10e0947a4 - rustc_typeck[4262d7238d3240f8]::collect::type_of::find_opaque_ty_constraints
  35:        0x10e091d84 - rustc_typeck[4262d7238d3240f8]::collect::type_of::type_of
  36:        0x10eac474c - rustc_query_system[7d8e326128972c4d]::query::plumbing::try_execute_query::<rustc_query_impl[5cb324285e2f04b9]::plumbing::QueryCtxt, rustc_query_system[7d8e326128972c4d]::query::caches::DefaultCache<rustc_span[931268512525c026]::def_id::DefId, rustc_middle[690a795738a1840c]::ty::Ty>>
  37:        0x10eb73e44 - rustc_query_system[7d8e326128972c4d]::query::plumbing::get_query::<rustc_query_impl[5cb324285e2f04b9]::queries::type_of, rustc_query_impl[5cb324285e2f04b9]::plumbing::QueryCtxt>
  38:        0x10e9764c8 - <rustc_query_impl[5cb324285e2f04b9]::Queries as rustc_middle[690a795738a1840c]::ty::query::QueryEngine>::type_of
  39:        0x10dfcc074 - rustc_typeck[4262d7238d3240f8]::check::check::check_opaque
  40:        0x10dfcd6dc - rustc_typeck[4262d7238d3240f8]::check::check::check_item_type
  41:        0x10dfd2d68 - rustc_typeck[4262d7238d3240f8]::check::check::check_mod_item_types
  42:        0x10eab7b60 - rustc_query_system[7d8e326128972c4d]::query::plumbing::try_execute_query::<rustc_query_impl[5cb324285e2f04b9]::plumbing::QueryCtxt, rustc_query_system[7d8e326128972c4d]::query::caches::DefaultCache<rustc_span[931268512525c026]::def_id::LocalDefId, ()>>
  43:        0x10eb4fd88 - rustc_query_system[7d8e326128972c4d]::query::plumbing::get_query::<rustc_query_impl[5cb324285e2f04b9]::queries::check_mod_item_types, rustc_query_impl[5cb324285e2f04b9]::plumbing::QueryCtxt>
  44:        0x10e9832b4 - <rustc_query_impl[5cb324285e2f04b9]::Queries as rustc_middle[690a795738a1840c]::ty::query::QueryEngine>::check_mod_item_types
  45:        0x10e096a34 - <rustc_middle[690a795738a1840c]::hir::map::Map>::for_each_module::<rustc_typeck[4262d7238d3240f8]::check_crate::{closure#6}::{closure#0}>
  46:        0x10e01ea80 - <rustc_session[c448c0a5dec433c3]::session::Session>::time::<(), rustc_typeck[4262d7238d3240f8]::check_crate::{closure#6}>
  47:        0x10e202924 - rustc_typeck[4262d7238d3240f8]::check_crate
  48:        0x10bc6efb0 - rustc_interface[c52c57c685108550]::passes::analysis
  49:        0x10eadc124 - rustc_query_system[7d8e326128972c4d]::query::plumbing::try_execute_query::<rustc_query_impl[5cb324285e2f04b9]::plumbing::QueryCtxt, rustc_query_system[7d8e326128972c4d]::query::caches::DefaultCache<(), core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>>>
  50:        0x10eb73fa0 - rustc_query_system[7d8e326128972c4d]::query::plumbing::get_query::<rustc_query_impl[5cb324285e2f04b9]::queries::analysis, rustc_query_impl[5cb324285e2f04b9]::plumbing::QueryCtxt>
  51:        0x10e97677c - <rustc_query_impl[5cb324285e2f04b9]::Queries as rustc_middle[690a795738a1840c]::ty::query::QueryEngine>::analysis
  52:        0x10bbc5444 - <rustc_interface[c52c57c685108550]::passes::QueryContext>::enter::<rustc_driver[7797c2389d089e8d]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>>
  53:        0x10bb53984 - <rustc_interface[c52c57c685108550]::interface::Compiler>::enter::<rustc_driver[7797c2389d089e8d]::run_compiler::{closure#1}::{closure#2}, core[32111c0fccea723b]::result::Result<core[32111c0fccea723b]::option::Option<rustc_interface[c52c57c685108550]::queries::Linker>, rustc_errors[c9670795598baa39]::ErrorGuaranteed>>
  54:        0x10bb6eb90 - rustc_span[931268512525c026]::with_source_map::<core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>, rustc_interface[c52c57c685108550]::interface::create_compiler_and_run<core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>, rustc_driver[7797c2389d089e8d]::run_compiler::{closure#1}>::{closure#1}>
  55:        0x10bb542bc - rustc_interface[c52c57c685108550]::interface::create_compiler_and_run::<core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>, rustc_driver[7797c2389d089e8d]::run_compiler::{closure#1}>
  56:        0x10bb77730 - <scoped_tls[a90f9c0771ff865f]::ScopedKey<rustc_span[931268512525c026]::SessionGlobals>>::set::<rustc_interface[c52c57c685108550]::interface::run_compiler<core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>, rustc_driver[7797c2389d089e8d]::run_compiler::{closure#1}>::{closure#0}, core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>>
  57:        0x10bb5fea8 - std[5bc8614f64c760b6]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[c52c57c685108550]::util::run_in_thread_pool_with_globals<rustc_interface[c52c57c685108550]::interface::run_compiler<core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>, rustc_driver[7797c2389d089e8d]::run_compiler::{closure#1}>::{closure#0}, core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>>::{closure#0}, core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>>
  58:        0x10bb60cd0 - std[5bc8614f64c760b6]::panicking::try::<core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>, core[32111c0fccea723b]::panic::unwind_safe::AssertUnwindSafe<<std[5bc8614f64c760b6]::thread::Builder>::spawn_unchecked_<rustc_interface[c52c57c685108550]::util::run_in_thread_pool_with_globals<rustc_interface[c52c57c685108550]::interface::run_compiler<core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>, rustc_driver[7797c2389d089e8d]::run_compiler::{closure#1}>::{closure#0}, core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>>::{closure#0}, core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>>::{closure#1}::{closure#0}>>
  59:        0x10bb7f8f0 - <<std[5bc8614f64c760b6]::thread::Builder>::spawn_unchecked_<rustc_interface[c52c57c685108550]::util::run_in_thread_pool_with_globals<rustc_interface[c52c57c685108550]::interface::run_compiler<core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>, rustc_driver[7797c2389d089e8d]::run_compiler::{closure#1}>::{closure#0}, core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>>::{closure#0}, core[32111c0fccea723b]::result::Result<(), rustc_errors[c9670795598baa39]::ErrorGuaranteed>>::{closure#1} as core[32111c0fccea723b]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  60:        0x103725ba4 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hb5035c6767426fbd
  61:        0x10374f058 - std::sys::unix::thread::Thread::new::thread_start::h8d70e3925da0bc3f
  62:        0x19614826c - __pthread_deallocate

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.64.0-dev running on aarch64-apple-darwin

note: compiler flags: -Z treat-err-as-bug

query stack during panic:
#0 [mir_borrowck] borrow-checking `test`
#1 [type_of] computing type of `Opq::{opaque#0}`
#2 [check_mod_item_types] checking item types in top-level module
#3 [analysis] running analysis passes on this crate
end of query stack

I found this to be weird in mir_borrowck we infer with with_opaque_type_inference(DefiningAnchor::Bind(hir_owner)) it still fails...

So to make this pass we just need this change to stay.

If we're using the bubble scheme, I'd expect not using take_opaque_type to also ICE. If that doesn't happen, something is either broken, or... oh probably probe is involved, just like with evaluate_obligation

But we don't use take_opaque_type here ? I checked probe it doesn't affect this.

non-evaluate_obligations case needs to be set up to fail less extremely than with a type mismatch error

I don't understand this 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this to be weird in mir_borrowck we infer with with_opaque_type_inference(DefiningAnchor::Bind(hir_owner)) it still fails...

So... some borrowck code calls type_op_prove_predicate, but the only things it can return are success or NoSolution. Without adding with_opaque_type_inference(DefiningAnchor::Bubble), this query will fail.

I checked probe it doesn't affect this.

probe does affect this by removing all hidden types added within the probe ^^

non-evaluate_obligations case needs to be set up to fail less extremely than with a type mismatch error

I don't understand this 😅

I was trying to propose that we make type_op_prove_predicate work like evaluate_obligation and return something like SucceededModuloOpaqueTypes, but I now realize that's not actually helpful. What we could do instead is either

  • replace all opaque types with inference vars before going into the query and that should hopefully cause Canonical<'tcx, QueryResponse to contain all the data to equate what ever types came out of it with the opaque type and have borrowck thus figure out the hidden types
    • lots of handwaving here, no clue if this works
  • figure out how to bubble out the hidden types instead of allowing the probe to lose them. Do we even need the probe?

&canonicalized,
|infcx, fulfill_cx, key| {
type_op_prove_predicate_with_cause(infcx, fulfill_cx, key, ObligationCause::dummy());
Ok(())
},
)
}

/// The core of the `type_op_prove_predicate` query: for diagnostics purposes in NLL HRTB errors,
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/impl-trait/issue-99642-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// check-pass

#![feature(type_alias_impl_trait)]
type Opq = impl Sized;
fn test() -> impl Iterator<Item = Opq> {
Box::new(0..) as Box<dyn Iterator<Item = _>>
}
fn main(){}
7 changes: 7 additions & 0 deletions src/test/ui/impl-trait/issue-99642.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// check-pass

fn test() -> impl Iterator<Item = impl Sized> {
Box::new(0..) as Box<dyn Iterator<Item = _>>
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
error[E0275]: overflow evaluating the requirement `<fn() -> Foo {foo} as FnOnce<()>>::Output == fn() -> Foo {foo}`
error[E0275]: overflow evaluating the requirement `fn() -> Foo {foo}: Sized`
--> $DIR/issue-53398-cyclic-types.rs:5:13
|
LL | fn foo() -> Foo {
| ^^^
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_53398_cyclic_types`)

error: aborting due to previous error

Expand Down