Skip to content
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

Some NodeId/LocalDefId don't have a corresponding HirId #71104

Closed
marmeladema opened this issue Apr 13, 2020 · 3 comments · Fixed by #73566
Closed

Some NodeId/LocalDefId don't have a corresponding HirId #71104

marmeladema opened this issue Apr 13, 2020 · 3 comments · Fixed by #73566
Labels
A-HIR Area: The high-level intermediate representation (HIR) A-type-system Area: Type system P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@marmeladema
Copy link
Contributor

marmeladema commented Apr 13, 2020

During refactor work to remove DUMMY_HIR_ID (see #71116), I noticed that some queries like has_typeck_tables are called for some NodeId or DefId that do not have a corresponding HirId.

Some specific helper functions have been introduced to overcome this bug and used in different places:

Especially, the following tests failed when trying to use as_local_hir_id:

failures:
    [ui] ui/generator/async-generator-issue-67158.rs
    [ui] ui/save-analysis/issue-68621.rs
    [ui] ui/type-alias-impl-trait/issue-63279.rs
    [ui] ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs

For ui/save-analysis/issue-68621.rs, the query debug info is:

#0 [has_typeck_tables] processing `<Struct as Service>::Future::{{opaque}}#0`

and for ui/type-alias-impl-trait/issue-63279.rs:

#0 [has_typeck_tables] processing `Closure::{{opaque}}#0`

Example backtrace for ui/save-analysis/issue-68621.rs:

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', /home/adema/code/rust/src/librustc_hir/definitions.rs:368:9
stack backtrace:
   0:     0x7fba2ed1ebe4 - backtrace::backtrace::libunwind::trace::hf4e48ba64f80f3eb
                               at /home/adema/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1:     0x7fba2ed1ebe4 - backtrace::backtrace::trace_unsynchronized::hc05f5ae9bd82f888
                               at /home/adema/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2:     0x7fba2ed1ebe4 - std::sys_common::backtrace::_print_fmt::h6194c30153926243
                               at src/libstd/sys_common/backtrace.rs:78
   3:     0x7fba2ed1ebe4 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hdefc5db2589e7b2f
                               at src/libstd/sys_common/backtrace.rs:59
   4:     0x7fba2ed6610c - core::fmt::write::h5e80f79ba6cafaf2
                               at src/libcore/fmt/mod.rs:1069
   5:     0x7fba2ed0d665 - std::io::Write::write_fmt::he4f935868e47e3ba
                               at src/libstd/io/mod.rs:1504
   6:     0x7fba2ecf27e5 - std::sys_common::backtrace::_print::h3fc078a3aae1ebdf
                               at src/libstd/sys_common/backtrace.rs:62
   7:     0x7fba2ecf27e5 - std::sys_common::backtrace::print::h27137ce93aeba206
                               at src/libstd/sys_common/backtrace.rs:49
   8:     0x7fba2ecf27e5 - std::panicking::default_hook::{{closure}}::h466f8b9e45a47838
                               at src/libstd/panicking.rs:198
   9:     0x7fba2ecf24cf - std::panicking::default_hook::h7589bdd3a2ab152b
                               at src/libstd/panicking.rs:218
  10:     0x7fba2f3f5673 - <alloc::boxed::Box<F> as core::ops::function::Fn<A>>::call::h25fa7aa7eb2f6f06
                               at /home/adema/code/rust/src/liballoc/boxed.rs:1022
  11:     0x7fba2f3f5673 - rustc_driver::report_ice::he6496451e88ccee4
                               at src/librustc_driver/lib.rs:1172
  12:     0x7fba2ecf3015 - std::panicking::rust_panic_with_hook::h94399de650c4f4da
                               at src/libstd/panicking.rs:515
  13:     0x7fba2ecf2b2b - rust_begin_unwind
                               at src/libstd/panicking.rs:419
  14:     0x7fba2ed63e51 - core::panicking::panic_fmt::h5a23a1434eb19732
                               at src/libcore/panicking.rs:111
  15:     0x7fba2ed63d9d - core::panicking::panic::h1a56bed8578da5a8
                               at src/libcore/panicking.rs:56
  16:     0x7fba320e3fa2 - core::option::Option<T>::unwrap::h01ca14479a9f3380
                               at /home/adema/code/rust/src/libcore/macros/mod.rs:11
  17:     0x7fba320e3fa2 - rustc_hir::definitions::Definitions::local_def_id_to_hir_id::h3e942dc1a9cdcbe3
                               at /home/adema/code/rust/src/librustc_hir/definitions.rs:368
  18:     0x7fba320e3fa2 - rustc_hir::definitions::Definitions::as_local_hir_id::h5052ccdd1650b1de
                               at /home/adema/code/rust/src/librustc_hir/definitions.rs:348
  19:     0x7fba320e3fa2 - rustc_middle::hir::map::Map::as_local_hir_id::hcc7339a4abf77535
                               at /home/adema/code/rust/src/librustc_middle/hir/map/mod.rs:204
  20:     0x7fba320e3fa2 - rustc_typeck::check::has_typeck_tables::h51a84fff8ccfcc3e
                               at src/librustc_typeck/check/mod.rs:842
  21:     0x7fba2f5fe272 - rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::has_typeck_tables>::compute::hcb61e0605089bcde
                               at /home/adema/code/rust/src/librustc_middle/ty/query/plumbing.rs:357
  22:     0x7fba2f5f8d34 - rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl::hab41ebbda3aa67f9
                               at /home/adema/code/rust/src/librustc_query_system/dep_graph/graph.rs:303
  23:     0x7fba2f60165d - rustc_query_system::dep_graph::graph::DepGraph<K>::with_task::h4369254ed57a7056
                               at /home/adema/code/rust/src/librustc_query_system/dep_graph/graph.rs:200
  24:     0x7fba2f60165d - rustc_query_system::query::plumbing::force_query_with_job::{{closure}}::{{closure}}::habdfeebee3f9cf45
                               at /home/adema/code/rust/src/librustc_query_system/query/plumbing.rs:593
  25:     0x7fba2f60165d - rustc_middle::ty::query::plumbing::<impl rustc_query_system::query::QueryContext for rustc_middle::ty::context::TyCtxt>::start_query::{{closure}}::{{closure}}::hd83318f92b9d7499
                               at /home/adema/code/rust/src/librustc_middle/ty/query/plumbing.rs:71
  26:     0x7fba2f60165d - rustc_middle::ty::context::tls::enter_context::{{closure}}::hdd4d49fc80d57c78
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1695
  27:     0x7fba2f60165d - rustc_middle::ty::context::tls::set_tlv::hc68046dd904eed8f
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1679
  28:     0x7fba2f60165d - rustc_middle::ty::context::tls::enter_context::h381621443cbb0e97
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1695
  29:     0x7fba2f60165d - rustc_middle::ty::query::plumbing::<impl rustc_query_system::query::QueryContext for rustc_middle::ty::context::TyCtxt>::start_query::{{closure}}::he843232fc1f45e72
                               at /home/adema/code/rust/src/librustc_middle/ty/query/plumbing.rs:71
  30:     0x7fba2f60165d - rustc_middle::ty::context::tls::with_related_context::{{closure}}::h4e7df0c52657e941
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1783
  31:     0x7fba2f60165d - rustc_middle::ty::context::tls::with_context::{{closure}}::h47a3fbb102fc828d
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1767
  32:     0x7fba2f60165d - rustc_middle::ty::context::tls::with_context_opt::ha6f845fb734f0a78
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1756
  33:     0x7fba2f60165d - rustc_middle::ty::context::tls::with_context::h757b8664d833e169
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1767
  34:     0x7fba2f60165d - rustc_middle::ty::context::tls::with_related_context::hcf3df7ef753f1f12
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1780
  35:     0x7fba2f60165d - rustc_middle::ty::query::plumbing::<impl rustc_query_system::query::QueryContext for rustc_middle::ty::context::TyCtxt>::start_query::h2f6dc24b8579de5f
                               at /home/adema/code/rust/src/librustc_middle/ty/query/plumbing.rs:60
  36:     0x7fba2f60165d - rustc_query_system::query::plumbing::force_query_with_job::{{closure}}::h8bf9e4bceef20544
                               at /home/adema/code/rust/src/librustc_query_system/query/plumbing.rs:583
  37:     0x7fba2f60165d - rustc_query_system::query::plumbing::with_diagnostics::haa016d7b51fce7cd
                               at /home/adema/code/rust/src/librustc_query_system/query/plumbing.rs:293
  38:     0x7fba2f60165d - rustc_query_system::query::plumbing::force_query_with_job::hb8bc1b278cc4ab1f
                               at /home/adema/code/rust/src/librustc_query_system/query/plumbing.rs:582
  39:     0x7fba2f60165d - rustc_query_system::query::plumbing::try_execute_query::h6d851fa650ee170a
                               at /home/adema/code/rust/src/librustc_query_system/query/plumbing.rs:410
  40:     0x7fba2f60165d - rustc_query_system::query::plumbing::get_query::{{closure}}::hd76e9b348ed430b5
                               at /home/adema/code/rust/src/librustc_query_system/query/plumbing.rs:627
  41:     0x7fba2f60165d - <rustc_query_system::query::caches::DefaultCache<K,V> as rustc_query_system::query::caches::QueryCache>::lookup::h65ee3022cd4fbc4b
                               at /home/adema/code/rust/src/librustc_query_system/query/caches.rs:91
  42:     0x7fba2f60165d - rustc_query_system::query::plumbing::try_get_cached::h458fe2f3c22a5ae0
                               at /home/adema/code/rust/src/librustc_query_system/query/plumbing.rs:368
  43:     0x7fba2f60165d - rustc_query_system::query::plumbing::get_query::h246763f6bd13604d
                               at /home/adema/code/rust/src/librustc_query_system/query/plumbing.rs:619
  44:     0x7fba2f5f57cf - rustc_middle::ty::query::TyCtxtAt::has_typeck_tables::ha54a24b2f1464e26
                               at /home/adema/code/rust/src/librustc_middle/ty/query/plumbing.rs:462
  45:     0x7fba2f5f57cf - rustc_middle::ty::query::<impl rustc_middle::ty::context::TyCtxt>::has_typeck_tables::h41d192875f061dea
                               at /home/adema/code/rust/src/librustc_middle/ty/query/plumbing.rs:425
  46:     0x7fba2f5f57cf - rustc_save_analysis::dump_visitor::DumpVisitor::nest_tables::h7bec618ccd6b7e9b
                               at src/librustc_save_analysis/dump_visitor.rs:112
  47:     0x7fba2f5f57cf - <rustc_save_analysis::dump_visitor::DumpVisitor as rustc_ast::visit::Visitor>::visit_ty::h24636c8a8e006b2e
                               at src/librustc_save_analysis/dump_visitor.rs:1419
  48:     0x7fba2f5f1efa - rustc_save_analysis::dump_visitor::DumpVisitor::process_impl_item::h3929b05aaef88a1b
                               at src/librustc_save_analysis/dump_visitor.rs:1107
  49:     0x7fba2f5f1efa - rustc_save_analysis::dump_visitor::DumpVisitor::process_impl::{{closure}}::hda1b88089e758a26
                               at src/librustc_save_analysis/dump_visitor.rs:675
  50:     0x7fba2f5f1efa - rustc_save_analysis::dump_visitor::DumpVisitor::nest_tables::he39ba8de26691545
                               at src/librustc_save_analysis/dump_visitor.rs:120
  51:     0x7fba2f5f1efa - rustc_save_analysis::dump_visitor::DumpVisitor::process_impl::h3357dee0ab6a675f
                               at src/librustc_save_analysis/dump_visitor.rs:668
  52:     0x7fba2f5f1efa - <rustc_save_analysis::dump_visitor::DumpVisitor as rustc_ast::visit::Visitor>::visit_item::hd1c32cd3f75a6e43
                               at src/librustc_save_analysis/dump_visitor.rs:1308
  53:     0x7fba2f5ee65a - rustc_ast::visit::walk_mod::h453232913b72f97a
                               at /home/adema/code/rust/src/librustc_ast/visit.rs:236
  54:     0x7fba2f5ee65a - <rustc_save_analysis::dump_visitor::DumpVisitor as rustc_ast::visit::Visitor>::visit_mod::hff0465a2c83a38d8
                               at src/librustc_save_analysis/dump_visitor.rs:1262
  55:     0x7fba2f3fbfa3 - rustc_ast::visit::walk_crate::hd16e58112689af6c
                               at /home/adema/code/rust/src/librustc_ast/visit.rs:251
  56:     0x7fba2f5480e1 - rustc_save_analysis::process_crate::{{closure}}::h81b39ee5fe417e3c
                               at /home/adema/code/rust/src/librustc_save_analysis/lib.rs:1043
  57:     0x7fba2f5480e1 - rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps::{{closure}}::{{closure}}::h4392b1dbdb581074
                               at /home/adema/code/rust/src/librustc_middle/dep_graph/mod.rs:71
  58:     0x7fba2f5480e1 - rustc_middle::ty::context::tls::enter_context::{{closure}}::h26a4f348a195ab40
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1695
  59:     0x7fba2f5480e1 - rustc_middle::ty::context::tls::set_tlv::hf112bb4733627b25
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1679
  60:     0x7fba2f5480e1 - rustc_middle::ty::context::tls::enter_context::h2205d6117dd7d657
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1695
  61:     0x7fba2f5480e1 - rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps::{{closure}}::h4825e2841f7105d4
                               at /home/adema/code/rust/src/librustc_middle/dep_graph/mod.rs:71
  62:     0x7fba2f5480e1 - rustc_middle::ty::context::tls::with_context::{{closure}}::h54a5c25daa6df37c
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1767
  63:     0x7fba2f5480e1 - rustc_middle::ty::context::tls::with_context_opt::h4955f6b417c79b08
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1756
  64:     0x7fba2f5480e1 - rustc_middle::ty::context::tls::with_context::h48976b8c37bd37ea
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1767
  65:     0x7fba2f5480e1 - rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps::ha925f2d79ea5ae7b
                               at /home/adema/code/rust/src/librustc_middle/dep_graph/mod.rs:68
  66:     0x7fba2f548bcd - rustc_query_system::dep_graph::graph::DepGraph<K>::with_ignore::heb8e89779bb2ee5c
                               at /home/adema/code/rust/src/librustc_query_system/dep_graph/graph.rs:162
  67:     0x7fba2f548bcd - rustc_save_analysis::process_crate::h261f0a0143c82a15
                               at /home/adema/code/rust/src/librustc_save_analysis/lib.rs:1019
  68:     0x7fba2f548bcd - rustc_driver::run_compiler::{{closure}}::{{closure}}::{{closure}}::{{closure}}::h8fbb56155e5868f0
                               at src/librustc_driver/lib.rs:360
  69:     0x7fba2f548bcd - rustc_data_structures::profiling::VerboseTimingGuard::run::he233753eb9d0f987
                               at /home/adema/code/rust/src/librustc_data_structures/profiling.rs:568
  70:     0x7fba2f548bcd - rustc_session::utils::<impl rustc_session::session::Session>::time::h3e44c1f80824bde6
                               at /home/adema/code/rust/src/librustc_session/utils.rs:9
  71:     0x7fba2f5791db - rustc_driver::run_compiler::{{closure}}::{{closure}}::{{closure}}::hc0a4eb6a93a6acbb
                               at src/librustc_driver/lib.rs:359
  72:     0x7fba2f5791db - rustc_middle::ty::context::tls::enter_global::{{closure}}::h4f772c7273d0b953
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1718
  73:     0x7fba2f5791db - rustc_middle::ty::context::tls::enter_context::{{closure}}::hc4091cfff8b06f9d
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1695
  74:     0x7fba2f5791db - rustc_middle::ty::context::tls::set_tlv::h9207087df904d098
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1679
  75:     0x7fba2f5791db - rustc_middle::ty::context::tls::enter_context::had72ad5eaff43ada
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1695
  76:     0x7fba2f5791db - rustc_middle::ty::context::tls::enter_global::h71995367196689c6
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1718
  77:     0x7fba2f549a54 - rustc_interface::passes::QueryContext::enter::h06663ee920c9b92d
                               at /home/adema/code/rust/src/librustc_interface/passes.rs:709
  78:     0x7fba2f549a54 - rustc_driver::run_compiler::{{closure}}::{{closure}}::he256573a74ae418a
                               at src/librustc_driver/lib.rs:356
  79:     0x7fba2f549a54 - rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter::h92c934d043260141
                               at /home/adema/code/rust/src/librustc_interface/queries.rs:385
  80:     0x7fba2f549a54 - rustc_driver::run_compiler::{{closure}}::hb4e87ee0015ffcea
                               at src/librustc_driver/lib.rs:283
  81:     0x7fba2f549a54 - rustc_interface::interface::run_compiler_in_existing_thread_pool::h0214c6d436249d75
                               at /home/adema/code/rust/src/librustc_interface/interface.rs:199
  82:     0x7fba2f3feffd - rustc_interface::interface::run_compiler::{{closure}}::h74859c046fb08e3f
                               at /home/adema/code/rust/src/librustc_interface/interface.rs:213
  83:     0x7fba2f3feffd - rustc_interface::util::spawn_thread_pool::{{closure}}::{{closure}}::{{closure}}::h79d111f3ae438d15
                               at /home/adema/code/rust/src/librustc_interface/util.rs:152
  84:     0x7fba2f3feffd - scoped_tls::ScopedKey<T>::set::h1cf2eba532202ed5
                               at /home/adema/.cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
  85:     0x7fba2f3feffd - rustc_interface::util::spawn_thread_pool::{{closure}}::{{closure}}::hb845af3cf404145b
                               at /home/adema/code/rust/src/librustc_interface/util.rs:148
  86:     0x7fba2f3feffd - scoped_tls::ScopedKey<T>::set::ha94ad89e21750bf4
                               at /home/adema/.cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
  87:     0x7fba2f3feffd - rustc_ast::attr::with_globals::{{closure}}::h925ca335cf988b3a
                               at /home/adema/code/rust/src/librustc_ast/attr/mod.rs:44
  88:     0x7fba2f3feffd - scoped_tls::ScopedKey<T>::set::h370e4876e5998364
                               at /home/adema/.cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
  89:     0x7fba2f3fbd04 - rustc_ast::attr::with_globals::h2d1de10aeff62ecf
                               at /home/adema/code/rust/src/librustc_ast/attr/mod.rs:44
  90:     0x7fba2f407f64 - rustc_interface::util::spawn_thread_pool::{{closure}}::h0f507ae6322d57b0
                               at /home/adema/code/rust/src/librustc_interface/util.rs:147
  91:     0x7fba2f407f64 - rustc_interface::util::scoped_thread::{{closure}}::h37f638b7f6de2a83
                               at /home/adema/code/rust/src/librustc_interface/util.rs:122
  92:     0x7fba2f407f64 - std::sys_common::backtrace::__rust_begin_short_backtrace::hda4d986712102604
                               at /home/adema/code/rust/src/libstd/sys_common/backtrace.rs:130
  93:     0x7fba2ecf2954 - std::panicking::try::do_try::hed7a629852400b5f
                               at src/libstd/panicking.rs:298
  94:     0x7fba2f54d0fd - std::panicking::try::ha4e540c03fa2d4c0
                               at /home/adema/code/rust/src/libstd/panicking.rs:274
  95:     0x7fba2f54d0fd - std::panic::catch_unwind::h99519e6c997fe112
                               at /home/adema/code/rust/src/libstd/panic.rs:394
  96:     0x7fba2f54d0fd - std::thread::Builder::spawn_unchecked::{{closure}}::hc2d0ac9187f1dd6d
                               at /home/adema/code/rust/src/libstd/thread/mod.rs:474
  97:     0x7fba2f54d0fd - core::ops::function::FnOnce::call_once{{vtable.shim}}::h86e0f7111ce1cb62
                               at /home/adema/code/rust/src/libcore/ops/function.rs:232
  98:     0x7fba2ed1240f - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h7d8c0ce9bb9a9a7b
                               at /home/adema/code/rust/src/liballoc/boxed.rs:1008
  99:     0x7fba2ecfab23 - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::hfcf1edc22130327f
                               at /home/adema/code/rust/src/liballoc/boxed.rs:1008
 100:     0x7fba2ecfab23 - std::sys::unix::thread::Thread::new::thread_start::he3bd71071b1a178e
                               at src/libstd/sys/unix/thread.rs:87
 101:     0x7fba2ea98f27 - start_thread
                               at /builddir/glibc-2.30/nptl/pthread_create.c:479
 102:     0x7fba2ebb2e0f - __GI___clone
                               at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
 103:                0x0 - <unknown>

and for ui/type-alias-impl-trait/issue-63279.rs:

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', /home/adema/code/rust/src/librustc_hir/definitions.rs:368:9
stack backtrace:
   0:     0x7f59a4c6cbe4 - backtrace::backtrace::libunwind::trace::hf4e48ba64f80f3eb
                               at /home/adema/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1:     0x7f59a4c6cbe4 - backtrace::backtrace::trace_unsynchronized::hc05f5ae9bd82f888
                               at /home/adema/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2:     0x7f59a4c6cbe4 - std::sys_common::backtrace::_print_fmt::h6194c30153926243
                               at src/libstd/sys_common/backtrace.rs:78
   3:     0x7f59a4c6cbe4 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hdefc5db2589e7b2f
                               at src/libstd/sys_common/backtrace.rs:59
   4:     0x7f59a4cb410c - core::fmt::write::h5e80f79ba6cafaf2
                               at src/libcore/fmt/mod.rs:1069
   5:     0x7f59a4c5b665 - std::io::Write::write_fmt::he4f935868e47e3ba
                               at src/libstd/io/mod.rs:1504
   6:     0x7f59a4c407e5 - std::sys_common::backtrace::_print::h3fc078a3aae1ebdf
                               at src/libstd/sys_common/backtrace.rs:62
   7:     0x7f59a4c407e5 - std::sys_common::backtrace::print::h27137ce93aeba206
                               at src/libstd/sys_common/backtrace.rs:49
   8:     0x7f59a4c407e5 - std::panicking::default_hook::{{closure}}::h466f8b9e45a47838
                               at src/libstd/panicking.rs:198
   9:     0x7f59a4c404cf - std::panicking::default_hook::h7589bdd3a2ab152b
                               at src/libstd/panicking.rs:218
  10:     0x7f59a5343673 - <alloc::boxed::Box<F> as core::ops::function::Fn<A>>::call::h25fa7aa7eb2f6f06
                               at /home/adema/code/rust/src/liballoc/boxed.rs:1022
  11:     0x7f59a5343673 - rustc_driver::report_ice::he6496451e88ccee4
                               at src/librustc_driver/lib.rs:1172
  12:     0x7f59a4c41015 - std::panicking::rust_panic_with_hook::h94399de650c4f4da
                               at src/libstd/panicking.rs:515
  13:     0x7f59a4c40b2b - rust_begin_unwind
                               at src/libstd/panicking.rs:419
  14:     0x7f59a4cb1e51 - core::panicking::panic_fmt::h5a23a1434eb19732
                               at src/libcore/panicking.rs:111
  15:     0x7f59a4cb1d9d - core::panicking::panic::h1a56bed8578da5a8
                               at src/libcore/panicking.rs:56
  16:     0x7f59a8031fa2 - core::option::Option<T>::unwrap::h01ca14479a9f3380
                               at /home/adema/code/rust/src/libcore/macros/mod.rs:11
  17:     0x7f59a8031fa2 - rustc_hir::definitions::Definitions::local_def_id_to_hir_id::h3e942dc1a9cdcbe3
                               at /home/adema/code/rust/src/librustc_hir/definitions.rs:368
  18:     0x7f59a8031fa2 - rustc_hir::definitions::Definitions::as_local_hir_id::h5052ccdd1650b1de
                               at /home/adema/code/rust/src/librustc_hir/definitions.rs:348
  19:     0x7f59a8031fa2 - rustc_middle::hir::map::Map::as_local_hir_id::hcc7339a4abf77535
                               at /home/adema/code/rust/src/librustc_middle/hir/map/mod.rs:204
  20:     0x7f59a8031fa2 - rustc_typeck::check::has_typeck_tables::h51a84fff8ccfcc3e
                               at src/librustc_typeck/check/mod.rs:842
  21:     0x7f59a554c272 - rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::has_typeck_tables>::compute::hcb61e0605089bcde
                               at /home/adema/code/rust/src/librustc_middle/ty/query/plumbing.rs:357
  22:     0x7f59a5546d34 - rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl::hab41ebbda3aa67f9
                               at /home/adema/code/rust/src/librustc_query_system/dep_graph/graph.rs:303
  23:     0x7f59a554f65d - rustc_query_system::dep_graph::graph::DepGraph<K>::with_task::h4369254ed57a7056
                               at /home/adema/code/rust/src/librustc_query_system/dep_graph/graph.rs:200
  24:     0x7f59a554f65d - rustc_query_system::query::plumbing::force_query_with_job::{{closure}}::{{closure}}::habdfeebee3f9cf45
                               at /home/adema/code/rust/src/librustc_query_system/query/plumbing.rs:593
  25:     0x7f59a554f65d - rustc_middle::ty::query::plumbing::<impl rustc_query_system::query::QueryContext for rustc_middle::ty::context::TyCtxt>::start_query::{{closure}}::{{closure}}::hd83318f92b9d7499
                               at /home/adema/code/rust/src/librustc_middle/ty/query/plumbing.rs:71
  26:     0x7f59a554f65d - rustc_middle::ty::context::tls::enter_context::{{closure}}::hdd4d49fc80d57c78
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1695
  27:     0x7f59a554f65d - rustc_middle::ty::context::tls::set_tlv::hc68046dd904eed8f
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1679
  28:     0x7f59a554f65d - rustc_middle::ty::context::tls::enter_context::h381621443cbb0e97
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1695
  29:     0x7f59a554f65d - rustc_middle::ty::query::plumbing::<impl rustc_query_system::query::QueryContext for rustc_middle::ty::context::TyCtxt>::start_query::{{closure}}::he843232fc1f45e72
                               at /home/adema/code/rust/src/librustc_middle/ty/query/plumbing.rs:71
  30:     0x7f59a554f65d - rustc_middle::ty::context::tls::with_related_context::{{closure}}::h4e7df0c52657e941
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1783
  31:     0x7f59a554f65d - rustc_middle::ty::context::tls::with_context::{{closure}}::h47a3fbb102fc828d
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1767
  32:     0x7f59a554f65d - rustc_middle::ty::context::tls::with_context_opt::ha6f845fb734f0a78
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1756
  33:     0x7f59a554f65d - rustc_middle::ty::context::tls::with_context::h757b8664d833e169
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1767
  34:     0x7f59a554f65d - rustc_middle::ty::context::tls::with_related_context::hcf3df7ef753f1f12
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1780
  35:     0x7f59a554f65d - rustc_middle::ty::query::plumbing::<impl rustc_query_system::query::QueryContext for rustc_middle::ty::context::TyCtxt>::start_query::h2f6dc24b8579de5f
                               at /home/adema/code/rust/src/librustc_middle/ty/query/plumbing.rs:60
  36:     0x7f59a554f65d - rustc_query_system::query::plumbing::force_query_with_job::{{closure}}::h8bf9e4bceef20544
                               at /home/adema/code/rust/src/librustc_query_system/query/plumbing.rs:583
  37:     0x7f59a554f65d - rustc_query_system::query::plumbing::with_diagnostics::haa016d7b51fce7cd
                               at /home/adema/code/rust/src/librustc_query_system/query/plumbing.rs:293
  38:     0x7f59a554f65d - rustc_query_system::query::plumbing::force_query_with_job::hb8bc1b278cc4ab1f
                               at /home/adema/code/rust/src/librustc_query_system/query/plumbing.rs:582
  39:     0x7f59a554f65d - rustc_query_system::query::plumbing::try_execute_query::h6d851fa650ee170a
                               at /home/adema/code/rust/src/librustc_query_system/query/plumbing.rs:410
  40:     0x7f59a554f65d - rustc_query_system::query::plumbing::get_query::{{closure}}::hd76e9b348ed430b5
                               at /home/adema/code/rust/src/librustc_query_system/query/plumbing.rs:627
  41:     0x7f59a554f65d - <rustc_query_system::query::caches::DefaultCache<K,V> as rustc_query_system::query::caches::QueryCache>::lookup::h65ee3022cd4fbc4b
                               at /home/adema/code/rust/src/librustc_query_system/query/caches.rs:91
  42:     0x7f59a554f65d - rustc_query_system::query::plumbing::try_get_cached::h458fe2f3c22a5ae0
                               at /home/adema/code/rust/src/librustc_query_system/query/plumbing.rs:368
  43:     0x7f59a554f65d - rustc_query_system::query::plumbing::get_query::h246763f6bd13604d
                               at /home/adema/code/rust/src/librustc_query_system/query/plumbing.rs:619
  44:     0x7f59a55437cf - rustc_middle::ty::query::TyCtxtAt::has_typeck_tables::ha54a24b2f1464e26
                               at /home/adema/code/rust/src/librustc_middle/ty/query/plumbing.rs:462
  45:     0x7f59a55437cf - rustc_middle::ty::query::<impl rustc_middle::ty::context::TyCtxt>::has_typeck_tables::h41d192875f061dea
                               at /home/adema/code/rust/src/librustc_middle/ty/query/plumbing.rs:425
  46:     0x7f59a55437cf - rustc_save_analysis::dump_visitor::DumpVisitor::nest_tables::h7bec618ccd6b7e9b
                               at src/librustc_save_analysis/dump_visitor.rs:112
  47:     0x7f59a55437cf - <rustc_save_analysis::dump_visitor::DumpVisitor as rustc_ast::visit::Visitor>::visit_ty::h24636c8a8e006b2e
                               at src/librustc_save_analysis/dump_visitor.rs:1419
  48:     0x7f59a554201f - <rustc_save_analysis::dump_visitor::DumpVisitor as rustc_ast::visit::Visitor>::visit_item::hd1c32cd3f75a6e43
                               at src/librustc_save_analysis/dump_visitor.rs:1352
  49:     0x7f59a553c65a - rustc_ast::visit::walk_mod::h453232913b72f97a
                               at /home/adema/code/rust/src/librustc_ast/visit.rs:236
  50:     0x7f59a553c65a - <rustc_save_analysis::dump_visitor::DumpVisitor as rustc_ast::visit::Visitor>::visit_mod::hff0465a2c83a38d8
                               at src/librustc_save_analysis/dump_visitor.rs:1262
  51:     0x7f59a5349fa3 - rustc_ast::visit::walk_crate::hd16e58112689af6c
                               at /home/adema/code/rust/src/librustc_ast/visit.rs:251
  52:     0x7f59a54960e1 - rustc_save_analysis::process_crate::{{closure}}::h81b39ee5fe417e3c
                               at /home/adema/code/rust/src/librustc_save_analysis/lib.rs:1043
  53:     0x7f59a54960e1 - rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps::{{closure}}::{{closure}}::h4392b1dbdb581074
                               at /home/adema/code/rust/src/librustc_middle/dep_graph/mod.rs:71
  54:     0x7f59a54960e1 - rustc_middle::ty::context::tls::enter_context::{{closure}}::h26a4f348a195ab40
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1695
  55:     0x7f59a54960e1 - rustc_middle::ty::context::tls::set_tlv::hf112bb4733627b25
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1679
  56:     0x7f59a54960e1 - rustc_middle::ty::context::tls::enter_context::h2205d6117dd7d657
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1695
  57:     0x7f59a54960e1 - rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps::{{closure}}::h4825e2841f7105d4
                               at /home/adema/code/rust/src/librustc_middle/dep_graph/mod.rs:71
  58:     0x7f59a54960e1 - rustc_middle::ty::context::tls::with_context::{{closure}}::h54a5c25daa6df37c
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1767
  59:     0x7f59a54960e1 - rustc_middle::ty::context::tls::with_context_opt::h4955f6b417c79b08
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1756
  60:     0x7f59a54960e1 - rustc_middle::ty::context::tls::with_context::h48976b8c37bd37ea
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1767
  61:     0x7f59a54960e1 - rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps::ha925f2d79ea5ae7b
                               at /home/adema/code/rust/src/librustc_middle/dep_graph/mod.rs:68
  62:     0x7f59a5496bcd - rustc_query_system::dep_graph::graph::DepGraph<K>::with_ignore::heb8e89779bb2ee5c
                               at /home/adema/code/rust/src/librustc_query_system/dep_graph/graph.rs:162
  63:     0x7f59a5496bcd - rustc_save_analysis::process_crate::h261f0a0143c82a15
                               at /home/adema/code/rust/src/librustc_save_analysis/lib.rs:1019
  64:     0x7f59a5496bcd - rustc_driver::run_compiler::{{closure}}::{{closure}}::{{closure}}::{{closure}}::h8fbb56155e5868f0
                               at src/librustc_driver/lib.rs:360
  65:     0x7f59a5496bcd - rustc_data_structures::profiling::VerboseTimingGuard::run::he233753eb9d0f987
                               at /home/adema/code/rust/src/librustc_data_structures/profiling.rs:568
  66:     0x7f59a5496bcd - rustc_session::utils::<impl rustc_session::session::Session>::time::h3e44c1f80824bde6
                               at /home/adema/code/rust/src/librustc_session/utils.rs:9
  67:     0x7f59a54c71db - rustc_driver::run_compiler::{{closure}}::{{closure}}::{{closure}}::hc0a4eb6a93a6acbb
                               at src/librustc_driver/lib.rs:359
  68:     0x7f59a54c71db - rustc_middle::ty::context::tls::enter_global::{{closure}}::h4f772c7273d0b953
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1718
  69:     0x7f59a54c71db - rustc_middle::ty::context::tls::enter_context::{{closure}}::hc4091cfff8b06f9d
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1695
  70:     0x7f59a54c71db - rustc_middle::ty::context::tls::set_tlv::h9207087df904d098
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1679
  71:     0x7f59a54c71db - rustc_middle::ty::context::tls::enter_context::had72ad5eaff43ada
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1695
  72:     0x7f59a54c71db - rustc_middle::ty::context::tls::enter_global::h71995367196689c6
                               at /home/adema/code/rust/src/librustc_middle/ty/context.rs:1718
  73:     0x7f59a5497a54 - rustc_interface::passes::QueryContext::enter::h06663ee920c9b92d
                               at /home/adema/code/rust/src/librustc_interface/passes.rs:709
  74:     0x7f59a5497a54 - rustc_driver::run_compiler::{{closure}}::{{closure}}::he256573a74ae418a
                               at src/librustc_driver/lib.rs:356
  75:     0x7f59a5497a54 - rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter::h92c934d043260141
                               at /home/adema/code/rust/src/librustc_interface/queries.rs:385
  76:     0x7f59a5497a54 - rustc_driver::run_compiler::{{closure}}::hb4e87ee0015ffcea
                               at src/librustc_driver/lib.rs:283
  77:     0x7f59a5497a54 - rustc_interface::interface::run_compiler_in_existing_thread_pool::h0214c6d436249d75
                               at /home/adema/code/rust/src/librustc_interface/interface.rs:199
  78:     0x7f59a534cffd - rustc_interface::interface::run_compiler::{{closure}}::h74859c046fb08e3f
                               at /home/adema/code/rust/src/librustc_interface/interface.rs:213
  79:     0x7f59a534cffd - rustc_interface::util::spawn_thread_pool::{{closure}}::{{closure}}::{{closure}}::h79d111f3ae438d15
                               at /home/adema/code/rust/src/librustc_interface/util.rs:152
  80:     0x7f59a534cffd - scoped_tls::ScopedKey<T>::set::h1cf2eba532202ed5
                               at /home/adema/.cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
  81:     0x7f59a534cffd - rustc_interface::util::spawn_thread_pool::{{closure}}::{{closure}}::hb845af3cf404145b
                               at /home/adema/code/rust/src/librustc_interface/util.rs:148
  82:     0x7f59a534cffd - scoped_tls::ScopedKey<T>::set::ha94ad89e21750bf4
                               at /home/adema/.cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
  83:     0x7f59a534cffd - rustc_ast::attr::with_globals::{{closure}}::h925ca335cf988b3a
                               at /home/adema/code/rust/src/librustc_ast/attr/mod.rs:44
  84:     0x7f59a534cffd - scoped_tls::ScopedKey<T>::set::h370e4876e5998364
                               at /home/adema/.cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
  85:     0x7f59a5349d04 - rustc_ast::attr::with_globals::h2d1de10aeff62ecf
                               at /home/adema/code/rust/src/librustc_ast/attr/mod.rs:44
  86:     0x7f59a5355f64 - rustc_interface::util::spawn_thread_pool::{{closure}}::h0f507ae6322d57b0
                               at /home/adema/code/rust/src/librustc_interface/util.rs:147
  87:     0x7f59a5355f64 - rustc_interface::util::scoped_thread::{{closure}}::h37f638b7f6de2a83
                               at /home/adema/code/rust/src/librustc_interface/util.rs:122
  88:     0x7f59a5355f64 - std::sys_common::backtrace::__rust_begin_short_backtrace::hda4d986712102604
                               at /home/adema/code/rust/src/libstd/sys_common/backtrace.rs:130
  89:     0x7f59a4c40954 - std::panicking::try::do_try::hed7a629852400b5f
                               at src/libstd/panicking.rs:298
  90:     0x7f59a549b0fd - std::panicking::try::ha4e540c03fa2d4c0
                               at /home/adema/code/rust/src/libstd/panicking.rs:274
  91:     0x7f59a549b0fd - std::panic::catch_unwind::h99519e6c997fe112
                               at /home/adema/code/rust/src/libstd/panic.rs:394
  92:     0x7f59a549b0fd - std::thread::Builder::spawn_unchecked::{{closure}}::hc2d0ac9187f1dd6d
                               at /home/adema/code/rust/src/libstd/thread/mod.rs:474
  93:     0x7f59a549b0fd - core::ops::function::FnOnce::call_once{{vtable.shim}}::h86e0f7111ce1cb62
                               at /home/adema/code/rust/src/libcore/ops/function.rs:232
  94:     0x7f59a4c6040f - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h7d8c0ce9bb9a9a7b
                               at /home/adema/code/rust/src/liballoc/boxed.rs:1008
  95:     0x7f59a4c48b23 - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::hfcf1edc22130327f
                               at /home/adema/code/rust/src/liballoc/boxed.rs:1008
  96:     0x7f59a4c48b23 - std::sys::unix::thread::Thread::new::thread_start::he3bd71071b1a178e
                               at src/libstd/sys/unix/thread.rs:87
  97:     0x7f59a49e6f27 - start_thread
                               at /builddir/glibc-2.30/nptl/pthread_create.c:479
  98:     0x7f59a4b00e0f - __GI___clone
                               at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
  99:                0x0 - <unknown>
@jonas-schievink jonas-schievink added A-HIR Area: The high-level intermediate representation (HIR) A-type-system Area: Type system T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 13, 2020
@marmeladema marmeladema changed the title [DRAFT] Some LocalDefId don't have a corresponding HirId [DRAFT] Some NodeId/LocalDefId don't have a corresponding HirId Apr 13, 2020
marmeladema added a commit to marmeladema/rust that referenced this issue Apr 14, 2020
…able

Some helpers functions have been introduced to deal with (buggy) cases
where either a `NodeId` or a `DefId` do not have a corresponding `HirId`.
Those cases are tracked in issue rust-lang#71104.
Centril added a commit to Centril/rust that referenced this issue Apr 15, 2020
…=eddyb

Entirely remove `DUMMY_HIR_ID`

Some helpers functions have been introduced to deal with (buggy) cases
where either a `NodeId` or a `DefId` do not have a corresponding `HirId`.
Those cases are tracked in issue rust-lang#71104.
Centril added a commit to Centril/rust that referenced this issue Apr 15, 2020
…=eddyb

Entirely remove `DUMMY_HIR_ID`

Some helpers functions have been introduced to deal with (buggy) cases
where either a `NodeId` or a `DefId` do not have a corresponding `HirId`.
Those cases are tracked in issue rust-lang#71104.
@marmeladema marmeladema changed the title [DRAFT] Some NodeId/LocalDefId don't have a corresponding HirId Some NodeId/LocalDefId don't have a corresponding HirId Apr 16, 2020
marmeladema added a commit to marmeladema/rust that referenced this issue May 3, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 13, 2020
Use `LocalDefId` in `DumpVisitor::nest_tables`

This is a partial fix for rust-lang#71104
RalfJung added a commit to RalfJung/rust that referenced this issue May 14, 2020
Use `LocalDefId` in `DumpVisitor::nest_tables`

This is a partial fix for rust-lang#71104
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 14, 2020
Use `LocalDefId` in `DumpVisitor::nest_tables`

This is a partial fix for rust-lang#71104
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 14, 2020
Use `LocalDefId` in `DumpVisitor::nest_tables`

This is a partial fix for rust-lang#71104
marmeladema added a commit to marmeladema/rust that referenced this issue May 16, 2020
…g an error.

This way the hir is "valid" and we can remove one more call to
`opt_node_id_to_hir_id` but an error is still emitted.

This is another partial fix for rust-lang#71104
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 20, 2020
…static-morse

Continue lowering for unsupported async generator instead of returning an error.

This way the hir is "valid" and we can remove one more call to
`opt_node_id_to_hir_id` but an error is still emitted.

This is another partial fix for rust-lang#71104

r? @eddyb
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 20, 2020
…static-morse

Continue lowering for unsupported async generator instead of returning an error.

This way the hir is "valid" and we can remove one more call to
`opt_node_id_to_hir_id` but an error is still emitted.

This is another partial fix for rust-lang#71104

r? @eddyb
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 20, 2020
…static-morse

Continue lowering for unsupported async generator instead of returning an error.

This way the hir is "valid" and we can remove one more call to
`opt_node_id_to_hir_id` but an error is still emitted.

This is another partial fix for rust-lang#71104

r? @eddyb
Manishearth added a commit to Manishearth/rust that referenced this issue Jun 16, 2020
…op, r=pnkfelix

Preserve `Expr`s that have `DefId`s in `ReplaceBodyWithLoop`

This PR fixes rust-lang#71820 as well as the last part of rust-lang#71104 by preserving expressions that are assigned their own `DefId`s (closures and `async` blocks) when passing them to `rustdoc`. This avoids having a `DefId` without a corresponding `HirId`.

The first commit in this PR makes `-Zunpretty=everybody_loops` actually work again, and the subsequent two are miscellaneous cleanup. They should probably get merged regardless of what we end up doing here.

Sample input:
```rust
fn foo() -> Box<i32> {
    let x = |a: i64| {
        const FOO: i64 = 1;
    };

    let a = 4;
    Box::new(a)
}
```

Sample output:
```rust
fn foo() -> Box<i32> {
    || -> !
        {
            const FOO: i64 = 1;
            loop  { }
        };
    loop  { }
}
```

r? @ghost
Manishearth added a commit to Manishearth/rust that referenced this issue Jun 16, 2020
…op, r=pnkfelix

Preserve `Expr`s that have `DefId`s in `ReplaceBodyWithLoop`

This PR fixes rust-lang#71820 as well as the last part of rust-lang#71104 by preserving expressions that are assigned their own `DefId`s (closures and `async` blocks) when passing them to `rustdoc`. This avoids having a `DefId` without a corresponding `HirId`.

The first commit in this PR makes `-Zunpretty=everybody_loops` actually work again, and the subsequent two are miscellaneous cleanup. They should probably get merged regardless of what we end up doing here.

Sample input:
```rust
fn foo() -> Box<i32> {
    let x = |a: i64| {
        const FOO: i64 = 1;
    };

    let a = 4;
    Box::new(a)
}
```

Sample output:
```rust
fn foo() -> Box<i32> {
    || -> !
        {
            const FOO: i64 = 1;
            loop  { }
        };
    loop  { }
}
```

r? @ghost
Manishearth added a commit to Manishearth/rust that referenced this issue Jun 16, 2020
…op, r=pnkfelix

Preserve `Expr`s that have `DefId`s in `ReplaceBodyWithLoop`

This PR fixes rust-lang#71820 as well as the last part of rust-lang#71104 by preserving expressions that are assigned their own `DefId`s (closures and `async` blocks) when passing them to `rustdoc`. This avoids having a `DefId` without a corresponding `HirId`.

The first commit in this PR makes `-Zunpretty=everybody_loops` actually work again, and the subsequent two are miscellaneous cleanup. They should probably get merged regardless of what we end up doing here.

Sample input:
```rust
fn foo() -> Box<i32> {
    let x = |a: i64| {
        const FOO: i64 = 1;
    };

    let a = 4;
    Box::new(a)
}
```

Sample output:
```rust
fn foo() -> Box<i32> {
    || -> !
        {
            const FOO: i64 = 1;
            loop  { }
        };
    loop  { }
}
```

r? @ghost
@jyn514
Copy link
Member

jyn514 commented Jun 29, 2020

Some more context:

@Dylan-DPC-zz Dylan-DPC-zz added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jun 29, 2020
@Dylan-DPC-zz
Copy link

marking it for prioritization based on last comment.

@Dylan-DPC-zz Dylan-DPC-zz added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jun 30, 2020
@Dylan-DPC-zz
Copy link

Marked as p-high based on the discussion here

Manishearth added a commit to Manishearth/rust that referenced this issue Jul 16, 2020
Don't run `everybody_loops` for rustdoc; instead ignore resolution errors

r? @eddyb
cc @petrochenkov, @GuillaumeGomez, @Manishearth, @ecstatic-morse, @marmeladema

~~Blocked on rust-lang#73743 Merged.
~~Blocked on crater run.~~ Crater popped up some ICEs ([now fixed](rust-lang#73566 (comment))). See [crater run](https://crater-reports.s3.amazonaws.com/pr-73566/index.html), [ICEs](rust-lang#73566 (comment)).
~~Blocked on rust-lang#74070 so that we don't make typeck_tables_of public when it shouldn't be.~~ Merged.

Closes rust-lang#71820, closes rust-lang#71104, closes rust-lang#65863.

## What is the motivation for this change?

As seen from a lengthy trail of PRs and issues (rust-lang#73532, rust-lang#73103, rust-lang#71820, rust-lang#71104), `everybody_loops` is causing bugs in rustdoc. The main issue is that it does not preserve the validity of the `DefId` tree, meaning that operations on DefIds may unexpectedly fail when called later. This is blocking intra-doc links (see rust-lang#73101).

This PR starts by removing `everybody_loops`, fixing rust-lang#71104 and rust-lang#71820. However, that brings back the bugs seen originally in rust-lang#43348: Since libstd documents items for all platforms, the function bodies sometimes do not type check. Here are the errors from documenting `libstd` with `everybody_loops` disabled and no other changes:

```rust
error[E0433]: failed to resolve: could not find `handle` in `sys`
  --> src/libstd/sys/windows/ext/process.rs:13:27
   |
13 |         let handle = sys::handle::Handle::new(handle as *mut _);
   |                           ^^^^^^ could not find `handle` in `sys`

error[E0425]: cannot find function `symlink_inner` in module `sys::fs`
   --> src/libstd/sys/windows/ext/fs.rs:544:14
    |
544 |     sys::fs::symlink_inner(src.as_ref(), dst.as_ref(), false)
    |              ^^^^^^^^^^^^^ not found in `sys::fs`

error[E0425]: cannot find function `symlink_inner` in module `sys::fs`
   --> src/libstd/sys/windows/ext/fs.rs:564:14
    |
564 |     sys::fs::symlink_inner(src.as_ref(), dst.as_ref(), true)
    |              ^^^^^^^^^^^^^ not found in `sys::fs`
```

## Why does this need changes to `rustc_resolve`?

Normally, this could be avoided by simply not calling the `typeck_item_bodies` pass. However, the errors above happen before type checking, in name resolution itself. Since name resolution is intermingled with macro expansion, and rustdoc needs expansion to happen before it knows all items to be documented, there needs to be someway to ignore _resolution_ errors in function bodies.

An alternative solution suggested by @petrochenkov was to not run `everybody_loops` on anything containing a nested `DefId`. This would solve some of the immediate issues, but isn't bullet-proof: the following functions still could not be documented if the items in the body failed to resolve:

- Functions containing a nested `DefId` (rust-lang#71104)
- ~~Functions returning `impl Trait` (rust-lang#43878 These ended up not resolving anyway with this PR.
- ~~`const fn`, because `loop {}` in `const fn` is unstable (rust-lang#43636 `const_loop` was just stabilized.

This also isn't exactly what rustdoc wants, which is to avoid looking at function bodies in the first place.

## What changes were made?

The hack implemented in this PR is to add an option to ignore all resolution errors in function bodies. This is enabled only for rustdoc. Since resolution errors are ignored, the MIR generated will be invalid, as can be seen in the following ICE:

```rust
error: internal compiler error: broken MIR in DefId(0:11 ~ doc_cfg[8787]::uses_target_feature[0]) ("return type"): bad type [type error]
  --> /home/joshua/src/rust/src/test/rustdoc/doc-cfg.rs:51:1
   |
51 | / pub unsafe fn uses_target_feature() {
52 | |     content::should::be::irrelevant();
53 | | }
   | |_^
```

Fortunately, rustdoc does not need to access MIR in order to generate documentation. Therefore this also removes the call to `analyze()` in `rustdoc::run_core`. This has the side effect of not generating all lints by default. Most lints are safe to ignore (does rustdoc really need to run liveness analysis?) but `missing_docs` in particular is disabled when it should not be. Re-running `missing_docs` specifically does not help, because it causes the typechecking pass to be run, bringing back the errors from rust-lang#24658:

```
error[E0599]: no method named `into_handle` found for struct `sys::unix::pipe::AnonPipe` in the current scope
  --> src/libstd/sys/windows/ext/process.rs:71:27
   |
71 |         self.into_inner().into_handle().into_raw() as *mut _
   |                           ^^^^^^^^^^^ method not found in `sys::unix::pipe::AnonPipe`
   |
```

Because of rust-lang#73743, we only run typeck on demand. So this only causes an issue for functions returning `impl Trait`, which were already special cased by `ReplaceFunctionWithBody`. However, it now considers `async fn f() -> T` to be considered `impl Future<Output = T>`, where before it was considered to have a concrete `T` type.

## How will this affect future changes to rustdoc?

- Any new changes to rustdoc will not be able to perform type checking without bringing back resolution errors in function bodies.
    + As a corollary, any new lints cannot require or perform type checking. In some cases this may require refactoring other parts of the compiler to perform type-checking only on-demand, see for example rust-lang#73743.
    + As a corollary, rustdoc can never again call `tcx.analysis()` unless this PR is reverted altogether.

## Current status

- ~~I am not yet sure how to bring back `missing_docs` without running typeck. @eddyb suggested allowing lints to opt-out of type-checking, which would probably be another rabbit hole.~~ The opt-out was implemented in rust-lang#73743. However, of the rustc lints, now _only_ missing_docs is run and no other lints: rust-lang#73566 (comment). We need a team decision on whether that's an acceptable tradeoff. Note that all rustdoc lints are still run (`intra_doc_link_resolution_failure`, etc). **UPDATE**: This was deemed acceptable in rust-lang#73566 (comment)
- ~~The implementation of optional errors in `rustc_resolve` is very brute force, it should probably be moved from `LateResolver` to `Resolver` to avoid duplicating the logic in many places.~~ I'm mostly happy with it now.

- This no longer allows errors in `async fn f() -> T`. This caused breakage in 50 crates out of a full crater run, all of which (that I looked at) didn't compile when run with rustc directly. In other words, it used to be that they could not be compiled but could still be documented; now they can't be documented either. This needs a decision from the rustdoc team on whether this is acceptable breakage. **UPDATE**: This was deemed acceptable in rust-lang#73566 (comment)
- ~~This makes `fn typeck_tables_of` in `rustc_typeck` public. This is not desired behavior, but needs the changes from rust-lang#74070 in order to be fixed.~~ Reverted.
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 16, 2020
Don't run `everybody_loops` for rustdoc; instead ignore resolution errors

r? @eddyb
cc @petrochenkov, @GuillaumeGomez, @Manishearth, @ecstatic-morse, @marmeladema

~~Blocked on rust-lang#73743 Merged.
~~Blocked on crater run.~~ Crater popped up some ICEs ([now fixed](rust-lang#73566 (comment))). See [crater run](https://crater-reports.s3.amazonaws.com/pr-73566/index.html), [ICEs](rust-lang#73566 (comment)).
~~Blocked on rust-lang#74070 so that we don't make typeck_tables_of public when it shouldn't be.~~ Merged.

Closes rust-lang#71820, closes rust-lang#71104, closes rust-lang#65863.

## What is the motivation for this change?

As seen from a lengthy trail of PRs and issues (rust-lang#73532, rust-lang#73103, rust-lang#71820, rust-lang#71104), `everybody_loops` is causing bugs in rustdoc. The main issue is that it does not preserve the validity of the `DefId` tree, meaning that operations on DefIds may unexpectedly fail when called later. This is blocking intra-doc links (see rust-lang#73101).

This PR starts by removing `everybody_loops`, fixing rust-lang#71104 and rust-lang#71820. However, that brings back the bugs seen originally in rust-lang#43348: Since libstd documents items for all platforms, the function bodies sometimes do not type check. Here are the errors from documenting `libstd` with `everybody_loops` disabled and no other changes:

```rust
error[E0433]: failed to resolve: could not find `handle` in `sys`
  --> src/libstd/sys/windows/ext/process.rs:13:27
   |
13 |         let handle = sys::handle::Handle::new(handle as *mut _);
   |                           ^^^^^^ could not find `handle` in `sys`

error[E0425]: cannot find function `symlink_inner` in module `sys::fs`
   --> src/libstd/sys/windows/ext/fs.rs:544:14
    |
544 |     sys::fs::symlink_inner(src.as_ref(), dst.as_ref(), false)
    |              ^^^^^^^^^^^^^ not found in `sys::fs`

error[E0425]: cannot find function `symlink_inner` in module `sys::fs`
   --> src/libstd/sys/windows/ext/fs.rs:564:14
    |
564 |     sys::fs::symlink_inner(src.as_ref(), dst.as_ref(), true)
    |              ^^^^^^^^^^^^^ not found in `sys::fs`
```

## Why does this need changes to `rustc_resolve`?

Normally, this could be avoided by simply not calling the `typeck_item_bodies` pass. However, the errors above happen before type checking, in name resolution itself. Since name resolution is intermingled with macro expansion, and rustdoc needs expansion to happen before it knows all items to be documented, there needs to be someway to ignore _resolution_ errors in function bodies.

An alternative solution suggested by @petrochenkov was to not run `everybody_loops` on anything containing a nested `DefId`. This would solve some of the immediate issues, but isn't bullet-proof: the following functions still could not be documented if the items in the body failed to resolve:

- Functions containing a nested `DefId` (rust-lang#71104)
- ~~Functions returning `impl Trait` (rust-lang#43878 These ended up not resolving anyway with this PR.
- ~~`const fn`, because `loop {}` in `const fn` is unstable (rust-lang#43636 `const_loop` was just stabilized.

This also isn't exactly what rustdoc wants, which is to avoid looking at function bodies in the first place.

## What changes were made?

The hack implemented in this PR is to add an option to ignore all resolution errors in function bodies. This is enabled only for rustdoc. Since resolution errors are ignored, the MIR generated will be invalid, as can be seen in the following ICE:

```rust
error: internal compiler error: broken MIR in DefId(0:11 ~ doc_cfg[8787]::uses_target_feature[0]) ("return type"): bad type [type error]
  --> /home/joshua/src/rust/src/test/rustdoc/doc-cfg.rs:51:1
   |
51 | / pub unsafe fn uses_target_feature() {
52 | |     content::should::be::irrelevant();
53 | | }
   | |_^
```

Fortunately, rustdoc does not need to access MIR in order to generate documentation. Therefore this also removes the call to `analyze()` in `rustdoc::run_core`. This has the side effect of not generating all lints by default. Most lints are safe to ignore (does rustdoc really need to run liveness analysis?) but `missing_docs` in particular is disabled when it should not be. Re-running `missing_docs` specifically does not help, because it causes the typechecking pass to be run, bringing back the errors from rust-lang#24658:

```
error[E0599]: no method named `into_handle` found for struct `sys::unix::pipe::AnonPipe` in the current scope
  --> src/libstd/sys/windows/ext/process.rs:71:27
   |
71 |         self.into_inner().into_handle().into_raw() as *mut _
   |                           ^^^^^^^^^^^ method not found in `sys::unix::pipe::AnonPipe`
   |
```

Because of rust-lang#73743, we only run typeck on demand. So this only causes an issue for functions returning `impl Trait`, which were already special cased by `ReplaceFunctionWithBody`. However, it now considers `async fn f() -> T` to be considered `impl Future<Output = T>`, where before it was considered to have a concrete `T` type.

## How will this affect future changes to rustdoc?

- Any new changes to rustdoc will not be able to perform type checking without bringing back resolution errors in function bodies.
    + As a corollary, any new lints cannot require or perform type checking. In some cases this may require refactoring other parts of the compiler to perform type-checking only on-demand, see for example rust-lang#73743.
    + As a corollary, rustdoc can never again call `tcx.analysis()` unless this PR is reverted altogether.

## Current status

- ~~I am not yet sure how to bring back `missing_docs` without running typeck. @eddyb suggested allowing lints to opt-out of type-checking, which would probably be another rabbit hole.~~ The opt-out was implemented in rust-lang#73743. However, of the rustc lints, now _only_ missing_docs is run and no other lints: rust-lang#73566 (comment). We need a team decision on whether that's an acceptable tradeoff. Note that all rustdoc lints are still run (`intra_doc_link_resolution_failure`, etc). **UPDATE**: This was deemed acceptable in rust-lang#73566 (comment)
- ~~The implementation of optional errors in `rustc_resolve` is very brute force, it should probably be moved from `LateResolver` to `Resolver` to avoid duplicating the logic in many places.~~ I'm mostly happy with it now.

- This no longer allows errors in `async fn f() -> T`. This caused breakage in 50 crates out of a full crater run, all of which (that I looked at) didn't compile when run with rustc directly. In other words, it used to be that they could not be compiled but could still be documented; now they can't be documented either. This needs a decision from the rustdoc team on whether this is acceptable breakage. **UPDATE**: This was deemed acceptable in rust-lang#73566 (comment)
- ~~This makes `fn typeck_tables_of` in `rustc_typeck` public. This is not desired behavior, but needs the changes from rust-lang#74070 in order to be fixed.~~ Reverted.
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 16, 2020
Don't run `everybody_loops` for rustdoc; instead ignore resolution errors

r? @eddyb
cc @petrochenkov, @GuillaumeGomez, @Manishearth, @ecstatic-morse, @marmeladema

~~Blocked on rust-lang#73743 Merged.
~~Blocked on crater run.~~ Crater popped up some ICEs ([now fixed](rust-lang#73566 (comment))). See [crater run](https://crater-reports.s3.amazonaws.com/pr-73566/index.html), [ICEs](rust-lang#73566 (comment)).
~~Blocked on rust-lang#74070 so that we don't make typeck_tables_of public when it shouldn't be.~~ Merged.

Closes rust-lang#71820, closes rust-lang#71104, closes rust-lang#65863.

## What is the motivation for this change?

As seen from a lengthy trail of PRs and issues (rust-lang#73532, rust-lang#73103, rust-lang#71820, rust-lang#71104), `everybody_loops` is causing bugs in rustdoc. The main issue is that it does not preserve the validity of the `DefId` tree, meaning that operations on DefIds may unexpectedly fail when called later. This is blocking intra-doc links (see rust-lang#73101).

This PR starts by removing `everybody_loops`, fixing rust-lang#71104 and rust-lang#71820. However, that brings back the bugs seen originally in rust-lang#43348: Since libstd documents items for all platforms, the function bodies sometimes do not type check. Here are the errors from documenting `libstd` with `everybody_loops` disabled and no other changes:

```rust
error[E0433]: failed to resolve: could not find `handle` in `sys`
  --> src/libstd/sys/windows/ext/process.rs:13:27
   |
13 |         let handle = sys::handle::Handle::new(handle as *mut _);
   |                           ^^^^^^ could not find `handle` in `sys`

error[E0425]: cannot find function `symlink_inner` in module `sys::fs`
   --> src/libstd/sys/windows/ext/fs.rs:544:14
    |
544 |     sys::fs::symlink_inner(src.as_ref(), dst.as_ref(), false)
    |              ^^^^^^^^^^^^^ not found in `sys::fs`

error[E0425]: cannot find function `symlink_inner` in module `sys::fs`
   --> src/libstd/sys/windows/ext/fs.rs:564:14
    |
564 |     sys::fs::symlink_inner(src.as_ref(), dst.as_ref(), true)
    |              ^^^^^^^^^^^^^ not found in `sys::fs`
```

## Why does this need changes to `rustc_resolve`?

Normally, this could be avoided by simply not calling the `typeck_item_bodies` pass. However, the errors above happen before type checking, in name resolution itself. Since name resolution is intermingled with macro expansion, and rustdoc needs expansion to happen before it knows all items to be documented, there needs to be someway to ignore _resolution_ errors in function bodies.

An alternative solution suggested by @petrochenkov was to not run `everybody_loops` on anything containing a nested `DefId`. This would solve some of the immediate issues, but isn't bullet-proof: the following functions still could not be documented if the items in the body failed to resolve:

- Functions containing a nested `DefId` (rust-lang#71104)
- ~~Functions returning `impl Trait` (rust-lang#43878 These ended up not resolving anyway with this PR.
- ~~`const fn`, because `loop {}` in `const fn` is unstable (rust-lang#43636 `const_loop` was just stabilized.

This also isn't exactly what rustdoc wants, which is to avoid looking at function bodies in the first place.

## What changes were made?

The hack implemented in this PR is to add an option to ignore all resolution errors in function bodies. This is enabled only for rustdoc. Since resolution errors are ignored, the MIR generated will be invalid, as can be seen in the following ICE:

```rust
error: internal compiler error: broken MIR in DefId(0:11 ~ doc_cfg[8787]::uses_target_feature[0]) ("return type"): bad type [type error]
  --> /home/joshua/src/rust/src/test/rustdoc/doc-cfg.rs:51:1
   |
51 | / pub unsafe fn uses_target_feature() {
52 | |     content::should::be::irrelevant();
53 | | }
   | |_^
```

Fortunately, rustdoc does not need to access MIR in order to generate documentation. Therefore this also removes the call to `analyze()` in `rustdoc::run_core`. This has the side effect of not generating all lints by default. Most lints are safe to ignore (does rustdoc really need to run liveness analysis?) but `missing_docs` in particular is disabled when it should not be. Re-running `missing_docs` specifically does not help, because it causes the typechecking pass to be run, bringing back the errors from rust-lang#24658:

```
error[E0599]: no method named `into_handle` found for struct `sys::unix::pipe::AnonPipe` in the current scope
  --> src/libstd/sys/windows/ext/process.rs:71:27
   |
71 |         self.into_inner().into_handle().into_raw() as *mut _
   |                           ^^^^^^^^^^^ method not found in `sys::unix::pipe::AnonPipe`
   |
```

Because of rust-lang#73743, we only run typeck on demand. So this only causes an issue for functions returning `impl Trait`, which were already special cased by `ReplaceFunctionWithBody`. However, it now considers `async fn f() -> T` to be considered `impl Future<Output = T>`, where before it was considered to have a concrete `T` type.

## How will this affect future changes to rustdoc?

- Any new changes to rustdoc will not be able to perform type checking without bringing back resolution errors in function bodies.
    + As a corollary, any new lints cannot require or perform type checking. In some cases this may require refactoring other parts of the compiler to perform type-checking only on-demand, see for example rust-lang#73743.
    + As a corollary, rustdoc can never again call `tcx.analysis()` unless this PR is reverted altogether.

## Current status

- ~~I am not yet sure how to bring back `missing_docs` without running typeck. @eddyb suggested allowing lints to opt-out of type-checking, which would probably be another rabbit hole.~~ The opt-out was implemented in rust-lang#73743. However, of the rustc lints, now _only_ missing_docs is run and no other lints: rust-lang#73566 (comment). We need a team decision on whether that's an acceptable tradeoff. Note that all rustdoc lints are still run (`intra_doc_link_resolution_failure`, etc). **UPDATE**: This was deemed acceptable in rust-lang#73566 (comment)
- ~~The implementation of optional errors in `rustc_resolve` is very brute force, it should probably be moved from `LateResolver` to `Resolver` to avoid duplicating the logic in many places.~~ I'm mostly happy with it now.

- This no longer allows errors in `async fn f() -> T`. This caused breakage in 50 crates out of a full crater run, all of which (that I looked at) didn't compile when run with rustc directly. In other words, it used to be that they could not be compiled but could still be documented; now they can't be documented either. This needs a decision from the rustdoc team on whether this is acceptable breakage. **UPDATE**: This was deemed acceptable in rust-lang#73566 (comment)
- ~~This makes `fn typeck_tables_of` in `rustc_typeck` public. This is not desired behavior, but needs the changes from rust-lang#74070 in order to be fixed.~~ Reverted.
@bors bors closed this as completed in c23f045 Jul 16, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Dec 28, 2020
Remove FIXME in rustc_privacy

rust-lang#71104 has been fixed.

r? `@marmeladema` if you have time, otherwise `@petrochenkov`
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Dec 28, 2020
Remove FIXME in rustc_privacy

rust-lang#71104 has been fixed.

r? ``@marmeladema`` if you have time, otherwise ``@petrochenkov``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-HIR Area: The high-level intermediate representation (HIR) A-type-system Area: Type system P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
6 participants