diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 37ee672291ec..cae813582cd2 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -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); } } diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index d79f1bfa6809..c49242485e15 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -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))), } } diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index c6409f8d4651..cd96bedf4bdb 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -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 { diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 25fc365b4ec0..c89d93337ebc 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -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, + 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!`). diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 63d8afc7ec99..f0499e5853f3 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -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)); } } diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index a91535b55162..45274b0526fe 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -218,7 +218,7 @@ impl<'a> HashStable> for hir::VisibilityKind { } } -impl<'a> HashStable> for hir::Mod { +impl<'a> HashStable> for hir::Mod<'_> { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let hir::Mod { inner: ref inner_span, diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 7f19ec60f536..5ac20f46238f 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -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); } diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 86c7d5515607..a5d6cf9dbb72 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -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>); diff --git a/src/librustc_lint/nonstandard_style.rs b/src/librustc_lint/nonstandard_style.rs index 63a5f8681d6f..9b9203083ee7 100644 --- a/src/librustc_lint/nonstandard_style.rs +++ b/src/librustc_lint/nonstandard_style.rs @@ -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; } diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index e9c5f90d9dcf..cfe5ea65fca5 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -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, ) { diff --git a/src/librustc_passes/hir_stats.rs b/src/librustc_passes/hir_stats.rs index 9ea742354014..776c1aff1118 100644 --- a/src/librustc_passes/hir_stats.rs +++ b/src/librustc_passes/hir_stats.rs @@ -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) } diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index d8d554bad2ca..83f2fe7e0231 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -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` } diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index aecc46d31288..e2b77c01e24d 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -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(..) => { diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 2c2a51928d9c..897c00f276e9 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -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) -> 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); }