Use Arena inside hir::Mod.

This commit is contained in:
Camille GILLOT 2019-11-29 10:24:47 +01:00
parent e2526120f2
commit 42c03e4bb4
14 changed files with 29 additions and 29 deletions

View file

@ -247,7 +247,7 @@ pub trait Visitor<'v>: Sized {
fn visit_ident(&mut self, ident: Ident) {
walk_ident(self, ident)
}
fn visit_mod(&mut self, m: &'v Mod, _s: Span, n: HirId) {
fn visit_mod(&mut self, m: &'v Mod<'v>, _s: Span, n: HirId) {
walk_mod(self, m, n)
}
fn visit_foreign_item(&mut self, i: &'v ForeignItem<'v>) {
@ -394,9 +394,9 @@ pub fn walk_macro_def<'v, V: Visitor<'v>>(visitor: &mut V, macro_def: &'v MacroD
walk_list!(visitor, visit_attribute, macro_def.attrs);
}
pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod, mod_hir_id: HirId) {
pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod<'v>, mod_hir_id: HirId) {
visitor.visit_id(mod_hir_id);
for &item_id in &module.item_ids {
for &item_id in module.item_ids {
visitor.visit_nested_item(item_id);
}
}

View file

@ -161,10 +161,10 @@ impl LoweringContext<'_, 'hir> {
res
}
pub(super) fn lower_mod(&mut self, m: &Mod) -> hir::Mod {
pub(super) fn lower_mod(&mut self, m: &Mod) -> hir::Mod<'hir> {
hir::Mod {
inner: m.inner,
item_ids: m.items.iter().flat_map(|x| self.lower_item_id(x)).collect(),
item_ids: self.arena.alloc_from_iter(m.items.iter().flat_map(|x| self.lower_item_id(x))),
}
}

View file

@ -580,7 +580,7 @@ impl<'hir> Map<'hir> {
&self.forest.krate.attrs
}
pub fn get_module(&self, module: DefId) -> (&'hir Mod, Span, HirId) {
pub fn get_module(&self, module: DefId) -> (&'hir Mod<'hir>, Span, HirId) {
let hir_id = self.as_local_hir_id(module).unwrap();
self.read(hir_id);
match self.find_entry(hir_id).unwrap().node {

View file

@ -743,7 +743,7 @@ pub struct ModuleItems {
/// [rustc guide]: https://rust-lang.github.io/rustc-guide/hir.html
#[derive(RustcEncodable, RustcDecodable, Debug)]
pub struct Crate<'hir> {
pub module: Mod,
pub module: Mod<'hir>,
pub attrs: &'hir [Attribute],
pub span: Span,
pub exported_macros: &'hir [MacroDef<'hir>],
@ -2243,12 +2243,12 @@ impl FunctionRetTy {
}
#[derive(RustcEncodable, RustcDecodable, Debug)]
pub struct Mod {
pub struct Mod<'hir> {
/// A span from the first token past `{` to the last token until `}`.
/// For `mod foo;`, the inner span ranges from the first token
/// to the last token in the external file.
pub inner: Span,
pub item_ids: HirVec<ItemId>,
pub item_ids: &'hir [ItemId],
}
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
@ -2489,7 +2489,7 @@ pub enum ItemKind<'hir> {
/// A function declaration.
Fn(FnSig, Generics, BodyId),
/// A module.
Mod(Mod),
Mod(Mod<'hir>),
/// An external module, e.g. `extern { .. }`.
ForeignMod(ForeignMod<'hir>),
/// Module-level inline assembly (from `global_asm!`).

View file

@ -259,9 +259,9 @@ impl<'a> State<'a> {
self.commasep_cmnt(b, exprs, |s, e| s.print_expr(&e), |e| e.span)
}
pub fn print_mod(&mut self, _mod: &hir::Mod, attrs: &[ast::Attribute]) {
pub fn print_mod(&mut self, _mod: &hir::Mod<'_>, attrs: &[ast::Attribute]) {
self.print_inner_attributes(attrs);
for &item_id in &_mod.item_ids {
for &item_id in _mod.item_ids {
self.ann.nested(self, Nested::Item(item_id));
}
}

View file

@ -218,7 +218,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::VisibilityKind {
}
}
impl<'a> HashStable<StableHashingContext<'a>> for hir::Mod {
impl<'a> HashStable<StableHashingContext<'a>> for hir::Mod<'_> {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let hir::Mod {
inner: ref inner_span,

View file

@ -883,7 +883,7 @@ impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> LateContextAndPass<'a, 'tcx, T> {
self.context.param_env = old_param_env;
}
fn process_mod(&mut self, m: &'tcx hir::Mod, s: Span, n: hir::HirId) {
fn process_mod(&mut self, m: &'tcx hir::Mod<'tcx>, s: Span, n: hir::HirId) {
lint_callback!(self, check_mod, m, s, n);
hir_visit::walk_mod(self, m, n);
lint_callback!(self, check_mod_post, m, s, n);
@ -1027,7 +1027,7 @@ for LateContextAndPass<'a, 'tcx, T> {
lint_callback!(self, check_name, sp, name);
}
fn visit_mod(&mut self, m: &'tcx hir::Mod, s: Span, n: hir::HirId) {
fn visit_mod(&mut self, m: &'tcx hir::Mod<'tcx>, s: Span, n: hir::HirId) {
if !self.context.only_module {
self.process_mod(m, s, n);
}

View file

@ -92,8 +92,8 @@ macro_rules! late_lint_methods {
fn check_name(a: Span, b: ast::Name);
fn check_crate(a: &$hir hir::Crate<$hir>);
fn check_crate_post(a: &$hir hir::Crate<$hir>);
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(a: &$hir hir::Mod<$hir>, b: Span, c: hir::HirId);
fn check_mod_post(a: &$hir hir::Mod<$hir>, b: Span, c: hir::HirId);
fn check_foreign_item(a: &$hir hir::ForeignItem<$hir>);
fn check_foreign_item_post(a: &$hir hir::ForeignItem<$hir>);
fn check_item(a: &$hir hir::Item<$hir>);

View file

@ -246,7 +246,7 @@ impl NonSnakeCase {
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
fn check_mod(&mut self, cx: &LateContext<'_, '_>, _: &'tcx hir::Mod, _: Span, id: hir::HirId) {
fn check_mod(&mut self, cx: &LateContext<'_, '_>, _: &'tcx hir::Mod<'tcx>, _: Span, id: hir::HirId) {
if id != hir::CRATE_HIR_ID {
return;
}

View file

@ -682,7 +682,7 @@ impl EncodeContext<'tcx> {
fn encode_info_for_mod(
&mut self,
id: hir::HirId,
md: &hir::Mod,
md: &hir::Mod<'_>,
attrs: &[ast::Attribute],
vis: &hir::Visibility,
) {

View file

@ -128,7 +128,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
hir_visit::walk_item(self, i)
}
fn visit_mod(&mut self, m: &'v hir::Mod, _s: Span, n: hir::HirId) {
fn visit_mod(&mut self, m: &'v hir::Mod<'v>, _s: Span, n: hir::HirId) {
self.record("Mod", Id::None, m);
hir_visit::walk_mod(self, m, n)
}

View file

@ -510,7 +510,7 @@ impl EmbargoVisitor<'tcx> {
fn update_macro_reachable_mod(&mut self, reachable_mod: hir::HirId, defining_mod: DefId) {
let module_def_id = self.tcx.hir().local_def_id(reachable_mod);
let module = self.tcx.hir().get_module(module_def_id).0;
for item_id in &module.item_ids {
for item_id in module.item_ids {
let hir_id = item_id.id;
let item_def_id = self.tcx.hir().local_def_id(hir_id);
if let Some(def_kind) = self.tcx.def_kind(item_def_id) {
@ -849,7 +849,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
self.prev_level = orig_level;
}
fn visit_mod(&mut self, m: &'tcx hir::Mod, _sp: Span, id: hir::HirId) {
fn visit_mod(&mut self, m: &'tcx hir::Mod<'tcx>, _sp: Span, id: hir::HirId) {
// This code is here instead of in visit_item so that the
// crate module gets processed as well.
if self.prev_level.is_some() {
@ -992,7 +992,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> {
NestedVisitorMap::All(&self.tcx.hir())
}
fn visit_mod(&mut self, _m: &'tcx hir::Mod, _s: Span, _n: hir::HirId) {
fn visit_mod(&mut self, _m: &'tcx hir::Mod<'tcx>, _s: Span, _n: hir::HirId) {
// Don't visit nested modules, since we run a separate visitor walk
// for each module in `privacy_access_levels`
}
@ -1132,7 +1132,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
NestedVisitorMap::All(&self.tcx.hir())
}
fn visit_mod(&mut self, _m: &'tcx hir::Mod, _s: Span, _n: hir::HirId) {
fn visit_mod(&mut self, _m: &'tcx hir::Mod<'tcx>, _s: Span, _n: hir::HirId) {
// Don't visit nested modules, since we run a separate visitor walk
// for each module in `privacy_access_levels`
}

View file

@ -1093,7 +1093,7 @@ impl UsePlacementFinder<'tcx> {
impl hir::intravisit::Visitor<'tcx> for UsePlacementFinder<'tcx> {
fn visit_mod(
&mut self,
module: &'tcx hir::Mod,
module: &'tcx hir::Mod<'tcx>,
_: Span,
hir_id: hir::HirId,
) {
@ -1105,7 +1105,7 @@ impl hir::intravisit::Visitor<'tcx> for UsePlacementFinder<'tcx> {
return;
}
// Find a `use` statement.
for item_id in &module.item_ids {
for item_id in module.item_ids {
let item = self.tcx.hir().expect_item(item_id.id);
match item.kind {
hir::ItemKind::Use(..) => {

View file

@ -215,7 +215,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
fn visit_mod_contents(&mut self, span: Span, attrs: &'tcx [ast::Attribute],
vis: &'tcx hir::Visibility, id: hir::HirId,
m: &'tcx hir::Mod,
m: &'tcx hir::Mod<'tcx>,
name: Option<ast::Name>) -> Module<'tcx> {
let mut om = Module::new(name, attrs, vis);
om.where_outer = span;
@ -224,7 +224,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
// Keep track of if there were any private modules in the path.
let orig_inside_public_path = self.inside_public_path;
self.inside_public_path &= vis.node.is_pub();
for i in &m.item_ids {
for i in m.item_ids {
let item = self.cx.tcx.hir().expect_item(i.id);
self.visit_item(item, None, &mut om);
}
@ -322,7 +322,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
let ret = match tcx.hir().get(res_hir_id) {
Node::Item(&hir::Item { kind: hir::ItemKind::Mod(ref m), .. }) if glob => {
let prev = mem::replace(&mut self.inlining, true);
for i in &m.item_ids {
for i in m.item_ids {
let i = self.cx.tcx.hir().expect_item(i.id);
self.visit_item(i, None, om);
}