Use Arena inside hir::Crate.
This commit is contained in:
parent
fc5deca214
commit
4dc79f1f7d
22 changed files with 109 additions and 97 deletions
|
@ -93,7 +93,6 @@ macro_rules! arena_types {
|
||||||
rustc::hir::def_id::CrateNum
|
rustc::hir::def_id::CrateNum
|
||||||
>
|
>
|
||||||
>,
|
>,
|
||||||
[few] hir_forest: rustc::hir::map::Forest,
|
|
||||||
[few] diagnostic_items: rustc_data_structures::fx::FxHashMap<
|
[few] diagnostic_items: rustc_data_structures::fx::FxHashMap<
|
||||||
syntax::symbol::Symbol,
|
syntax::symbol::Symbol,
|
||||||
rustc::hir::def_id::DefId,
|
rustc::hir::def_id::DefId,
|
||||||
|
@ -123,6 +122,10 @@ macro_rules! arena_types {
|
||||||
[few] crate_variances: rustc::ty::CrateVariancesMap<'tcx>,
|
[few] crate_variances: rustc::ty::CrateVariancesMap<'tcx>,
|
||||||
[few] inferred_outlives_crate: rustc::ty::CratePredicatesMap<'tcx>,
|
[few] inferred_outlives_crate: rustc::ty::CratePredicatesMap<'tcx>,
|
||||||
[] upvars: rustc_data_structures::fx::FxIndexMap<rustc::hir::HirId, rustc::hir::Upvar>,
|
[] upvars: rustc_data_structures::fx::FxIndexMap<rustc::hir::HirId, rustc::hir::Upvar>,
|
||||||
|
// HIR nodes arenas
|
||||||
|
[few] hir_forest: rustc::hir::map::Forest<$tcx>,
|
||||||
|
[] attribute: syntax::ast::Attribute,
|
||||||
|
[] macro_def: rustc::hir::MacroDef,
|
||||||
], $tcx);
|
], $tcx);
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -382,10 +382,10 @@ pub trait Visitor<'v>: Sized {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Walks the contents of a crate. See also `Crate::visit_all_items`.
|
/// Walks the contents of a crate. See also `Crate::visit_all_items`.
|
||||||
pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate) {
|
pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate<'v>) {
|
||||||
visitor.visit_mod(&krate.module, krate.span, CRATE_HIR_ID);
|
visitor.visit_mod(&krate.module, krate.span, CRATE_HIR_ID);
|
||||||
walk_list!(visitor, visit_attribute, &krate.attrs);
|
walk_list!(visitor, visit_attribute, krate.attrs);
|
||||||
walk_list!(visitor, visit_macro_def, &krate.exported_macros);
|
walk_list!(visitor, visit_macro_def, krate.exported_macros);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_macro_def<'v, V: Visitor<'v>>(visitor: &mut V, macro_def: &'v MacroDef) {
|
pub fn walk_macro_def<'v, V: Visitor<'v>>(visitor: &mut V, macro_def: &'v MacroDef) {
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
mod expr;
|
mod expr;
|
||||||
mod item;
|
mod item;
|
||||||
|
|
||||||
|
use crate::arena::Arena;
|
||||||
use crate::dep_graph::DepGraph;
|
use crate::dep_graph::DepGraph;
|
||||||
use crate::hir::{self, ParamName};
|
use crate::hir::{self, ParamName};
|
||||||
use crate::hir::HirVec;
|
use crate::hir::HirVec;
|
||||||
|
@ -77,7 +78,7 @@ use rustc_error_codes::*;
|
||||||
|
|
||||||
const HIR_ID_COUNTER_LOCKED: u32 = 0xFFFFFFFF;
|
const HIR_ID_COUNTER_LOCKED: u32 = 0xFFFFFFFF;
|
||||||
|
|
||||||
pub struct LoweringContext<'a> {
|
pub struct LoweringContext<'a, 'hir: 'a> {
|
||||||
crate_root: Option<Symbol>,
|
crate_root: Option<Symbol>,
|
||||||
|
|
||||||
/// Used to assign IDs to HIR nodes that do not directly correspond to AST nodes.
|
/// Used to assign IDs to HIR nodes that do not directly correspond to AST nodes.
|
||||||
|
@ -90,6 +91,9 @@ pub struct LoweringContext<'a> {
|
||||||
/// librustc is independent of the parser, we use dynamic dispatch here.
|
/// librustc is independent of the parser, we use dynamic dispatch here.
|
||||||
nt_to_tokenstream: NtToTokenstream,
|
nt_to_tokenstream: NtToTokenstream,
|
||||||
|
|
||||||
|
/// Used to allocate HIR nodes
|
||||||
|
arena: &'hir Arena<'hir>,
|
||||||
|
|
||||||
/// The items being lowered are collected here.
|
/// The items being lowered are collected here.
|
||||||
items: BTreeMap<hir::HirId, hir::Item>,
|
items: BTreeMap<hir::HirId, hir::Item>,
|
||||||
|
|
||||||
|
@ -240,13 +244,14 @@ impl<'a> ImplTraitContext<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lower_crate(
|
pub fn lower_crate<'a, 'hir>(
|
||||||
sess: &Session,
|
sess: &'a Session,
|
||||||
dep_graph: &DepGraph,
|
dep_graph: &'a DepGraph,
|
||||||
krate: &Crate,
|
krate: &'a Crate,
|
||||||
resolver: &mut dyn Resolver,
|
resolver: &'a mut dyn Resolver,
|
||||||
nt_to_tokenstream: NtToTokenstream,
|
nt_to_tokenstream: NtToTokenstream,
|
||||||
) -> hir::Crate {
|
arena: &'hir Arena<'hir>,
|
||||||
|
) -> hir::Crate<'hir> {
|
||||||
// We're constructing the HIR here; we don't care what we will
|
// We're constructing the HIR here; we don't care what we will
|
||||||
// read, since we haven't even constructed the *input* to
|
// read, since we haven't even constructed the *input* to
|
||||||
// incr. comp. yet.
|
// incr. comp. yet.
|
||||||
|
@ -259,6 +264,7 @@ pub fn lower_crate(
|
||||||
sess,
|
sess,
|
||||||
resolver,
|
resolver,
|
||||||
nt_to_tokenstream,
|
nt_to_tokenstream,
|
||||||
|
arena,
|
||||||
items: BTreeMap::new(),
|
items: BTreeMap::new(),
|
||||||
trait_items: BTreeMap::new(),
|
trait_items: BTreeMap::new(),
|
||||||
impl_items: BTreeMap::new(),
|
impl_items: BTreeMap::new(),
|
||||||
|
@ -382,19 +388,19 @@ impl<'a, 'b> Visitor<'a> for ImplTraitTypeIdVisitor<'b> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> LoweringContext<'a> {
|
impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
fn lower_crate(mut self, c: &Crate) -> hir::Crate {
|
fn lower_crate(mut self, c: &Crate) -> hir::Crate<'hir> {
|
||||||
/// Full-crate AST visitor that inserts into a fresh
|
/// Full-crate AST visitor that inserts into a fresh
|
||||||
/// `LoweringContext` any information that may be
|
/// `LoweringContext` any information that may be
|
||||||
/// needed from arbitrary locations in the crate,
|
/// needed from arbitrary locations in the crate,
|
||||||
/// e.g., the number of lifetime generic parameters
|
/// e.g., the number of lifetime generic parameters
|
||||||
/// declared for every type and trait definition.
|
/// declared for every type and trait definition.
|
||||||
struct MiscCollector<'tcx, 'interner> {
|
struct MiscCollector<'tcx, 'lowering, 'hir> {
|
||||||
lctx: &'tcx mut LoweringContext<'interner>,
|
lctx: &'tcx mut LoweringContext<'lowering, 'hir>,
|
||||||
hir_id_owner: Option<NodeId>,
|
hir_id_owner: Option<NodeId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MiscCollector<'_, '_> {
|
impl MiscCollector<'_, '_, '_> {
|
||||||
fn allocate_use_tree_hir_id_counters(
|
fn allocate_use_tree_hir_id_counters(
|
||||||
&mut self,
|
&mut self,
|
||||||
tree: &UseTree,
|
tree: &UseTree,
|
||||||
|
@ -434,7 +440,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx, 'interner> Visitor<'tcx> for MiscCollector<'tcx, 'interner> {
|
impl<'tcx, 'lowering, 'hir> Visitor<'tcx> for MiscCollector<'tcx, 'lowering, 'hir> {
|
||||||
fn visit_pat(&mut self, p: &'tcx Pat) {
|
fn visit_pat(&mut self, p: &'tcx Pat) {
|
||||||
if let PatKind::Paren(..) | PatKind::Rest = p.kind {
|
if let PatKind::Paren(..) | PatKind::Rest = p.kind {
|
||||||
// Doesn't generate a HIR node
|
// Doesn't generate a HIR node
|
||||||
|
@ -537,7 +543,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
visit::walk_crate(&mut item::ItemLowerer { lctx: &mut self }, c);
|
visit::walk_crate(&mut item::ItemLowerer { lctx: &mut self }, c);
|
||||||
|
|
||||||
let module = self.lower_mod(&c.module);
|
let module = self.lower_mod(&c.module);
|
||||||
let attrs = self.lower_attrs(&c.attrs);
|
let attrs = self.arena.alloc_from_iter(self.lower_attrs(&c.attrs).into_iter());
|
||||||
let body_ids = body_ids(&self.bodies);
|
let body_ids = body_ids(&self.bodies);
|
||||||
|
|
||||||
self.resolver
|
self.resolver
|
||||||
|
@ -548,8 +554,8 @@ impl<'a> LoweringContext<'a> {
|
||||||
module,
|
module,
|
||||||
attrs,
|
attrs,
|
||||||
span: c.span,
|
span: c.span,
|
||||||
exported_macros: hir::HirVec::from(self.exported_macros),
|
exported_macros: self.arena.alloc_from_iter(self.exported_macros),
|
||||||
non_exported_macro_attrs: hir::HirVec::from(self.non_exported_macro_attrs),
|
non_exported_macro_attrs: self.arena.alloc_from_iter(self.non_exported_macro_attrs),
|
||||||
items: self.items,
|
items: self.items,
|
||||||
trait_items: self.trait_items,
|
trait_items: self.trait_items,
|
||||||
impl_items: self.impl_items,
|
impl_items: self.impl_items,
|
||||||
|
@ -750,7 +756,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
f: F,
|
f: F,
|
||||||
) -> (Vec<hir::GenericParam>, T)
|
) -> (Vec<hir::GenericParam>, T)
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut LoweringContext<'_>) -> (Vec<hir::GenericParam>, T),
|
F: FnOnce(&mut LoweringContext<'_, '_>) -> (Vec<hir::GenericParam>, T),
|
||||||
{
|
{
|
||||||
assert!(!self.is_collecting_in_band_lifetimes);
|
assert!(!self.is_collecting_in_band_lifetimes);
|
||||||
assert!(self.lifetimes_to_define.is_empty());
|
assert!(self.lifetimes_to_define.is_empty());
|
||||||
|
@ -867,7 +873,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
// for them.
|
// for them.
|
||||||
fn with_in_scope_lifetime_defs<T, F>(&mut self, params: &[GenericParam], f: F) -> T
|
fn with_in_scope_lifetime_defs<T, F>(&mut self, params: &[GenericParam], f: F) -> T
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut LoweringContext<'_>) -> T,
|
F: FnOnce(&mut LoweringContext<'_, '_>) -> T,
|
||||||
{
|
{
|
||||||
let old_len = self.in_scope_lifetimes.len();
|
let old_len = self.in_scope_lifetimes.len();
|
||||||
let lt_def_names = params.iter().filter_map(|param| match param.kind {
|
let lt_def_names = params.iter().filter_map(|param| match param.kind {
|
||||||
|
@ -896,7 +902,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
f: F,
|
f: F,
|
||||||
) -> (hir::Generics, T)
|
) -> (hir::Generics, T)
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut LoweringContext<'_>, &mut Vec<hir::GenericParam>) -> T,
|
F: FnOnce(&mut LoweringContext<'_, '_>, &mut Vec<hir::GenericParam>) -> T,
|
||||||
{
|
{
|
||||||
let (in_band_defs, (mut lowered_generics, res)) = self.with_in_scope_lifetime_defs(
|
let (in_band_defs, (mut lowered_generics, res)) = self.with_in_scope_lifetime_defs(
|
||||||
&generics.params,
|
&generics.params,
|
||||||
|
@ -945,7 +951,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
|
|
||||||
fn with_dyn_type_scope<T, F>(&mut self, in_scope: bool, f: F) -> T
|
fn with_dyn_type_scope<T, F>(&mut self, in_scope: bool, f: F) -> T
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut LoweringContext<'_>) -> T,
|
F: FnOnce(&mut LoweringContext<'_, '_>) -> T,
|
||||||
{
|
{
|
||||||
let was_in_dyn_type = self.is_in_dyn_type;
|
let was_in_dyn_type = self.is_in_dyn_type;
|
||||||
self.is_in_dyn_type = in_scope;
|
self.is_in_dyn_type = in_scope;
|
||||||
|
@ -959,7 +965,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
|
|
||||||
fn with_new_scopes<T, F>(&mut self, f: F) -> T
|
fn with_new_scopes<T, F>(&mut self, f: F) -> T
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut LoweringContext<'_>) -> T,
|
F: FnOnce(&mut LoweringContext<'_, '_>) -> T,
|
||||||
{
|
{
|
||||||
let was_in_loop_condition = self.is_in_loop_condition;
|
let was_in_loop_condition = self.is_in_loop_condition;
|
||||||
self.is_in_loop_condition = false;
|
self.is_in_loop_condition = false;
|
||||||
|
@ -1446,7 +1452,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
span: Span,
|
span: Span,
|
||||||
fn_def_id: Option<DefId>,
|
fn_def_id: Option<DefId>,
|
||||||
opaque_ty_node_id: NodeId,
|
opaque_ty_node_id: NodeId,
|
||||||
lower_bounds: impl FnOnce(&mut LoweringContext<'_>) -> hir::GenericBounds,
|
lower_bounds: impl FnOnce(&mut LoweringContext<'_, '_>) -> hir::GenericBounds,
|
||||||
) -> hir::TyKind {
|
) -> hir::TyKind {
|
||||||
debug!(
|
debug!(
|
||||||
"lower_opaque_impl_trait(fn_def_id={:?}, opaque_ty_node_id={:?}, span={:?})",
|
"lower_opaque_impl_trait(fn_def_id={:?}, opaque_ty_node_id={:?}, span={:?})",
|
||||||
|
@ -1563,8 +1569,8 @@ impl<'a> LoweringContext<'a> {
|
||||||
// This visitor walks over `impl Trait` bounds and creates defs for all lifetimes that
|
// This visitor walks over `impl Trait` bounds and creates defs for all lifetimes that
|
||||||
// appear in the bounds, excluding lifetimes that are created within the bounds.
|
// appear in the bounds, excluding lifetimes that are created within the bounds.
|
||||||
// E.g., `'a`, `'b`, but not `'c` in `impl for<'c> SomeTrait<'a, 'b, 'c>`.
|
// E.g., `'a`, `'b`, but not `'c` in `impl for<'c> SomeTrait<'a, 'b, 'c>`.
|
||||||
struct ImplTraitLifetimeCollector<'r, 'a> {
|
struct ImplTraitLifetimeCollector<'r, 'a, 'hir> {
|
||||||
context: &'r mut LoweringContext<'a>,
|
context: &'r mut LoweringContext<'a, 'hir>,
|
||||||
parent: DefIndex,
|
parent: DefIndex,
|
||||||
opaque_ty_id: NodeId,
|
opaque_ty_id: NodeId,
|
||||||
collect_elided_lifetimes: bool,
|
collect_elided_lifetimes: bool,
|
||||||
|
@ -1574,7 +1580,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
output_lifetime_params: Vec<hir::GenericParam>,
|
output_lifetime_params: Vec<hir::GenericParam>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'r, 'a, 'v> hir::intravisit::Visitor<'v> for ImplTraitLifetimeCollector<'r, 'a> {
|
impl<'r, 'a, 'v, 'hir> hir::intravisit::Visitor<'v> for ImplTraitLifetimeCollector<'r, 'a, 'hir> {
|
||||||
fn nested_visit_map<'this>(
|
fn nested_visit_map<'this>(
|
||||||
&'this mut self,
|
&'this mut self,
|
||||||
) -> hir::intravisit::NestedVisitorMap<'this, 'v> {
|
) -> hir::intravisit::NestedVisitorMap<'this, 'v> {
|
||||||
|
@ -2757,8 +2763,9 @@ impl<'a> LoweringContext<'a> {
|
||||||
let node = match p.kind {
|
let node = match p.kind {
|
||||||
PatKind::Wild => hir::PatKind::Wild,
|
PatKind::Wild => hir::PatKind::Wild,
|
||||||
PatKind::Ident(ref binding_mode, ident, ref sub) => {
|
PatKind::Ident(ref binding_mode, ident, ref sub) => {
|
||||||
let lower_sub = |this: &mut Self| sub.as_ref().map(|x| this.lower_pat(x));
|
let lower_sub = |this: &mut Self| sub.as_ref().map(|s| this.lower_pat(&*s));
|
||||||
self.lower_pat_ident(p, binding_mode, ident, lower_sub)
|
let node = self.lower_pat_ident(p, binding_mode, ident, lower_sub);
|
||||||
|
node
|
||||||
}
|
}
|
||||||
PatKind::Lit(ref e) => hir::PatKind::Lit(P(self.lower_expr(e))),
|
PatKind::Lit(ref e) => hir::PatKind::Lit(P(self.lower_expr(e))),
|
||||||
PatKind::TupleStruct(ref path, ref pats) => {
|
PatKind::TupleStruct(ref path, ref pats) => {
|
||||||
|
|
|
@ -13,7 +13,7 @@ use syntax::symbol::{sym, Symbol};
|
||||||
|
|
||||||
use rustc_error_codes::*;
|
use rustc_error_codes::*;
|
||||||
|
|
||||||
impl LoweringContext<'_> {
|
impl LoweringContext<'_, '_> {
|
||||||
fn lower_exprs(&mut self, exprs: &[AstP<Expr>]) -> HirVec<hir::Expr> {
|
fn lower_exprs(&mut self, exprs: &[AstP<Expr>]) -> HirVec<hir::Expr> {
|
||||||
exprs.iter().map(|x| self.lower_expr(x)).collect()
|
exprs.iter().map(|x| self.lower_expr(x)).collect()
|
||||||
}
|
}
|
||||||
|
@ -473,7 +473,7 @@ impl LoweringContext<'_> {
|
||||||
ret_ty: Option<AstP<Ty>>,
|
ret_ty: Option<AstP<Ty>>,
|
||||||
span: Span,
|
span: Span,
|
||||||
async_gen_kind: hir::AsyncGeneratorKind,
|
async_gen_kind: hir::AsyncGeneratorKind,
|
||||||
body: impl FnOnce(&mut LoweringContext<'_>) -> hir::Expr,
|
body: impl FnOnce(&mut LoweringContext<'_, '_>) -> hir::Expr,
|
||||||
) -> hir::ExprKind {
|
) -> hir::ExprKind {
|
||||||
let output = match ret_ty {
|
let output = match ret_ty {
|
||||||
Some(ty) => FunctionRetTy::Ty(ty),
|
Some(ty) => FunctionRetTy::Ty(ty),
|
||||||
|
@ -909,7 +909,7 @@ impl LoweringContext<'_> {
|
||||||
|
|
||||||
fn with_catch_scope<T, F>(&mut self, catch_id: NodeId, f: F) -> T
|
fn with_catch_scope<T, F>(&mut self, catch_id: NodeId, f: F) -> T
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut LoweringContext<'_>) -> T,
|
F: FnOnce(&mut LoweringContext<'_, '_>) -> T,
|
||||||
{
|
{
|
||||||
let len = self.catch_scopes.len();
|
let len = self.catch_scopes.len();
|
||||||
self.catch_scopes.push(catch_id);
|
self.catch_scopes.push(catch_id);
|
||||||
|
@ -928,7 +928,7 @@ impl LoweringContext<'_> {
|
||||||
|
|
||||||
fn with_loop_scope<T, F>(&mut self, loop_id: NodeId, f: F) -> T
|
fn with_loop_scope<T, F>(&mut self, loop_id: NodeId, f: F) -> T
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut LoweringContext<'_>) -> T,
|
F: FnOnce(&mut LoweringContext<'_, '_>) -> T,
|
||||||
{
|
{
|
||||||
// We're no longer in the base loop's condition; we're in another loop.
|
// We're no longer in the base loop's condition; we're in another loop.
|
||||||
let was_in_loop_condition = self.is_in_loop_condition;
|
let was_in_loop_condition = self.is_in_loop_condition;
|
||||||
|
@ -953,7 +953,7 @@ impl LoweringContext<'_> {
|
||||||
|
|
||||||
fn with_loop_condition_scope<T, F>(&mut self, f: F) -> T
|
fn with_loop_condition_scope<T, F>(&mut self, f: F) -> T
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut LoweringContext<'_>) -> T,
|
F: FnOnce(&mut LoweringContext<'_, '_>) -> T,
|
||||||
{
|
{
|
||||||
let was_in_loop_condition = self.is_in_loop_condition;
|
let was_in_loop_condition = self.is_in_loop_condition;
|
||||||
self.is_in_loop_condition = true;
|
self.is_in_loop_condition = true;
|
||||||
|
|
|
@ -24,11 +24,11 @@ use syntax_pos::Span;
|
||||||
|
|
||||||
use rustc_error_codes::*;
|
use rustc_error_codes::*;
|
||||||
|
|
||||||
pub(super) struct ItemLowerer<'tcx, 'interner> {
|
pub(super) struct ItemLowerer<'a, 'lowering, 'hir> {
|
||||||
pub(super) lctx: &'tcx mut LoweringContext<'interner>,
|
pub(super) lctx: &'a mut LoweringContext<'lowering, 'hir>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx, 'interner> ItemLowerer<'tcx, 'interner> {
|
impl<'a, 'lowering, 'hir> ItemLowerer<'a, 'lowering, 'hir> {
|
||||||
fn with_trait_impl_ref<F>(&mut self, trait_impl_ref: &Option<TraitRef>, f: F)
|
fn with_trait_impl_ref<F>(&mut self, trait_impl_ref: &Option<TraitRef>, f: F)
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut Self),
|
F: FnOnce(&mut Self),
|
||||||
|
@ -44,8 +44,8 @@ impl<'tcx, 'interner> ItemLowerer<'tcx, 'interner> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx, 'interner> Visitor<'tcx> for ItemLowerer<'tcx, 'interner> {
|
impl<'a, 'lowering, 'hir> Visitor<'a> for ItemLowerer<'a, 'lowering, 'hir> {
|
||||||
fn visit_mod(&mut self, m: &'tcx Mod, _s: Span, _attrs: &[Attribute], n: NodeId) {
|
fn visit_mod(&mut self, m: &'a Mod, _s: Span, _attrs: &[Attribute], n: NodeId) {
|
||||||
let hir_id = self.lctx.lower_node_id(n);
|
let hir_id = self.lctx.lower_node_id(n);
|
||||||
|
|
||||||
self.lctx.modules.insert(hir_id, hir::ModuleItems {
|
self.lctx.modules.insert(hir_id, hir::ModuleItems {
|
||||||
|
@ -60,7 +60,7 @@ impl<'tcx, 'interner> Visitor<'tcx> for ItemLowerer<'tcx, 'interner> {
|
||||||
self.lctx.current_module = old;
|
self.lctx.current_module = old;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_item(&mut self, item: &'tcx Item) {
|
fn visit_item(&mut self, item: &'a Item) {
|
||||||
let mut item_hir_id = None;
|
let mut item_hir_id = None;
|
||||||
self.lctx.with_hir_id_owner(item.id, |lctx| {
|
self.lctx.with_hir_id_owner(item.id, |lctx| {
|
||||||
lctx.without_in_scope_lifetime_defs(|lctx| {
|
lctx.without_in_scope_lifetime_defs(|lctx| {
|
||||||
|
@ -85,7 +85,7 @@ impl<'tcx, 'interner> Visitor<'tcx> for ItemLowerer<'tcx, 'interner> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_trait_item(&mut self, item: &'tcx AssocItem) {
|
fn visit_trait_item(&mut self, item: &'a AssocItem) {
|
||||||
self.lctx.with_hir_id_owner(item.id, |lctx| {
|
self.lctx.with_hir_id_owner(item.id, |lctx| {
|
||||||
let hir_item = lctx.lower_trait_item(item);
|
let hir_item = lctx.lower_trait_item(item);
|
||||||
let id = hir::TraitItemId { hir_id: hir_item.hir_id };
|
let id = hir::TraitItemId { hir_id: hir_item.hir_id };
|
||||||
|
@ -96,7 +96,7 @@ impl<'tcx, 'interner> Visitor<'tcx> for ItemLowerer<'tcx, 'interner> {
|
||||||
visit::walk_trait_item(self, item);
|
visit::walk_trait_item(self, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_impl_item(&mut self, item: &'tcx AssocItem) {
|
fn visit_impl_item(&mut self, item: &'a AssocItem) {
|
||||||
self.lctx.with_hir_id_owner(item.id, |lctx| {
|
self.lctx.with_hir_id_owner(item.id, |lctx| {
|
||||||
let hir_item = lctx.lower_impl_item(item);
|
let hir_item = lctx.lower_impl_item(item);
|
||||||
let id = hir::ImplItemId { hir_id: hir_item.hir_id };
|
let id = hir::ImplItemId { hir_id: hir_item.hir_id };
|
||||||
|
@ -107,7 +107,7 @@ impl<'tcx, 'interner> Visitor<'tcx> for ItemLowerer<'tcx, 'interner> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LoweringContext<'_> {
|
impl LoweringContext<'_, '_> {
|
||||||
// Same as the method above, but accepts `hir::GenericParam`s
|
// Same as the method above, but accepts `hir::GenericParam`s
|
||||||
// instead of `ast::GenericParam`s.
|
// instead of `ast::GenericParam`s.
|
||||||
// This should only be used with generics that have already had their
|
// This should only be used with generics that have already had their
|
||||||
|
@ -116,7 +116,7 @@ impl LoweringContext<'_> {
|
||||||
fn with_parent_item_lifetime_defs<T>(
|
fn with_parent_item_lifetime_defs<T>(
|
||||||
&mut self,
|
&mut self,
|
||||||
parent_hir_id: hir::HirId,
|
parent_hir_id: hir::HirId,
|
||||||
f: impl FnOnce(&mut LoweringContext<'_>) -> T,
|
f: impl FnOnce(&mut LoweringContext<'_, '_>) -> T,
|
||||||
) -> T {
|
) -> T {
|
||||||
let old_len = self.in_scope_lifetimes.len();
|
let old_len = self.in_scope_lifetimes.len();
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ impl LoweringContext<'_> {
|
||||||
// from their surrounding environment.
|
// from their surrounding environment.
|
||||||
fn without_in_scope_lifetime_defs<T>(
|
fn without_in_scope_lifetime_defs<T>(
|
||||||
&mut self,
|
&mut self,
|
||||||
f: impl FnOnce(&mut LoweringContext<'_>) -> T,
|
f: impl FnOnce(&mut LoweringContext<'_, '_>) -> T,
|
||||||
) -> T {
|
) -> T {
|
||||||
let old_in_scope_lifetimes = std::mem::replace(&mut self.in_scope_lifetimes, vec![]);
|
let old_in_scope_lifetimes = std::mem::replace(&mut self.in_scope_lifetimes, vec![]);
|
||||||
|
|
||||||
|
@ -1055,7 +1055,7 @@ impl LoweringContext<'_> {
|
||||||
|
|
||||||
fn lower_body(
|
fn lower_body(
|
||||||
&mut self,
|
&mut self,
|
||||||
f: impl FnOnce(&mut LoweringContext<'_>) -> (HirVec<hir::Param>, hir::Expr),
|
f: impl FnOnce(&mut LoweringContext<'_, '_>) -> (HirVec<hir::Param>, hir::Expr),
|
||||||
) -> hir::BodyId {
|
) -> hir::BodyId {
|
||||||
let prev_gen_kind = self.generator_kind.take();
|
let prev_gen_kind = self.generator_kind.take();
|
||||||
let (parameters, result) = f(self);
|
let (parameters, result) = f(self);
|
||||||
|
@ -1076,7 +1076,7 @@ impl LoweringContext<'_> {
|
||||||
pub(super) fn lower_fn_body(
|
pub(super) fn lower_fn_body(
|
||||||
&mut self,
|
&mut self,
|
||||||
decl: &FnDecl,
|
decl: &FnDecl,
|
||||||
body: impl FnOnce(&mut LoweringContext<'_>) -> hir::Expr,
|
body: impl FnOnce(&mut LoweringContext<'_, '_>) -> hir::Expr,
|
||||||
) -> hir::BodyId {
|
) -> hir::BodyId {
|
||||||
self.lower_body(|this| (
|
self.lower_body(|this| (
|
||||||
decl.inputs.iter().map(|x| this.lower_param(x)).collect(),
|
decl.inputs.iter().map(|x| this.lower_param(x)).collect(),
|
||||||
|
|
|
@ -22,7 +22,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||||
/// A visitor that walks over the HIR and collects `Node`s into a HIR map.
|
/// A visitor that walks over the HIR and collects `Node`s into a HIR map.
|
||||||
pub(super) struct NodeCollector<'a, 'hir> {
|
pub(super) struct NodeCollector<'a, 'hir> {
|
||||||
/// The crate
|
/// The crate
|
||||||
krate: &'hir Crate,
|
krate: &'hir Crate<'hir>,
|
||||||
|
|
||||||
/// Source map
|
/// Source map
|
||||||
source_map: &'a SourceMap,
|
source_map: &'a SourceMap,
|
||||||
|
@ -99,7 +99,7 @@ where
|
||||||
|
|
||||||
impl<'a, 'hir> NodeCollector<'a, 'hir> {
|
impl<'a, 'hir> NodeCollector<'a, 'hir> {
|
||||||
pub(super) fn root(sess: &'a Session,
|
pub(super) fn root(sess: &'a Session,
|
||||||
krate: &'hir Crate,
|
krate: &'hir Crate<'hir>,
|
||||||
dep_graph: &'a DepGraph,
|
dep_graph: &'a DepGraph,
|
||||||
definitions: &'a definitions::Definitions,
|
definitions: &'a definitions::Definitions,
|
||||||
hir_to_node_id: &'a FxHashMap<HirId, NodeId>,
|
hir_to_node_id: &'a FxHashMap<HirId, NodeId>,
|
||||||
|
|
|
@ -153,20 +153,20 @@ impl<'hir> Entry<'hir> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stores a crate and any number of inlined items from other crates.
|
/// Stores a crate and any number of inlined items from other crates.
|
||||||
pub struct Forest {
|
pub struct Forest<'hir> {
|
||||||
krate: Crate,
|
krate: Crate<'hir>,
|
||||||
pub dep_graph: DepGraph,
|
pub dep_graph: DepGraph,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Forest {
|
impl Forest<'hir> {
|
||||||
pub fn new(krate: Crate, dep_graph: &DepGraph) -> Forest {
|
pub fn new(krate: Crate<'hir>, dep_graph: &DepGraph) -> Forest<'hir> {
|
||||||
Forest {
|
Forest {
|
||||||
krate,
|
krate,
|
||||||
dep_graph: dep_graph.clone(),
|
dep_graph: dep_graph.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn krate(&self) -> &Crate {
|
pub fn krate(&self) -> &Crate<'hir> {
|
||||||
self.dep_graph.read(DepNode::new_no_params(DepKind::Krate));
|
self.dep_graph.read(DepNode::new_no_params(DepKind::Krate));
|
||||||
&self.krate
|
&self.krate
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,7 @@ impl Forest {
|
||||||
/// This is used internally in the dependency tracking system.
|
/// This is used internally in the dependency tracking system.
|
||||||
/// Use the `krate` method to ensure your dependency on the
|
/// Use the `krate` method to ensure your dependency on the
|
||||||
/// crate is tracked.
|
/// crate is tracked.
|
||||||
pub fn untracked_krate(&self) -> &Crate {
|
pub fn untracked_krate(&self) -> &Crate<'hir> {
|
||||||
&self.krate
|
&self.krate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -189,7 +189,7 @@ pub(super) type HirEntryMap<'hir> = IndexVec<DefIndex, IndexVec<ItemLocalId, Opt
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Map<'hir> {
|
pub struct Map<'hir> {
|
||||||
/// The backing storage for all the AST nodes.
|
/// The backing storage for all the AST nodes.
|
||||||
pub forest: &'hir Forest,
|
pub forest: &'hir Forest<'hir>,
|
||||||
|
|
||||||
/// Same as the dep_graph in forest, just available with one fewer
|
/// Same as the dep_graph in forest, just available with one fewer
|
||||||
/// deref. This is a gratuitous micro-optimization.
|
/// deref. This is a gratuitous micro-optimization.
|
||||||
|
@ -439,7 +439,7 @@ impl<'hir> Map<'hir> {
|
||||||
self.lookup(id).cloned()
|
self.lookup(id).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn krate(&self) -> &'hir Crate {
|
pub fn krate(&self) -> &'hir Crate<'hir> {
|
||||||
self.forest.krate()
|
self.forest.krate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1257,7 +1257,7 @@ impl Named for ImplItem { fn name(&self) -> Name { self.ident.name } }
|
||||||
|
|
||||||
pub fn map_crate<'hir>(sess: &crate::session::Session,
|
pub fn map_crate<'hir>(sess: &crate::session::Session,
|
||||||
cstore: &CrateStoreDyn,
|
cstore: &CrateStoreDyn,
|
||||||
forest: &'hir Forest,
|
forest: &'hir Forest<'hir>,
|
||||||
definitions: Definitions)
|
definitions: Definitions)
|
||||||
-> Map<'hir> {
|
-> Map<'hir> {
|
||||||
let _prof_timer = sess.prof.generic_activity("build_hir_map");
|
let _prof_timer = sess.prof.generic_activity("build_hir_map");
|
||||||
|
|
|
@ -742,13 +742,13 @@ pub struct ModuleItems {
|
||||||
///
|
///
|
||||||
/// [rustc guide]: https://rust-lang.github.io/rustc-guide/hir.html
|
/// [rustc guide]: https://rust-lang.github.io/rustc-guide/hir.html
|
||||||
#[derive(RustcEncodable, RustcDecodable, Debug)]
|
#[derive(RustcEncodable, RustcDecodable, Debug)]
|
||||||
pub struct Crate {
|
pub struct Crate<'hir> {
|
||||||
pub module: Mod,
|
pub module: Mod,
|
||||||
pub attrs: HirVec<Attribute>,
|
pub attrs: &'hir [Attribute],
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub exported_macros: HirVec<MacroDef>,
|
pub exported_macros: &'hir [MacroDef],
|
||||||
// Attributes from non-exported macros, kept only for collecting the library feature list.
|
// Attributes from non-exported macros, kept only for collecting the library feature list.
|
||||||
pub non_exported_macro_attrs: HirVec<Attribute>,
|
pub non_exported_macro_attrs: &'hir [Attribute],
|
||||||
|
|
||||||
// N.B., we use a `BTreeMap` here so that `visit_all_items` iterates
|
// N.B., we use a `BTreeMap` here so that `visit_all_items` iterates
|
||||||
// over the ids in increasing order. In principle it should not
|
// over the ids in increasing order. In principle it should not
|
||||||
|
@ -774,7 +774,7 @@ pub struct Crate {
|
||||||
pub modules: BTreeMap<HirId, ModuleItems>,
|
pub modules: BTreeMap<HirId, ModuleItems>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Crate {
|
impl Crate<'_> {
|
||||||
pub fn item(&self, id: HirId) -> &Item {
|
pub fn item(&self, id: HirId) -> &Item {
|
||||||
&self.items[&id]
|
&self.items[&id]
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ pub struct NoAnn;
|
||||||
impl PpAnn for NoAnn {}
|
impl PpAnn for NoAnn {}
|
||||||
pub const NO_ANN: &dyn PpAnn = &NoAnn;
|
pub const NO_ANN: &dyn PpAnn = &NoAnn;
|
||||||
|
|
||||||
impl PpAnn for hir::Crate {
|
impl PpAnn for hir::Crate<'a> {
|
||||||
fn try_fetch_item(&self, item: hir::HirId) -> Option<&hir::Item> {
|
fn try_fetch_item(&self, item: hir::HirId) -> Option<&hir::Item> {
|
||||||
Some(self.item(item))
|
Some(self.item(item))
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ pub const INDENT_UNIT: usize = 4;
|
||||||
/// it can scan the input text for comments to copy forward.
|
/// it can scan the input text for comments to copy forward.
|
||||||
pub fn print_crate<'a>(cm: &'a SourceMap,
|
pub fn print_crate<'a>(cm: &'a SourceMap,
|
||||||
sess: &ParseSess,
|
sess: &ParseSess,
|
||||||
krate: &hir::Crate,
|
krate: &hir::Crate<'a>,
|
||||||
filename: FileName,
|
filename: FileName,
|
||||||
input: String,
|
input: String,
|
||||||
ann: &'a dyn PpAnn) -> String {
|
ann: &'a dyn PpAnn) -> String {
|
||||||
|
|
|
@ -56,7 +56,7 @@ pub enum NodeIdHashingMode {
|
||||||
/// We could also just store a plain reference to the `hir::Crate` but we want
|
/// We could also just store a plain reference to the `hir::Crate` but we want
|
||||||
/// to avoid that the crate is used to get untracked access to all of the HIR.
|
/// to avoid that the crate is used to get untracked access to all of the HIR.
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
struct BodyResolver<'tcx>(&'tcx hir::Crate);
|
struct BodyResolver<'tcx>(&'tcx hir::Crate<'tcx>);
|
||||||
|
|
||||||
impl<'tcx> BodyResolver<'tcx> {
|
impl<'tcx> BodyResolver<'tcx> {
|
||||||
/// Returns a reference to the `hir::Body` with the given `BodyId`.
|
/// Returns a reference to the `hir::Body` with the given `BodyId`.
|
||||||
|
@ -72,7 +72,7 @@ impl<'a> StableHashingContext<'a> {
|
||||||
/// leaking data out of the tracking system.
|
/// leaking data out of the tracking system.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(sess: &'a Session,
|
pub fn new(sess: &'a Session,
|
||||||
krate: &'a hir::Crate,
|
krate: &'a hir::Crate<'a>,
|
||||||
definitions: &'a Definitions,
|
definitions: &'a Definitions,
|
||||||
cstore: &'a dyn CrateStore)
|
cstore: &'a dyn CrateStore)
|
||||||
-> Self {
|
-> Self {
|
||||||
|
|
|
@ -90,8 +90,8 @@ macro_rules! late_lint_methods {
|
||||||
fn check_body(a: &$hir hir::Body);
|
fn check_body(a: &$hir hir::Body);
|
||||||
fn check_body_post(a: &$hir hir::Body);
|
fn check_body_post(a: &$hir hir::Body);
|
||||||
fn check_name(a: Span, b: ast::Name);
|
fn check_name(a: Span, b: ast::Name);
|
||||||
fn check_crate(a: &$hir hir::Crate);
|
fn check_crate(a: &$hir hir::Crate<$hir>);
|
||||||
fn check_crate_post(a: &$hir hir::Crate);
|
fn check_crate_post(a: &$hir hir::Crate<$hir>);
|
||||||
fn check_mod(a: &$hir hir::Mod, b: Span, c: hir::HirId);
|
fn check_mod(a: &$hir hir::Mod, b: Span, c: hir::HirId);
|
||||||
fn check_mod_post(a: &$hir hir::Mod, b: Span, c: hir::HirId);
|
fn check_mod_post(a: &$hir hir::Mod, b: Span, c: hir::HirId);
|
||||||
fn check_foreign_item(a: &$hir hir::ForeignItem);
|
fn check_foreign_item(a: &$hir hir::ForeignItem);
|
||||||
|
@ -562,7 +562,7 @@ fn lint_levels(tcx: TyCtxt<'_>, cnum: CrateNum) -> &LintLevelMap {
|
||||||
|
|
||||||
let push = builder.levels.push(&krate.attrs, &store);
|
let push = builder.levels.push(&krate.attrs, &store);
|
||||||
builder.levels.register_id(hir::CRATE_HIR_ID);
|
builder.levels.register_id(hir::CRATE_HIR_ID);
|
||||||
for macro_def in &krate.exported_macros {
|
for macro_def in krate.exported_macros {
|
||||||
builder.levels.register_id(macro_def.hir_id);
|
builder.levels.register_id(macro_def.hir_id);
|
||||||
}
|
}
|
||||||
intravisit::walk_crate(&mut builder, krate);
|
intravisit::walk_crate(&mut builder, krate);
|
||||||
|
|
|
@ -157,7 +157,7 @@ impl Visitor<'tcx> for LibFeatureCollector<'tcx> {
|
||||||
pub fn collect(tcx: TyCtxt<'_>) -> LibFeatures {
|
pub fn collect(tcx: TyCtxt<'_>) -> LibFeatures {
|
||||||
let mut collector = LibFeatureCollector::new(tcx);
|
let mut collector = LibFeatureCollector::new(tcx);
|
||||||
let krate = tcx.hir().krate();
|
let krate = tcx.hir().krate();
|
||||||
for attr in &krate.non_exported_macro_attrs {
|
for attr in krate.non_exported_macro_attrs {
|
||||||
collector.visit_attribute(attr);
|
collector.visit_attribute(attr);
|
||||||
}
|
}
|
||||||
intravisit::walk_crate(&mut collector, krate);
|
intravisit::walk_crate(&mut collector, krate);
|
||||||
|
|
|
@ -73,7 +73,7 @@ where
|
||||||
}
|
}
|
||||||
fn call_with_pp_support_hir<A, F>(ppmode: &PpSourceMode, tcx: TyCtxt<'_>, f: F) -> A
|
fn call_with_pp_support_hir<A, F>(ppmode: &PpSourceMode, tcx: TyCtxt<'_>, f: F) -> A
|
||||||
where
|
where
|
||||||
F: FnOnce(&dyn HirPrinterSupport<'_>, &hir::Crate) -> A,
|
F: FnOnce(&dyn HirPrinterSupport<'_>, &hir::Crate<'_>) -> A,
|
||||||
{
|
{
|
||||||
match *ppmode {
|
match *ppmode {
|
||||||
PpmNormal => {
|
PpmNormal => {
|
||||||
|
|
|
@ -47,7 +47,7 @@ pub fn assert_module_sources(tcx: TyCtxt<'_>) {
|
||||||
available_cgus
|
available_cgus
|
||||||
};
|
};
|
||||||
|
|
||||||
for attr in &tcx.hir().krate().attrs {
|
for attr in tcx.hir().krate().attrs {
|
||||||
ams.check_attr(attr);
|
ams.check_attr(attr);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -446,17 +446,18 @@ fn configure_and_expand_inner<'a>(
|
||||||
Ok((krate, resolver))
|
Ok((krate, resolver))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lower_to_hir(
|
pub fn lower_to_hir<'res, 'tcx>(
|
||||||
sess: &Session,
|
sess: &'tcx Session,
|
||||||
lint_store: &lint::LintStore,
|
lint_store: &lint::LintStore,
|
||||||
resolver: &mut Resolver<'_>,
|
resolver: &'res mut Resolver<'_>,
|
||||||
dep_graph: &DepGraph,
|
dep_graph: &'res DepGraph,
|
||||||
krate: &ast::Crate,
|
krate: &'res ast::Crate,
|
||||||
) -> Result<hir::map::Forest> {
|
arena: &'tcx Arena<'tcx>,
|
||||||
|
) -> Result<hir::map::Forest<'tcx>> {
|
||||||
// Lower AST to HIR.
|
// Lower AST to HIR.
|
||||||
let hir_forest = time(sess, "lowering AST -> HIR", || {
|
let hir_forest = time(sess, "lowering AST -> HIR", || {
|
||||||
let nt_to_tokenstream = rustc_parse::nt_to_tokenstream;
|
let nt_to_tokenstream = rustc_parse::nt_to_tokenstream;
|
||||||
let hir_crate = lower_crate(sess, &dep_graph, &krate, resolver, nt_to_tokenstream);
|
let hir_crate = lower_crate(sess, &dep_graph, &krate, resolver, nt_to_tokenstream, arena);
|
||||||
|
|
||||||
if sess.opts.debugging_opts.hir_stats {
|
if sess.opts.debugging_opts.hir_stats {
|
||||||
hir_stats::print_hir_stats(&hir_crate);
|
hir_stats::print_hir_stats(&hir_crate);
|
||||||
|
@ -738,7 +739,7 @@ impl<'tcx> QueryContext<'tcx> {
|
||||||
pub fn create_global_ctxt<'tcx>(
|
pub fn create_global_ctxt<'tcx>(
|
||||||
compiler: &'tcx Compiler,
|
compiler: &'tcx Compiler,
|
||||||
lint_store: Lrc<lint::LintStore>,
|
lint_store: Lrc<lint::LintStore>,
|
||||||
hir_forest: &'tcx hir::map::Forest,
|
hir_forest: &'tcx hir::map::Forest<'tcx>,
|
||||||
mut resolver_outputs: ResolverOutputs,
|
mut resolver_outputs: ResolverOutputs,
|
||||||
outputs: OutputFilenames,
|
outputs: OutputFilenames,
|
||||||
crate_name: &str,
|
crate_name: &str,
|
||||||
|
|
|
@ -82,7 +82,7 @@ pub struct Queries<'tcx> {
|
||||||
register_plugins: Query<(ast::Crate, Lrc<LintStore>)>,
|
register_plugins: Query<(ast::Crate, Lrc<LintStore>)>,
|
||||||
expansion: Query<(ast::Crate, Steal<Rc<RefCell<BoxedResolver>>>, Lrc<LintStore>)>,
|
expansion: Query<(ast::Crate, Steal<Rc<RefCell<BoxedResolver>>>, Lrc<LintStore>)>,
|
||||||
dep_graph: Query<DepGraph>,
|
dep_graph: Query<DepGraph>,
|
||||||
lower_to_hir: Query<(&'tcx hir::map::Forest, Steal<ResolverOutputs>)>,
|
lower_to_hir: Query<(&'tcx hir::map::Forest<'tcx>, Steal<ResolverOutputs>)>,
|
||||||
prepare_outputs: Query<OutputFilenames>,
|
prepare_outputs: Query<OutputFilenames>,
|
||||||
global_ctxt: Query<QueryContext<'tcx>>,
|
global_ctxt: Query<QueryContext<'tcx>>,
|
||||||
ongoing_codegen: Query<Box<dyn Any>>,
|
ongoing_codegen: Query<Box<dyn Any>>,
|
||||||
|
@ -216,7 +216,7 @@ impl<'tcx> Queries<'tcx> {
|
||||||
|
|
||||||
pub fn lower_to_hir(
|
pub fn lower_to_hir(
|
||||||
&'tcx self,
|
&'tcx self,
|
||||||
) -> Result<&Query<(&'tcx hir::map::Forest, Steal<ResolverOutputs>)>> {
|
) -> Result<&Query<(&'tcx hir::map::Forest<'tcx>, Steal<ResolverOutputs>)>> {
|
||||||
self.lower_to_hir.compute(|| {
|
self.lower_to_hir.compute(|| {
|
||||||
let expansion_result = self.expansion()?;
|
let expansion_result = self.expansion()?;
|
||||||
let peeked = expansion_result.peek();
|
let peeked = expansion_result.peek();
|
||||||
|
@ -229,7 +229,8 @@ impl<'tcx> Queries<'tcx> {
|
||||||
lint_store,
|
lint_store,
|
||||||
resolver,
|
resolver,
|
||||||
&*self.dep_graph()?.peek(),
|
&*self.dep_graph()?.peek(),
|
||||||
&krate
|
&krate,
|
||||||
|
&self.arena,
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
let hir = self.arena.alloc(hir);
|
let hir = self.arena.alloc(hir);
|
||||||
|
|
|
@ -378,10 +378,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
|
||||||
self.doc_hidden_stack.pop().expect("empty doc_hidden_stack");
|
self.doc_hidden_stack.pop().expect("empty doc_hidden_stack");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_crate(&mut self, cx: &LateContext<'_, '_>, krate: &hir::Crate) {
|
fn check_crate(&mut self, cx: &LateContext<'_, '_>, krate: &hir::Crate<'_>) {
|
||||||
self.check_missing_docs_attrs(cx, None, &krate.attrs, krate.span, "crate");
|
self.check_missing_docs_attrs(cx, None, &krate.attrs, krate.span, "crate");
|
||||||
|
|
||||||
for macro_def in &krate.exported_macros {
|
for macro_def in krate.exported_macros {
|
||||||
let has_doc = macro_def.attrs.iter().any(|a| has_doc(a));
|
let has_doc = macro_def.attrs.iter().any(|a| has_doc(a));
|
||||||
if !has_doc {
|
if !has_doc {
|
||||||
cx.span_lint(MISSING_DOCS,
|
cx.span_lint(MISSING_DOCS,
|
||||||
|
|
|
@ -342,7 +342,7 @@ impl<'tcx> EncodeContext<'tcx> {
|
||||||
let vis = Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityKind::Public };
|
let vis = Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityKind::Public };
|
||||||
self.encode_info_for_mod(hir::CRATE_HIR_ID, &krate.module, &krate.attrs, &vis);
|
self.encode_info_for_mod(hir::CRATE_HIR_ID, &krate.module, &krate.attrs, &vis);
|
||||||
krate.visit_all_item_likes(&mut self.as_deep_visitor());
|
krate.visit_all_item_likes(&mut self.as_deep_visitor());
|
||||||
for macro_def in &krate.exported_macros {
|
for macro_def in krate.exported_macros {
|
||||||
self.visit_macro_def(macro_def);
|
self.visit_macro_def(macro_def);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -355,7 +355,7 @@ fn has_allow_dead_code_or_lang_attr(
|
||||||
// * Implementation of a trait method
|
// * Implementation of a trait method
|
||||||
struct LifeSeeder<'k, 'tcx> {
|
struct LifeSeeder<'k, 'tcx> {
|
||||||
worklist: Vec<hir::HirId>,
|
worklist: Vec<hir::HirId>,
|
||||||
krate: &'k hir::Crate,
|
krate: &'k hir::Crate<'k>,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
// see `MarkSymbolVisitor::struct_constructors`
|
// see `MarkSymbolVisitor::struct_constructors`
|
||||||
struct_constructors: FxHashMap<hir::HirId, hir::HirId>,
|
struct_constructors: FxHashMap<hir::HirId, hir::HirId>,
|
||||||
|
@ -429,7 +429,7 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
|
||||||
fn create_and_seed_worklist<'tcx>(
|
fn create_and_seed_worklist<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
access_levels: &privacy::AccessLevels,
|
access_levels: &privacy::AccessLevels,
|
||||||
krate: &hir::Crate,
|
krate: &hir::Crate<'_>,
|
||||||
) -> (Vec<hir::HirId>, FxHashMap<hir::HirId, hir::HirId>) {
|
) -> (Vec<hir::HirId>, FxHashMap<hir::HirId, hir::HirId>) {
|
||||||
let worklist = access_levels.map.iter().filter_map(|(&id, level)| {
|
let worklist = access_levels.map.iter().filter_map(|(&id, level)| {
|
||||||
if level >= &privacy::AccessLevel::Reachable {
|
if level >= &privacy::AccessLevel::Reachable {
|
||||||
|
@ -457,7 +457,7 @@ fn create_and_seed_worklist<'tcx>(
|
||||||
fn find_live<'tcx>(
|
fn find_live<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
access_levels: &privacy::AccessLevels,
|
access_levels: &privacy::AccessLevels,
|
||||||
krate: &hir::Crate,
|
krate: &hir::Crate<'_>,
|
||||||
) -> FxHashSet<hir::HirId> {
|
) -> FxHashSet<hir::HirId> {
|
||||||
let (worklist, struct_constructors) = create_and_seed_worklist(tcx, access_levels, krate);
|
let (worklist, struct_constructors) = create_and_seed_worklist(tcx, access_levels, krate);
|
||||||
let mut symbol_visitor = MarkSymbolVisitor {
|
let mut symbol_visitor = MarkSymbolVisitor {
|
||||||
|
|
|
@ -23,12 +23,12 @@ struct NodeData {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct StatCollector<'k> {
|
struct StatCollector<'k> {
|
||||||
krate: Option<&'k hir::Crate>,
|
krate: Option<&'k hir::Crate<'k>>,
|
||||||
data: FxHashMap<&'static str, NodeData>,
|
data: FxHashMap<&'static str, NodeData>,
|
||||||
seen: FxHashSet<Id>,
|
seen: FxHashSet<Id>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_hir_stats(krate: &hir::Crate) {
|
pub fn print_hir_stats(krate: &hir::Crate<'_>) {
|
||||||
let mut collector = StatCollector {
|
let mut collector = StatCollector {
|
||||||
krate: Some(krate),
|
krate: Some(krate),
|
||||||
data: FxHashMap::default(),
|
data: FxHashMap::default(),
|
||||||
|
|
|
@ -1076,7 +1076,7 @@ struct UsePlacementFinder<'tcx> {
|
||||||
impl UsePlacementFinder<'tcx> {
|
impl UsePlacementFinder<'tcx> {
|
||||||
fn check(
|
fn check(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
krate: &'tcx hir::Crate,
|
krate: &'tcx hir::Crate<'tcx>,
|
||||||
target_module: hir::HirId,
|
target_module: hir::HirId,
|
||||||
) -> (Option<Span>, bool) {
|
) -> (Option<Span>, bool) {
|
||||||
let mut finder = UsePlacementFinder {
|
let mut finder = UsePlacementFinder {
|
||||||
|
|
|
@ -72,7 +72,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
|
|
||||||
pub fn visit(mut self, krate: &'tcx hir::Crate) -> Module<'tcx> {
|
pub fn visit(mut self, krate: &'tcx hir::Crate) -> Module<'tcx> {
|
||||||
let mut module = self.visit_mod_contents(krate.span,
|
let mut module = self.visit_mod_contents(krate.span,
|
||||||
&krate.attrs,
|
krate.attrs,
|
||||||
&Spanned { span: syntax_pos::DUMMY_SP,
|
&Spanned { span: syntax_pos::DUMMY_SP,
|
||||||
node: hir::VisibilityKind::Public },
|
node: hir::VisibilityKind::Public },
|
||||||
hir::CRATE_HIR_ID,
|
hir::CRATE_HIR_ID,
|
||||||
|
@ -213,7 +213,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_mod_contents(&mut self, span: Span, attrs: &'tcx hir::HirVec<ast::Attribute>,
|
fn visit_mod_contents(&mut self, span: Span, attrs: &'tcx [ast::Attribute],
|
||||||
vis: &'tcx hir::Visibility, id: hir::HirId,
|
vis: &'tcx hir::Visibility, id: hir::HirId,
|
||||||
m: &'tcx hir::Mod,
|
m: &'tcx hir::Mod,
|
||||||
name: Option<ast::Name>) -> Module<'tcx> {
|
name: Option<ast::Name>) -> Module<'tcx> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue