Description
Lang items are collected on HIR in rustc_passes::lang_items
.
However, AST -> HIR lowering may need to know of some lang items, for instance for loops of async desugaring.
Having lang items ready before lowering may simplify those code paths.
This requires re-implementing lang item collection on AST instead of HIR.
The simplest way is to make rustc_passes::lang_items::LanguageItemCollector
a rustc_ast::Visitor
, and have get_lang_items
use it to visit the full crate. The AST is accessible using the second field of tcx.resolver_for_lowering(()).borrow()
.
A statement tcx.ensure_with_value().get_lang_items(LOCAL_CRATE)
needs to be added at the top of rustc_ast_lowering::lower_to_hir
to ensure that the computation is done before dropping the AST.
Once that is done, hir::QPath::LangItem
and hir::GenericBound::LangItemTrait
variants can be removed from HIR, replaced by actual resolutions of the lang items. (For particular cases, see how those variants are constructed and used.)
Please contact me on zulip for any question.
Activity