From 4dc79f1f7d8aabbed2983a91ba1027373b376a65 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 28 Nov 2019 11:49:29 +0100 Subject: [PATCH 01/12] Use Arena inside hir::Crate. --- src/librustc/arena.rs | 5 +- src/librustc/hir/intravisit.rs | 6 +- src/librustc/hir/lowering.rs | 61 +++++++++++-------- src/librustc/hir/lowering/expr.rs | 10 +-- src/librustc/hir/lowering/item.rs | 26 ++++---- src/librustc/hir/map/collector.rs | 4 +- src/librustc/hir/map/mod.rs | 18 +++--- src/librustc/hir/mod.rs | 10 +-- src/librustc/hir/print.rs | 4 +- src/librustc/ich/hcx.rs | 4 +- src/librustc/lint/mod.rs | 6 +- src/librustc/middle/lib_features.rs | 2 +- src/librustc_driver/pretty.rs | 2 +- .../assert_module_sources.rs | 2 +- src/librustc_interface/passes.rs | 17 +++--- src/librustc_interface/queries.rs | 7 ++- src/librustc_lint/builtin.rs | 4 +- src/librustc_metadata/rmeta/encoder.rs | 2 +- src/librustc_passes/dead.rs | 6 +- src/librustc_passes/hir_stats.rs | 4 +- src/librustc_typeck/check/method/suggest.rs | 2 +- src/librustdoc/visit_ast.rs | 4 +- 22 files changed, 109 insertions(+), 97 deletions(-) diff --git a/src/librustc/arena.rs b/src/librustc/arena.rs index eb7a1709801..59d57c6ae24 100644 --- a/src/librustc/arena.rs +++ b/src/librustc/arena.rs @@ -93,7 +93,6 @@ macro_rules! arena_types { rustc::hir::def_id::CrateNum > >, - [few] hir_forest: rustc::hir::map::Forest, [few] diagnostic_items: rustc_data_structures::fx::FxHashMap< syntax::symbol::Symbol, rustc::hir::def_id::DefId, @@ -123,6 +122,10 @@ macro_rules! arena_types { [few] crate_variances: rustc::ty::CrateVariancesMap<'tcx>, [few] inferred_outlives_crate: rustc::ty::CratePredicatesMap<'tcx>, [] upvars: rustc_data_structures::fx::FxIndexMap, + // HIR nodes arenas + [few] hir_forest: rustc::hir::map::Forest<$tcx>, + [] attribute: syntax::ast::Attribute, + [] macro_def: rustc::hir::MacroDef, ], $tcx); ) } diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index a4557a0776c..e71e05678f3 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -382,10 +382,10 @@ pub trait Visitor<'v>: Sized { } /// 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); - walk_list!(visitor, visit_attribute, &krate.attrs); - walk_list!(visitor, visit_macro_def, &krate.exported_macros); + walk_list!(visitor, visit_attribute, krate.attrs); + 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) { diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 2fd708f1ea3..a8f0c90ab3a 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -35,6 +35,7 @@ mod expr; mod item; +use crate::arena::Arena; use crate::dep_graph::DepGraph; use crate::hir::{self, ParamName}; use crate::hir::HirVec; @@ -77,7 +78,7 @@ use rustc_error_codes::*; const HIR_ID_COUNTER_LOCKED: u32 = 0xFFFFFFFF; -pub struct LoweringContext<'a> { +pub struct LoweringContext<'a, 'hir: 'a> { crate_root: Option, /// 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. nt_to_tokenstream: NtToTokenstream, + /// Used to allocate HIR nodes + arena: &'hir Arena<'hir>, + /// The items being lowered are collected here. items: BTreeMap, @@ -240,13 +244,14 @@ impl<'a> ImplTraitContext<'a> { } } -pub fn lower_crate( - sess: &Session, - dep_graph: &DepGraph, - krate: &Crate, - resolver: &mut dyn Resolver, +pub fn lower_crate<'a, 'hir>( + sess: &'a Session, + dep_graph: &'a DepGraph, + krate: &'a Crate, + resolver: &'a mut dyn Resolver, 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 // read, since we haven't even constructed the *input* to // incr. comp. yet. @@ -259,6 +264,7 @@ pub fn lower_crate( sess, resolver, nt_to_tokenstream, + arena, items: BTreeMap::new(), trait_items: BTreeMap::new(), impl_items: BTreeMap::new(), @@ -382,19 +388,19 @@ impl<'a, 'b> Visitor<'a> for ImplTraitTypeIdVisitor<'b> { } } -impl<'a> LoweringContext<'a> { - fn lower_crate(mut self, c: &Crate) -> hir::Crate { +impl<'a, 'hir> LoweringContext<'a, 'hir> { + fn lower_crate(mut self, c: &Crate) -> hir::Crate<'hir> { /// Full-crate AST visitor that inserts into a fresh /// `LoweringContext` any information that may be /// needed from arbitrary locations in the crate, /// e.g., the number of lifetime generic parameters /// declared for every type and trait definition. - struct MiscCollector<'tcx, 'interner> { - lctx: &'tcx mut LoweringContext<'interner>, + struct MiscCollector<'tcx, 'lowering, 'hir> { + lctx: &'tcx mut LoweringContext<'lowering, 'hir>, hir_id_owner: Option, } - impl MiscCollector<'_, '_> { + impl MiscCollector<'_, '_, '_> { fn allocate_use_tree_hir_id_counters( &mut self, 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) { if let PatKind::Paren(..) | PatKind::Rest = p.kind { // Doesn't generate a HIR node @@ -537,7 +543,7 @@ impl<'a> LoweringContext<'a> { visit::walk_crate(&mut item::ItemLowerer { lctx: &mut self }, c); 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); self.resolver @@ -548,8 +554,8 @@ impl<'a> LoweringContext<'a> { module, attrs, span: c.span, - exported_macros: hir::HirVec::from(self.exported_macros), - non_exported_macro_attrs: hir::HirVec::from(self.non_exported_macro_attrs), + exported_macros: self.arena.alloc_from_iter(self.exported_macros), + non_exported_macro_attrs: self.arena.alloc_from_iter(self.non_exported_macro_attrs), items: self.items, trait_items: self.trait_items, impl_items: self.impl_items, @@ -750,7 +756,7 @@ impl<'a> LoweringContext<'a> { f: F, ) -> (Vec, T) where - F: FnOnce(&mut LoweringContext<'_>) -> (Vec, T), + F: FnOnce(&mut LoweringContext<'_, '_>) -> (Vec, T), { assert!(!self.is_collecting_in_band_lifetimes); assert!(self.lifetimes_to_define.is_empty()); @@ -867,7 +873,7 @@ impl<'a> LoweringContext<'a> { // for them. fn with_in_scope_lifetime_defs(&mut self, params: &[GenericParam], f: F) -> T where - F: FnOnce(&mut LoweringContext<'_>) -> T, + F: FnOnce(&mut LoweringContext<'_, '_>) -> T, { let old_len = self.in_scope_lifetimes.len(); let lt_def_names = params.iter().filter_map(|param| match param.kind { @@ -896,7 +902,7 @@ impl<'a> LoweringContext<'a> { f: F, ) -> (hir::Generics, T) where - F: FnOnce(&mut LoweringContext<'_>, &mut Vec) -> T, + F: FnOnce(&mut LoweringContext<'_, '_>, &mut Vec) -> T, { let (in_band_defs, (mut lowered_generics, res)) = self.with_in_scope_lifetime_defs( &generics.params, @@ -945,7 +951,7 @@ impl<'a> LoweringContext<'a> { fn with_dyn_type_scope(&mut self, in_scope: bool, f: F) -> T where - F: FnOnce(&mut LoweringContext<'_>) -> T, + F: FnOnce(&mut LoweringContext<'_, '_>) -> T, { let was_in_dyn_type = self.is_in_dyn_type; self.is_in_dyn_type = in_scope; @@ -959,7 +965,7 @@ impl<'a> LoweringContext<'a> { fn with_new_scopes(&mut self, f: F) -> T where - F: FnOnce(&mut LoweringContext<'_>) -> T, + F: FnOnce(&mut LoweringContext<'_, '_>) -> T, { let was_in_loop_condition = self.is_in_loop_condition; self.is_in_loop_condition = false; @@ -1446,7 +1452,7 @@ impl<'a> LoweringContext<'a> { span: Span, fn_def_id: Option, opaque_ty_node_id: NodeId, - lower_bounds: impl FnOnce(&mut LoweringContext<'_>) -> hir::GenericBounds, + lower_bounds: impl FnOnce(&mut LoweringContext<'_, '_>) -> hir::GenericBounds, ) -> hir::TyKind { debug!( "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 // 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>`. - struct ImplTraitLifetimeCollector<'r, 'a> { - context: &'r mut LoweringContext<'a>, + struct ImplTraitLifetimeCollector<'r, 'a, 'hir> { + context: &'r mut LoweringContext<'a, 'hir>, parent: DefIndex, opaque_ty_id: NodeId, collect_elided_lifetimes: bool, @@ -1574,7 +1580,7 @@ impl<'a> LoweringContext<'a> { output_lifetime_params: Vec, } - 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>( &'this mut self, ) -> hir::intravisit::NestedVisitorMap<'this, 'v> { @@ -2757,8 +2763,9 @@ impl<'a> LoweringContext<'a> { let node = match p.kind { PatKind::Wild => hir::PatKind::Wild, PatKind::Ident(ref binding_mode, ident, ref sub) => { - let lower_sub = |this: &mut Self| sub.as_ref().map(|x| this.lower_pat(x)); - self.lower_pat_ident(p, binding_mode, ident, lower_sub) + let lower_sub = |this: &mut Self| sub.as_ref().map(|s| this.lower_pat(&*s)); + 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::TupleStruct(ref path, ref pats) => { diff --git a/src/librustc/hir/lowering/expr.rs b/src/librustc/hir/lowering/expr.rs index a1a37719812..08b00ce69ad 100644 --- a/src/librustc/hir/lowering/expr.rs +++ b/src/librustc/hir/lowering/expr.rs @@ -13,7 +13,7 @@ use syntax::symbol::{sym, Symbol}; use rustc_error_codes::*; -impl LoweringContext<'_> { +impl LoweringContext<'_, '_> { fn lower_exprs(&mut self, exprs: &[AstP]) -> HirVec { exprs.iter().map(|x| self.lower_expr(x)).collect() } @@ -473,7 +473,7 @@ impl LoweringContext<'_> { ret_ty: Option>, span: Span, async_gen_kind: hir::AsyncGeneratorKind, - body: impl FnOnce(&mut LoweringContext<'_>) -> hir::Expr, + body: impl FnOnce(&mut LoweringContext<'_, '_>) -> hir::Expr, ) -> hir::ExprKind { let output = match ret_ty { Some(ty) => FunctionRetTy::Ty(ty), @@ -909,7 +909,7 @@ impl LoweringContext<'_> { fn with_catch_scope(&mut self, catch_id: NodeId, f: F) -> T where - F: FnOnce(&mut LoweringContext<'_>) -> T, + F: FnOnce(&mut LoweringContext<'_, '_>) -> T, { let len = self.catch_scopes.len(); self.catch_scopes.push(catch_id); @@ -928,7 +928,7 @@ impl LoweringContext<'_> { fn with_loop_scope(&mut self, loop_id: NodeId, f: F) -> T 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. let was_in_loop_condition = self.is_in_loop_condition; @@ -953,7 +953,7 @@ impl LoweringContext<'_> { fn with_loop_condition_scope(&mut self, f: F) -> T where - F: FnOnce(&mut LoweringContext<'_>) -> T, + F: FnOnce(&mut LoweringContext<'_, '_>) -> T, { let was_in_loop_condition = self.is_in_loop_condition; self.is_in_loop_condition = true; diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index 6cae8e2cc04..a4c9394c92d 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -24,11 +24,11 @@ use syntax_pos::Span; use rustc_error_codes::*; -pub(super) struct ItemLowerer<'tcx, 'interner> { - pub(super) lctx: &'tcx mut LoweringContext<'interner>, +pub(super) struct ItemLowerer<'a, 'lowering, 'hir> { + 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(&mut self, trait_impl_ref: &Option, f: F) where F: FnOnce(&mut Self), @@ -44,8 +44,8 @@ impl<'tcx, 'interner> ItemLowerer<'tcx, 'interner> { } } -impl<'tcx, 'interner> Visitor<'tcx> for ItemLowerer<'tcx, 'interner> { - fn visit_mod(&mut self, m: &'tcx Mod, _s: Span, _attrs: &[Attribute], n: NodeId) { +impl<'a, 'lowering, 'hir> Visitor<'a> for ItemLowerer<'a, 'lowering, 'hir> { + fn visit_mod(&mut self, m: &'a Mod, _s: Span, _attrs: &[Attribute], n: NodeId) { let hir_id = self.lctx.lower_node_id(n); 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; } - fn visit_item(&mut self, item: &'tcx Item) { + fn visit_item(&mut self, item: &'a Item) { let mut item_hir_id = None; self.lctx.with_hir_id_owner(item.id, |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| { let hir_item = lctx.lower_trait_item(item); 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); } - 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| { let hir_item = lctx.lower_impl_item(item); 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 // instead of `ast::GenericParam`s. // This should only be used with generics that have already had their @@ -116,7 +116,7 @@ impl LoweringContext<'_> { fn with_parent_item_lifetime_defs( &mut self, parent_hir_id: hir::HirId, - f: impl FnOnce(&mut LoweringContext<'_>) -> T, + f: impl FnOnce(&mut LoweringContext<'_, '_>) -> T, ) -> T { let old_len = self.in_scope_lifetimes.len(); @@ -144,7 +144,7 @@ impl LoweringContext<'_> { // from their surrounding environment. fn without_in_scope_lifetime_defs( &mut self, - f: impl FnOnce(&mut LoweringContext<'_>) -> T, + f: impl FnOnce(&mut LoweringContext<'_, '_>) -> T, ) -> T { let old_in_scope_lifetimes = std::mem::replace(&mut self.in_scope_lifetimes, vec![]); @@ -1055,7 +1055,7 @@ impl LoweringContext<'_> { fn lower_body( &mut self, - f: impl FnOnce(&mut LoweringContext<'_>) -> (HirVec, hir::Expr), + f: impl FnOnce(&mut LoweringContext<'_, '_>) -> (HirVec, hir::Expr), ) -> hir::BodyId { let prev_gen_kind = self.generator_kind.take(); let (parameters, result) = f(self); @@ -1076,7 +1076,7 @@ impl LoweringContext<'_> { pub(super) fn lower_fn_body( &mut self, decl: &FnDecl, - body: impl FnOnce(&mut LoweringContext<'_>) -> hir::Expr, + body: impl FnOnce(&mut LoweringContext<'_, '_>) -> hir::Expr, ) -> hir::BodyId { self.lower_body(|this| ( decl.inputs.iter().map(|x| this.lower_param(x)).collect(), diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index b0fa844c818..f472bc6d38e 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -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. pub(super) struct NodeCollector<'a, 'hir> { /// The crate - krate: &'hir Crate, + krate: &'hir Crate<'hir>, /// Source map source_map: &'a SourceMap, @@ -99,7 +99,7 @@ where impl<'a, 'hir> NodeCollector<'a, 'hir> { pub(super) fn root(sess: &'a Session, - krate: &'hir Crate, + krate: &'hir Crate<'hir>, dep_graph: &'a DepGraph, definitions: &'a definitions::Definitions, hir_to_node_id: &'a FxHashMap, diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 69e772697f8..a44dbeb0366 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -153,20 +153,20 @@ impl<'hir> Entry<'hir> { } /// Stores a crate and any number of inlined items from other crates. -pub struct Forest { - krate: Crate, +pub struct Forest<'hir> { + krate: Crate<'hir>, pub dep_graph: DepGraph, } -impl Forest { - pub fn new(krate: Crate, dep_graph: &DepGraph) -> Forest { +impl Forest<'hir> { + pub fn new(krate: Crate<'hir>, dep_graph: &DepGraph) -> Forest<'hir> { Forest { krate, 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.krate } @@ -174,7 +174,7 @@ impl Forest { /// This is used internally in the dependency tracking system. /// Use the `krate` method to ensure your dependency on the /// crate is tracked. - pub fn untracked_krate(&self) -> &Crate { + pub fn untracked_krate(&self) -> &Crate<'hir> { &self.krate } } @@ -189,7 +189,7 @@ pub(super) type HirEntryMap<'hir> = IndexVec { /// 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 /// deref. This is a gratuitous micro-optimization. @@ -439,7 +439,7 @@ impl<'hir> Map<'hir> { self.lookup(id).cloned() } - pub fn krate(&self) -> &'hir Crate { + pub fn krate(&self) -> &'hir Crate<'hir> { 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, cstore: &CrateStoreDyn, - forest: &'hir Forest, + forest: &'hir Forest<'hir>, definitions: Definitions) -> Map<'hir> { let _prof_timer = sess.prof.generic_activity("build_hir_map"); diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 368269ff200..aa2bde07e6f 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -742,13 +742,13 @@ pub struct ModuleItems { /// /// [rustc guide]: https://rust-lang.github.io/rustc-guide/hir.html #[derive(RustcEncodable, RustcDecodable, Debug)] -pub struct Crate { +pub struct Crate<'hir> { pub module: Mod, - pub attrs: HirVec, + pub attrs: &'hir [Attribute], pub span: Span, - pub exported_macros: HirVec, + pub exported_macros: &'hir [MacroDef], // Attributes from non-exported macros, kept only for collecting the library feature list. - pub non_exported_macro_attrs: HirVec, + pub non_exported_macro_attrs: &'hir [Attribute], // N.B., we use a `BTreeMap` here so that `visit_all_items` iterates // over the ids in increasing order. In principle it should not @@ -774,7 +774,7 @@ pub struct Crate { pub modules: BTreeMap, } -impl Crate { +impl Crate<'_> { pub fn item(&self, id: HirId) -> &Item { &self.items[&id] } diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 92ad1c38fa0..fd121f6a9b7 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -52,7 +52,7 @@ pub struct NoAnn; impl PpAnn for 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> { 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. pub fn print_crate<'a>(cm: &'a SourceMap, sess: &ParseSess, - krate: &hir::Crate, + krate: &hir::Crate<'a>, filename: FileName, input: String, ann: &'a dyn PpAnn) -> String { diff --git a/src/librustc/ich/hcx.rs b/src/librustc/ich/hcx.rs index 8b35839c182..77a9bcd67a5 100644 --- a/src/librustc/ich/hcx.rs +++ b/src/librustc/ich/hcx.rs @@ -56,7 +56,7 @@ pub enum NodeIdHashingMode { /// 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. #[derive(Clone, Copy)] -struct BodyResolver<'tcx>(&'tcx hir::Crate); +struct BodyResolver<'tcx>(&'tcx hir::Crate<'tcx>); impl<'tcx> BodyResolver<'tcx> { /// 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. #[inline] pub fn new(sess: &'a Session, - krate: &'a hir::Crate, + krate: &'a hir::Crate<'a>, definitions: &'a Definitions, cstore: &'a dyn CrateStore) -> Self { diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 0054f149f8c..20bc1793dc1 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -90,8 +90,8 @@ macro_rules! late_lint_methods { fn check_body(a: &$hir hir::Body); fn check_body_post(a: &$hir hir::Body); fn check_name(a: Span, b: ast::Name); - fn check_crate(a: &$hir hir::Crate); - fn check_crate_post(a: &$hir hir::Crate); + 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_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); 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); } intravisit::walk_crate(&mut builder, krate); diff --git a/src/librustc/middle/lib_features.rs b/src/librustc/middle/lib_features.rs index e6f8521216b..c38ab525ce4 100644 --- a/src/librustc/middle/lib_features.rs +++ b/src/librustc/middle/lib_features.rs @@ -157,7 +157,7 @@ impl Visitor<'tcx> for LibFeatureCollector<'tcx> { pub fn collect(tcx: TyCtxt<'_>) -> LibFeatures { let mut collector = LibFeatureCollector::new(tcx); 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); } intravisit::walk_crate(&mut collector, krate); diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 11603f6d9c1..97e4cf72124 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -73,7 +73,7 @@ where } fn call_with_pp_support_hir(ppmode: &PpSourceMode, tcx: TyCtxt<'_>, f: F) -> A where - F: FnOnce(&dyn HirPrinterSupport<'_>, &hir::Crate) -> A, + F: FnOnce(&dyn HirPrinterSupport<'_>, &hir::Crate<'_>) -> A, { match *ppmode { PpmNormal => { diff --git a/src/librustc_incremental/assert_module_sources.rs b/src/librustc_incremental/assert_module_sources.rs index 1a675ea002c..8b692d84b11 100644 --- a/src/librustc_incremental/assert_module_sources.rs +++ b/src/librustc_incremental/assert_module_sources.rs @@ -47,7 +47,7 @@ pub fn assert_module_sources(tcx: TyCtxt<'_>) { available_cgus }; - for attr in &tcx.hir().krate().attrs { + for attr in tcx.hir().krate().attrs { ams.check_attr(attr); } }) diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs index 2a4bc41f850..e1c4c86d9d6 100644 --- a/src/librustc_interface/passes.rs +++ b/src/librustc_interface/passes.rs @@ -446,17 +446,18 @@ fn configure_and_expand_inner<'a>( Ok((krate, resolver)) } -pub fn lower_to_hir( - sess: &Session, +pub fn lower_to_hir<'res, 'tcx>( + sess: &'tcx Session, lint_store: &lint::LintStore, - resolver: &mut Resolver<'_>, - dep_graph: &DepGraph, - krate: &ast::Crate, -) -> Result { + resolver: &'res mut Resolver<'_>, + dep_graph: &'res DepGraph, + krate: &'res ast::Crate, + arena: &'tcx Arena<'tcx>, +) -> Result> { // Lower AST to HIR. let hir_forest = time(sess, "lowering AST -> HIR", || { 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 { hir_stats::print_hir_stats(&hir_crate); @@ -738,7 +739,7 @@ impl<'tcx> QueryContext<'tcx> { pub fn create_global_ctxt<'tcx>( compiler: &'tcx Compiler, lint_store: Lrc, - hir_forest: &'tcx hir::map::Forest, + hir_forest: &'tcx hir::map::Forest<'tcx>, mut resolver_outputs: ResolverOutputs, outputs: OutputFilenames, crate_name: &str, diff --git a/src/librustc_interface/queries.rs b/src/librustc_interface/queries.rs index e429b4d101a..d6de9d5f4e4 100644 --- a/src/librustc_interface/queries.rs +++ b/src/librustc_interface/queries.rs @@ -82,7 +82,7 @@ pub struct Queries<'tcx> { register_plugins: Query<(ast::Crate, Lrc)>, expansion: Query<(ast::Crate, Steal>>, Lrc)>, dep_graph: Query, - lower_to_hir: Query<(&'tcx hir::map::Forest, Steal)>, + lower_to_hir: Query<(&'tcx hir::map::Forest<'tcx>, Steal)>, prepare_outputs: Query, global_ctxt: Query>, ongoing_codegen: Query>, @@ -216,7 +216,7 @@ impl<'tcx> Queries<'tcx> { pub fn lower_to_hir( &'tcx self, - ) -> Result<&Query<(&'tcx hir::map::Forest, Steal)>> { + ) -> Result<&Query<(&'tcx hir::map::Forest<'tcx>, Steal)>> { self.lower_to_hir.compute(|| { let expansion_result = self.expansion()?; let peeked = expansion_result.peek(); @@ -229,7 +229,8 @@ impl<'tcx> Queries<'tcx> { lint_store, resolver, &*self.dep_graph()?.peek(), - &krate + &krate, + &self.arena, ) })?; let hir = self.arena.alloc(hir); diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 4cf694631d0..2e4f8e7aabc 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -378,10 +378,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { 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"); - 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)); if !has_doc { cx.span_lint(MISSING_DOCS, diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index d963323342c..5649789e2c5 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -342,7 +342,7 @@ impl<'tcx> EncodeContext<'tcx> { 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); 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); } } diff --git a/src/librustc_passes/dead.rs b/src/librustc_passes/dead.rs index db661e7f4d2..fb5052fedb2 100644 --- a/src/librustc_passes/dead.rs +++ b/src/librustc_passes/dead.rs @@ -355,7 +355,7 @@ fn has_allow_dead_code_or_lang_attr( // * Implementation of a trait method struct LifeSeeder<'k, 'tcx> { worklist: Vec, - krate: &'k hir::Crate, + krate: &'k hir::Crate<'k>, tcx: TyCtxt<'tcx>, // see `MarkSymbolVisitor::struct_constructors` struct_constructors: FxHashMap, @@ -429,7 +429,7 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> { fn create_and_seed_worklist<'tcx>( tcx: TyCtxt<'tcx>, access_levels: &privacy::AccessLevels, - krate: &hir::Crate, + krate: &hir::Crate<'_>, ) -> (Vec, FxHashMap) { let worklist = access_levels.map.iter().filter_map(|(&id, level)| { if level >= &privacy::AccessLevel::Reachable { @@ -457,7 +457,7 @@ fn create_and_seed_worklist<'tcx>( fn find_live<'tcx>( tcx: TyCtxt<'tcx>, access_levels: &privacy::AccessLevels, - krate: &hir::Crate, + krate: &hir::Crate<'_>, ) -> FxHashSet { let (worklist, struct_constructors) = create_and_seed_worklist(tcx, access_levels, krate); let mut symbol_visitor = MarkSymbolVisitor { diff --git a/src/librustc_passes/hir_stats.rs b/src/librustc_passes/hir_stats.rs index 66ceb4212c8..60c486b30d4 100644 --- a/src/librustc_passes/hir_stats.rs +++ b/src/librustc_passes/hir_stats.rs @@ -23,12 +23,12 @@ struct NodeData { } struct StatCollector<'k> { - krate: Option<&'k hir::Crate>, + krate: Option<&'k hir::Crate<'k>>, data: FxHashMap<&'static str, NodeData>, seen: FxHashSet, } -pub fn print_hir_stats(krate: &hir::Crate) { +pub fn print_hir_stats(krate: &hir::Crate<'_>) { let mut collector = StatCollector { krate: Some(krate), data: FxHashMap::default(), diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 9cd8c9abfd7..1ab703db83c 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -1076,7 +1076,7 @@ struct UsePlacementFinder<'tcx> { impl UsePlacementFinder<'tcx> { fn check( tcx: TyCtxt<'tcx>, - krate: &'tcx hir::Crate, + krate: &'tcx hir::Crate<'tcx>, target_module: hir::HirId, ) -> (Option, bool) { let mut finder = UsePlacementFinder { diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index aea9b7c38ef..7ec7f460987 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -72,7 +72,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { pub fn visit(mut self, krate: &'tcx hir::Crate) -> Module<'tcx> { let mut module = self.visit_mod_contents(krate.span, - &krate.attrs, + krate.attrs, &Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityKind::Public }, 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, + fn visit_mod_contents(&mut self, span: Span, attrs: &'tcx [ast::Attribute], vis: &'tcx hir::Visibility, id: hir::HirId, m: &'tcx hir::Mod, name: Option) -> Module<'tcx> { From 084e6722f97560891cfe70dc7ab649f22eaf9aae Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 28 Nov 2019 19:28:50 +0100 Subject: [PATCH 02/12] Use Arena inside hir::Item. --- src/librustc/arena.rs | 5 ++ src/librustc/hir/check_attr.rs | 10 +-- src/librustc/hir/intravisit.rs | 8 +-- src/librustc/hir/itemlikevisit.rs | 8 +-- src/librustc/hir/lowering.rs | 6 +- src/librustc/hir/lowering/item.rs | 71 ++++++++++--------- src/librustc/hir/map/blocks.rs | 2 +- src/librustc/hir/map/collector.rs | 2 +- src/librustc/hir/map/hir_id_validator.rs | 2 +- src/librustc/hir/map/mod.rs | 6 +- src/librustc/hir/mod.rs | 42 +++++------ src/librustc/hir/print.rs | 14 ++-- src/librustc/ich/impls_hir.rs | 2 +- src/librustc/infer/error_reporting/mod.rs | 2 +- src/librustc/lint/context.rs | 2 +- src/librustc/lint/mod.rs | 6 +- src/librustc/middle/diagnostic_items.rs | 2 +- src/librustc/middle/lang_items.rs | 2 +- src/librustc/middle/reachable.rs | 4 +- src/librustc/middle/resolve_lifetime.rs | 4 +- src/librustc/middle/stability.rs | 8 +-- src/librustc/ty/wf.rs | 4 +- .../symbol_names_test.rs | 2 +- src/librustc_incremental/assert_dep_graph.rs | 2 +- .../persist/dirty_clean.rs | 2 +- src/librustc_interface/proc_macro_decls.rs | 2 +- src/librustc_lint/builtin.rs | 28 ++++---- src/librustc_lint/nonstandard_style.rs | 4 +- src/librustc_lint/types.rs | 2 +- src/librustc_metadata/foreign_modules.rs | 2 +- src/librustc_metadata/link_args.rs | 2 +- src/librustc_metadata/native_libs.rs | 2 +- src/librustc_metadata/rmeta/encoder.rs | 8 +-- src/librustc_mir/build/mod.rs | 3 + src/librustc_mir/monomorphize/collector.rs | 4 +- src/librustc_passes/dead.rs | 10 +-- src/librustc_passes/entry.rs | 6 +- src/librustc_passes/hir_stats.rs | 2 +- src/librustc_passes/layout_test.rs | 4 +- src/librustc_plugin_impl/build.rs | 2 +- src/librustc_privacy/lib.rs | 24 +++---- src/librustc_save_analysis/lib.rs | 4 +- src/librustc_traits/lowering/mod.rs | 2 +- src/librustc_typeck/check/method/suggest.rs | 2 +- src/librustc_typeck/check/mod.rs | 6 +- src/librustc_typeck/check/wfcheck.rs | 14 ++-- src/librustc_typeck/check_unused.rs | 4 +- .../coherence/inherent_impls.rs | 4 +- .../coherence/inherent_impls_overlap.rs | 2 +- src/librustc_typeck/coherence/orphan.rs | 2 +- src/librustc_typeck/coherence/unsafety.rs | 4 +- src/librustc_typeck/collect.rs | 10 ++- src/librustc_typeck/impl_wf_check.rs | 2 +- .../outlives/implicit_infer.rs | 2 +- src/librustc_typeck/outlives/test.rs | 2 +- src/librustc_typeck/variance/constraints.rs | 2 +- src/librustc_typeck/variance/terms.rs | 2 +- src/librustc_typeck/variance/test.rs | 2 +- src/librustdoc/doctree.rs | 9 ++- src/librustdoc/visit_ast.rs | 8 +-- 60 files changed, 208 insertions(+), 198 deletions(-) diff --git a/src/librustc/arena.rs b/src/librustc/arena.rs index 59d57c6ae24..d95e5f64f0c 100644 --- a/src/librustc/arena.rs +++ b/src/librustc/arena.rs @@ -125,7 +125,12 @@ macro_rules! arena_types { // HIR nodes arenas [few] hir_forest: rustc::hir::map::Forest<$tcx>, [] attribute: syntax::ast::Attribute, + [] global_asm: rustc::hir::GlobalAsm, + [] impl_item_ref: rustc::hir::ImplItemRef, [] macro_def: rustc::hir::MacroDef, + [] path: rustc::hir::Path, + [] trait_item_ref: rustc::hir::TraitItemRef, + [] ty: rustc::hir::Ty, ], $tcx); ) } diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index ea1c585176d..d50d60e88c2 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -86,7 +86,7 @@ impl Display for Target { } impl Target { - pub(crate) fn from_item(item: &Item) -> Target { + pub(crate) fn from_item(item: &Item<'_>) -> Target { match item.kind { ItemKind::ExternCrate(..) => Target::ExternCrate, ItemKind::Use(..) => Target::Use, @@ -161,7 +161,7 @@ impl CheckAttrVisitor<'tcx> { attrs: &HirVec, span: &Span, target: Target, - item: Option<&Item>, + item: Option<&Item<'_>>, ) { let mut is_valid = true; for attr in attrs { @@ -335,7 +335,7 @@ impl CheckAttrVisitor<'tcx> { attrs: &HirVec, span: &Span, target: Target, - item: Option<&Item>, + item: Option<&Item<'_>>, ) { // Extract the names of all repr hints, e.g., [foo, bar, align] for: // ``` @@ -492,7 +492,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> { NestedVisitorMap::OnlyBodies(&self.tcx.hir()) } - fn visit_item(&mut self, item: &'tcx Item) { + fn visit_item(&mut self, item: &'tcx Item<'tcx>) { let target = Target::from_item(item); self.check_attributes(item.hir_id, &item.attrs, &item.span, target, Some(item)); intravisit::walk_item(self, item) @@ -527,7 +527,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> { } } -fn is_c_like_enum(item: &Item) -> bool { +fn is_c_like_enum(item: &Item<'_>) -> bool { if let ItemKind::Enum(ref def, _) = item.kind { for variant in &def.variants { match variant.data { diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index e71e05678f3..28c8e58feaf 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -218,7 +218,7 @@ pub trait Visitor<'v>: Sized { /// Visits the top-level item and (optionally) nested items / impl items. See /// `visit_nested_item` for details. - fn visit_item(&mut self, i: &'v Item) { + fn visit_item(&mut self, i: &'v Item<'v>) { walk_item(self, i) } @@ -462,7 +462,7 @@ pub fn walk_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Param) { walk_list!(visitor, visit_attribute, ¶m.attrs); } -pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { +pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) { visitor.visit_vis(&item.vis); visitor.visit_ident(item.ident); match item.kind { @@ -527,7 +527,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { ref generics, ref opt_trait_reference, ref typ, - ref impl_item_refs + impl_item_refs ) => { visitor.visit_id(item.hir_id); visitor.visit_generics(generics); @@ -542,7 +542,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { visitor.visit_variant_data(struct_definition, item.ident.name, generics, item.hir_id, item.span); } - ItemKind::Trait(.., ref generics, ref bounds, ref trait_item_refs) => { + ItemKind::Trait(.., ref generics, ref bounds, trait_item_refs) => { visitor.visit_id(item.hir_id); visitor.visit_generics(generics); walk_list!(visitor, visit_param_bound, bounds); diff --git a/src/librustc/hir/itemlikevisit.rs b/src/librustc/hir/itemlikevisit.rs index 39dd46c2d29..4d3fd5e05b4 100644 --- a/src/librustc/hir/itemlikevisit.rs +++ b/src/librustc/hir/itemlikevisit.rs @@ -45,7 +45,7 @@ use super::intravisit::Visitor; /// existing `fn visit_nested` methods to see where changes are /// needed. pub trait ItemLikeVisitor<'hir> { - fn visit_item(&mut self, item: &'hir Item); + fn visit_item(&mut self, item: &'hir Item<'hir>); fn visit_trait_item(&mut self, trait_item: &'hir TraitItem); fn visit_impl_item(&mut self, impl_item: &'hir ImplItem); } @@ -65,7 +65,7 @@ impl<'v, 'hir, V> DeepVisitor<'v, V> impl<'v, 'hir, V> ItemLikeVisitor<'hir> for DeepVisitor<'v, V> where V: Visitor<'hir> { - fn visit_item(&mut self, item: &'hir Item) { + fn visit_item(&mut self, item: &'hir Item<'hir>) { self.visitor.visit_item(item); } @@ -80,7 +80,7 @@ impl<'v, 'hir, V> ItemLikeVisitor<'hir> for DeepVisitor<'v, V> /// A parallel variant of `ItemLikeVisitor`. pub trait ParItemLikeVisitor<'hir> { - fn visit_item(&self, item: &'hir Item); + fn visit_item(&self, item: &'hir Item<'hir>); fn visit_trait_item(&self, trait_item: &'hir TraitItem); fn visit_impl_item(&self, impl_item: &'hir ImplItem); } @@ -95,7 +95,7 @@ pub struct ParDeepVisitor(pub V); impl<'hir, V> ParItemLikeVisitor<'hir> for ParDeepVisitor where V: IntoVisitor<'hir> { - fn visit_item(&self, item: &'hir Item) { + fn visit_item(&self, item: &'hir Item<'hir>) { self.0.into_visitor().visit_item(item); } diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index a8f0c90ab3a..6ab2bb53e2a 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -95,7 +95,7 @@ pub struct LoweringContext<'a, 'hir: 'a> { arena: &'hir Arena<'hir>, /// The items being lowered are collected here. - items: BTreeMap, + items: BTreeMap>, trait_items: BTreeMap, impl_items: BTreeMap, @@ -566,7 +566,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } } - fn insert_item(&mut self, item: hir::Item) { + fn insert_item(&mut self, item: hir::Item<'hir>) { let id = item.hir_id; // FIXME: Use `debug_asset-rt`. assert_eq!(id.local_id, hir::ItemLocalId::from_u32(0)); @@ -873,7 +873,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { // for them. fn with_in_scope_lifetime_defs(&mut self, params: &[GenericParam], f: F) -> T where - F: FnOnce(&mut LoweringContext<'_, '_>) -> T, + F: FnOnce(&mut LoweringContext<'_, 'hir>) -> T, { let old_len = self.in_scope_lifetimes.len(); let lt_def_names = params.iter().filter_map(|param| match param.kind { diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index a4c9394c92d..7e5ac42d13e 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -107,7 +107,7 @@ impl<'a, 'lowering, 'hir> Visitor<'a> for ItemLowerer<'a, 'lowering, 'hir> { } } -impl LoweringContext<'_, '_> { +impl LoweringContext<'_, 'hir> { // Same as the method above, but accepts `hir::GenericParam`s // instead of `ast::GenericParam`s. // This should only be used with generics that have already had their @@ -225,7 +225,7 @@ impl LoweringContext<'_, '_> { } } - pub fn lower_item(&mut self, i: &Item) -> Option { + pub fn lower_item(&mut self, i: &Item) -> Option> { let mut ident = i.ident; let mut vis = self.lower_visibility(&i.vis, None); let attrs = self.lower_attrs(&i.attrs); @@ -269,7 +269,7 @@ impl LoweringContext<'_, '_> { attrs: &hir::HirVec, vis: &mut hir::Visibility, i: &ItemKind, - ) -> hir::ItemKind { + ) -> hir::ItemKind<'hir> { match *i { ItemKind::ExternCrate(orig_name) => hir::ItemKind::ExternCrate(orig_name), ItemKind::Use(ref use_tree) => { @@ -282,29 +282,31 @@ impl LoweringContext<'_, '_> { self.lower_use_tree(use_tree, &prefix, id, vis, ident, attrs) } ItemKind::Static(ref t, m, ref e) => { + let ty = self.lower_ty( + t, + if self.sess.features_untracked().impl_trait_in_bindings { + ImplTraitContext::OpaqueTy(None) + } else { + ImplTraitContext::Disallowed(ImplTraitPosition::Binding) + } + ); hir::ItemKind::Static( - self.lower_ty( - t, - if self.sess.features_untracked().impl_trait_in_bindings { - ImplTraitContext::OpaqueTy(None) - } else { - ImplTraitContext::Disallowed(ImplTraitPosition::Binding) - } - ), + self.arena.alloc(ty.into_inner()), m, self.lower_const_body(span, Some(e)), ) } ItemKind::Const(ref t, ref e) => { + let ty = self.lower_ty( + t, + if self.sess.features_untracked().impl_trait_in_bindings { + ImplTraitContext::OpaqueTy(None) + } else { + ImplTraitContext::Disallowed(ImplTraitPosition::Binding) + } + ); hir::ItemKind::Const( - self.lower_ty( - t, - if self.sess.features_untracked().impl_trait_in_bindings { - ImplTraitContext::OpaqueTy(None) - } else { - ImplTraitContext::Disallowed(ImplTraitPosition::Binding) - } - ), + self.arena.alloc(ty.into_inner()), self.lower_const_body(span, Some(e)) ) } @@ -346,7 +348,7 @@ impl LoweringContext<'_, '_> { None => { let ty = self.lower_ty(ty, ImplTraitContext::disallowed()); let generics = self.lower_generics(generics, ImplTraitContext::disallowed()); - hir::ItemKind::TyAlias(ty, generics) + hir::ItemKind::TyAlias(self.arena.alloc(ty.into_inner()), generics) }, Some(bounds) => { let ty = hir::OpaqueTy { @@ -434,10 +436,11 @@ impl LoweringContext<'_, '_> { let new_impl_items = self.with_in_scope_lifetime_defs( &ast_generics.params, |this| { - impl_items - .iter() - .map(|item| this.lower_impl_item_ref(item)) - .collect() + this.arena.alloc_from_iter( + impl_items + .iter() + .map(|item| this.lower_impl_item_ref(item)) + ) }, ); @@ -447,16 +450,16 @@ impl LoweringContext<'_, '_> { self.lower_defaultness(defaultness, true /* [1] */), generics, trait_ref, - lowered_ty, + self.arena.alloc(lowered_ty.into_inner()), new_impl_items, ) } ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, ref items) => { let bounds = self.lower_param_bounds(bounds, ImplTraitContext::disallowed()); - let items = items + let items = self.arena.alloc_from_iter(items .iter() .map(|item| self.lower_trait_item_ref(item)) - .collect(); + ); hir::ItemKind::Trait( is_auto, unsafety, @@ -485,7 +488,7 @@ impl LoweringContext<'_, '_> { vis: &mut hir::Visibility, ident: &mut Ident, attrs: &hir::HirVec, - ) -> hir::ItemKind { + ) -> hir::ItemKind<'hir> { debug!("lower_use_tree(tree={:?})", tree); debug!("lower_use_tree: vis = {:?}", vis); @@ -540,7 +543,7 @@ impl LoweringContext<'_, '_> { let res = this.lower_res(res); let path = this.lower_path_extra(res, &path, ParamMode::Explicit, None); - let kind = hir::ItemKind::Use(P(path), hir::UseKind::Single); + let kind = hir::ItemKind::Use(this.arena.alloc(path), hir::UseKind::Single); let vis = this.rebuild_vis(&vis); this.insert_item( @@ -556,11 +559,11 @@ impl LoweringContext<'_, '_> { }); } - let path = P(self.lower_path_extra(ret_res, &path, ParamMode::Explicit, None)); + let path = self.arena.alloc(self.lower_path_extra(ret_res, &path, ParamMode::Explicit, None)); hir::ItemKind::Use(path, hir::UseKind::Single) } UseTreeKind::Glob => { - let path = P(self.lower_path( + let path = self.arena.alloc(self.lower_path( id, &Path { segments, @@ -663,7 +666,7 @@ impl LoweringContext<'_, '_> { let res = self.expect_full_res_from_use(id).next().unwrap_or(Res::Err); let res = self.lower_res(res); - let path = P(self.lower_path_extra(res, &prefix, ParamMode::Explicit, None)); + let path = self.arena.alloc(self.lower_path_extra(res, &prefix, ParamMode::Explicit, None)); hir::ItemKind::Use(path, hir::UseKind::ListStem) } } @@ -748,8 +751,8 @@ impl LoweringContext<'_, '_> { } } - fn lower_global_asm(&mut self, ga: &GlobalAsm) -> P { - P(hir::GlobalAsm { asm: ga.asm }) + fn lower_global_asm(&mut self, ga: &GlobalAsm) -> &'hir hir::GlobalAsm { + self.arena.alloc(hir::GlobalAsm { asm: ga.asm }) } fn lower_variant(&mut self, v: &Variant) -> hir::Variant { diff --git a/src/librustc/hir/map/blocks.rs b/src/librustc/hir/map/blocks.rs index 8f9f3983262..ee2c3b9879f 100644 --- a/src/librustc/hir/map/blocks.rs +++ b/src/librustc/hir/map/blocks.rs @@ -35,7 +35,7 @@ pub struct FnLikeNode<'a> { node: Node<'a> } /// corresponds to some FnLikeNode. trait MaybeFnLike { fn is_fn_like(&self) -> bool; } -impl MaybeFnLike for ast::Item { +impl MaybeFnLike for ast::Item<'_> { fn is_fn_like(&self) -> bool { match self.kind { ast::ItemKind::Fn(..) => true, diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index f472bc6d38e..b56adf25e8a 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -367,7 +367,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> { }); } - fn visit_item(&mut self, i: &'hir Item) { + fn visit_item(&mut self, i: &'hir Item<'hir>) { debug!("visit_item: {:?}", i); debug_assert_eq!(i.hir_id.owner, self.definitions.opt_def_index(self.hir_to_node_id[&i.hir_id]).unwrap()); diff --git a/src/librustc/hir/map/hir_id_validator.rs b/src/librustc/hir/map/hir_id_validator.rs index b66c2ce1178..865b0198493 100644 --- a/src/librustc/hir/map/hir_id_validator.rs +++ b/src/librustc/hir/map/hir_id_validator.rs @@ -53,7 +53,7 @@ impl<'a, 'hir> OuterVisitor<'a, 'hir> { } impl<'a, 'hir> ItemLikeVisitor<'hir> for OuterVisitor<'a, 'hir> { - fn visit_item(&mut self, i: &'hir hir::Item) { + fn visit_item(&mut self, i: &'hir hir::Item<'hir>) { let mut inner_visitor = self.new_inner_visitor(self.hir_map); inner_visitor.check(i.hir_id, |this| intravisit::walk_item(this, i)); } diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index a44dbeb0366..982753da5f6 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -959,7 +959,7 @@ impl<'hir> Map<'hir> { bug!("expected foreign mod or inlined parent, found {}", self.node_to_string(parent)) } - pub fn expect_item(&self, id: HirId) -> &'hir Item { + pub fn expect_item(&self, id: HirId) -> &'hir Item<'hir> { match self.find(id) { // read recorded by `find` Some(Node::Item(item)) => item, _ => bug!("expected item, found {}", self.node_to_string(id)) @@ -1213,7 +1213,7 @@ impl<'a> NodesMatchingSuffix<'a> { id = parent; } - fn item_is_mod(item: &Item) -> bool { + fn item_is_mod(item: &Item<'_>) -> bool { match item.kind { ItemKind::Mod(_) => true, _ => false, @@ -1248,7 +1248,7 @@ trait Named { impl Named for Spanned { fn name(&self) -> Name { self.node.name() } } -impl Named for Item { fn name(&self) -> Name { self.ident.name } } +impl Named for Item<'_> { fn name(&self) -> Name { self.ident.name } } impl Named for ForeignItem { fn name(&self) -> Name { self.ident.name } } impl Named for Variant { fn name(&self) -> Name { self.ident.name } } impl Named for StructField { fn name(&self) -> Name { self.ident.name } } diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index aa2bde07e6f..4fb9f27c27d 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -756,7 +756,7 @@ pub struct Crate<'hir> { // does, because it can affect the order in which errors are // detected, which in turn can make compile-fail tests yield // slightly different results. - pub items: BTreeMap, + pub items: BTreeMap>, pub trait_items: BTreeMap, pub impl_items: BTreeMap, @@ -774,8 +774,8 @@ pub struct Crate<'hir> { pub modules: BTreeMap, } -impl Crate<'_> { - pub fn item(&self, id: HirId) -> &Item { +impl Crate<'hir> { + pub fn item(&self, id: HirId) -> &Item<'hir> { &self.items[&id] } @@ -787,6 +787,12 @@ impl Crate<'_> { &self.impl_items[&id] } + pub fn body(&self, id: BodyId) -> &Body { + &self.bodies[&id] + } +} + +impl Crate<'_> { /// Visits all items in the crate in some deterministic (but /// unspecified) order. If you just need to process every item, /// but don't care about nesting, this method is the best choice. @@ -829,10 +835,6 @@ impl Crate<'_> { }); }); } - - pub fn body(&self, id: BodyId) -> &Body { - &self.bodies[&id] - } } /// A macro definition, in this crate or imported from another. @@ -2440,11 +2442,11 @@ pub struct ItemId { /// /// The name might be a dummy name in case of anonymous items #[derive(RustcEncodable, RustcDecodable, Debug)] -pub struct Item { +pub struct Item<'hir> { pub ident: Ident, pub hir_id: HirId, pub attrs: HirVec, - pub kind: ItemKind, + pub kind: ItemKind<'hir>, pub vis: Visibility, pub span: Span, } @@ -2467,7 +2469,7 @@ impl FnHeader { } #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] -pub enum ItemKind { +pub enum ItemKind<'hir> { /// An `extern crate` item, with optional *original* crate name if the crate was renamed. /// /// E.g., `extern crate foo` or `extern crate foo_bar as foo`. @@ -2478,12 +2480,12 @@ pub enum ItemKind { /// or just /// /// `use foo::bar::baz;` (with `as baz` implicitly on the right). - Use(P, UseKind), + Use(&'hir Path, UseKind), /// A `static` item. - Static(P, Mutability, BodyId), + Static(&'hir Ty, Mutability, BodyId), /// A `const` item. - Const(P, BodyId), + Const(&'hir Ty, BodyId), /// A function declaration. Fn(FnSig, Generics, BodyId), /// A module. @@ -2491,9 +2493,9 @@ pub enum ItemKind { /// An external module, e.g. `extern { .. }`. ForeignMod(ForeignMod), /// Module-level inline assembly (from `global_asm!`). - GlobalAsm(P), + GlobalAsm(&'hir GlobalAsm), /// A type alias, e.g., `type Foo = Bar`. - TyAlias(P, Generics), + TyAlias(&'hir Ty, Generics), /// An opaque `impl Trait` type alias, e.g., `type Foo = impl Bar;`. OpaqueTy(OpaqueTy), /// An enum definition, e.g., `enum Foo {C, D}`. @@ -2503,7 +2505,7 @@ pub enum ItemKind { /// A union definition, e.g., `union Foo {x: A, y: B}`. Union(VariantData, Generics), /// A trait definition. - Trait(IsAuto, Unsafety, Generics, GenericBounds, HirVec), + Trait(IsAuto, Unsafety, Generics, GenericBounds, &'hir [TraitItemRef]), /// A trait alias. TraitAlias(Generics, GenericBounds), @@ -2513,11 +2515,11 @@ pub enum ItemKind { Defaultness, Generics, Option, // (optional) trait this impl implements - P, // self - HirVec), + &'hir Ty, // self + &'hir [ImplItemRef]), } -impl ItemKind { +impl ItemKind<'_> { pub fn descriptive_variant(&self) -> &str { match *self { ItemKind::ExternCrate(..) => "extern crate", @@ -2785,7 +2787,7 @@ impl CodegenFnAttrs { #[derive(Copy, Clone, Debug)] pub enum Node<'hir> { Param(&'hir Param), - Item(&'hir Item), + Item(&'hir Item<'hir>), ForeignItem(&'hir ForeignItem), TraitItem(&'hir TraitItem), ImplItem(&'hir ImplItem), diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index fd121f6a9b7..e6398b8c2e9 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -21,7 +21,7 @@ use std::vec; pub enum AnnNode<'a> { Name(&'a ast::Name), Block(&'a hir::Block), - Item(&'a hir::Item), + Item(&'a hir::Item<'a>), SubItem(hir::HirId), Expr(&'a hir::Expr), Pat(&'a hir::Pat), @@ -43,7 +43,7 @@ pub trait PpAnn { } fn post(&self, _state: &mut State<'_>, _node: AnnNode<'_>) { } - fn try_fetch_item(&self, _: hir::HirId) -> Option<&hir::Item> { + fn try_fetch_item(&self, _: hir::HirId) -> Option<&hir::Item<'_>> { None } } @@ -53,7 +53,7 @@ impl PpAnn for NoAnn {} pub const NO_ANN: &dyn PpAnn = &NoAnn; 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)) } fn nested(&self, state: &mut State<'_>, nested: Nested) { @@ -445,7 +445,7 @@ impl<'a> State<'a> { fn print_item_type( &mut self, - item: &hir::Item, + item: &hir::Item<'_>, generics: &hir::Generics, inner: impl Fn(&mut Self), ) { @@ -462,7 +462,7 @@ impl<'a> State<'a> { } /// Pretty-print an item - pub fn print_item(&mut self, item: &hir::Item) { + pub fn print_item(&mut self, item: &hir::Item<'_>) { self.hardbreak_if_not_bol(); self.maybe_print_comment(item.span.lo()); self.print_outer_attributes(&item.attrs); @@ -601,7 +601,7 @@ impl<'a> State<'a> { ref generics, ref opt_trait, ref ty, - ref impl_items) => { + impl_items) => { self.head(""); self.print_visibility(&item.vis); self.print_defaultness(defaultness); @@ -634,7 +634,7 @@ impl<'a> State<'a> { } self.bclose(item.span); } - hir::ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, ref trait_items) => { + hir::ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, trait_items) => { self.head(""); self.print_visibility(&item.vis); self.print_is_auto(is_auto); diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 066359bd4e0..f2e893ec055 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -245,7 +245,7 @@ impl<'a> HashStable> for hir::Mod { } } -impl<'a> HashStable> for hir::Item { +impl<'a> HashStable> for hir::Item<'_> { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let hir::Item { ident, diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index c9d57706d55..1a1c718e55a 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -252,7 +252,7 @@ impl<'tcx> TyCtxt<'tcx> { } } - fn item_scope_tag(item: &hir::Item) -> &'static str { + fn item_scope_tag(item: &hir::Item<'_>) -> &'static str { match item.kind { hir::ItemKind::Impl(..) => "impl", hir::ItemKind::Struct(..) => "struct", diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 0fdd509a0bb..4b7d2f67332 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -930,7 +930,7 @@ for LateContextAndPass<'a, 'tcx, T> { lint_callback!(self, check_body_post, body); } - fn visit_item(&mut self, it: &'tcx hir::Item) { + fn visit_item(&mut self, it: &'tcx hir::Item<'tcx>) { let generics = self.context.generics.take(); self.context.generics = it.kind.generics(); self.with_lint_attrs(it.hir_id, &it.attrs, |cx| { diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 20bc1793dc1..c8dc761eef9 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -96,8 +96,8 @@ macro_rules! late_lint_methods { 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_post(a: &$hir hir::ForeignItem); - fn check_item(a: &$hir hir::Item); - fn check_item_post(a: &$hir hir::Item); + fn check_item(a: &$hir hir::Item<$hir>); + fn check_item_post(a: &$hir hir::Item<$hir>); fn check_local(a: &$hir hir::Local); fn check_block(a: &$hir hir::Block); fn check_block_post(a: &$hir hir::Block); @@ -604,7 +604,7 @@ impl intravisit::Visitor<'tcx> for LintLevelMapBuilder<'_, 'tcx> { }); } - fn visit_item(&mut self, it: &'tcx hir::Item) { + fn visit_item(&mut self, it: &'tcx hir::Item<'tcx>) { self.with_lint_attrs(it.hir_id, &it.attrs, |builder| { intravisit::walk_item(builder, it); }); diff --git a/src/librustc/middle/diagnostic_items.rs b/src/librustc/middle/diagnostic_items.rs index dfae169b278..57b1f09626f 100644 --- a/src/librustc/middle/diagnostic_items.rs +++ b/src/librustc/middle/diagnostic_items.rs @@ -25,7 +25,7 @@ struct DiagnosticItemCollector<'tcx> { } impl<'v, 'tcx> ItemLikeVisitor<'v> for DiagnosticItemCollector<'tcx> { - fn visit_item(&mut self, item: &hir::Item) { + fn visit_item(&mut self, item: &hir::Item<'_>) { self.observe_item(&item.attrs, item.hir_id); } diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 6f7a022eccf..cfb54b15b3b 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -113,7 +113,7 @@ struct LanguageItemCollector<'tcx> { } impl ItemLikeVisitor<'v> for LanguageItemCollector<'tcx> { - fn visit_item(&mut self, item: &hir::Item) { + fn visit_item(&mut self, item: &hir::Item<'_>) { if let Some((value, span)) = extract(&item.attrs) { let actual_target = Target::from_item(item); match self.item_refs.get(&*value.as_str()).cloned() { diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index f77f5a72e60..9f045a59df6 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -27,7 +27,7 @@ use crate::hir::intravisit; // Returns true if the given item must be inlined because it may be // monomorphized or it was marked with `#[inline]`. This will only return // true for functions. -fn item_might_be_inlined(tcx: TyCtxt<'tcx>, item: &hir::Item, attrs: CodegenFnAttrs) -> bool { +fn item_might_be_inlined(tcx: TyCtxt<'tcx>, item: &hir::Item<'_>, attrs: CodegenFnAttrs) -> bool { if attrs.requests_inline() { return true } @@ -349,7 +349,7 @@ struct CollectPrivateImplItemsVisitor<'a, 'tcx> { } impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx> { - fn visit_item(&mut self, item: &hir::Item) { + fn visit_item(&mut self, item: &hir::Item<'_>) { // Anything which has custom linkage gets thrown on the worklist no // matter where it is in the crate, along with "special std symbols" // which are currently akin to allocator symbols. diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index c13c44c413d..4fd117b5980 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -421,7 +421,7 @@ fn krate(tcx: TyCtxt<'_>) -> NamedRegionMap { /// In traits, there is an implicit `Self` type parameter which comes before the generics. /// We have to account for this when computing the index of the other generic parameters. /// This function returns whether there is such an implicit parameter defined on the given item. -fn sub_items_have_self_param(node: &hir::ItemKind) -> bool { +fn sub_items_have_self_param(node: &hir::ItemKind<'_>) -> bool { match *node { hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..) => true, @@ -454,7 +454,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { replace(&mut self.labels_in_fn, saved); } - fn visit_item(&mut self, item: &'tcx hir::Item) { + fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { match item.kind { hir::ItemKind::Fn(ref sig, ref generics, _) => { self.visit_early_late(None, &sig.decl, generics, |this| { diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 51756084f24..6aa84b59338 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -254,7 +254,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { NestedVisitorMap::All(&self.tcx.hir()) } - fn visit_item(&mut self, i: &'tcx Item) { + fn visit_item(&mut self, i: &'tcx Item<'tcx>) { let orig_in_trait_impl = self.in_trait_impl; let mut kind = AnnotationKind::Required; match i.kind { @@ -354,7 +354,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> { NestedVisitorMap::OnlyBodies(&self.tcx.hir()) } - fn visit_item(&mut self, i: &'tcx Item) { + fn visit_item(&mut self, i: &'tcx Item<'tcx>) { match i.kind { // Inherent impls and foreign modules serve only as containers for other items, // they don't have their own stability. They still can be annotated as unstable @@ -816,7 +816,7 @@ impl Visitor<'tcx> for Checker<'tcx> { NestedVisitorMap::OnlyBodies(&self.tcx.hir()) } - fn visit_item(&mut self, item: &'tcx hir::Item) { + fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { match item.kind { hir::ItemKind::ExternCrate(_) => { // compiler-generated `extern crate` items have a dummy span. @@ -834,7 +834,7 @@ impl Visitor<'tcx> for Checker<'tcx> { // For implementations of traits, check the stability of each item // individually as it's possible to have a stable trait with unstable // items. - hir::ItemKind::Impl(.., Some(ref t), _, ref impl_item_refs) => { + hir::ItemKind::Impl(.., Some(ref t), _, impl_item_refs) => { if let Res::Def(DefKind::Trait, trait_did) = t.path.res { for impl_item_ref in impl_item_refs { let impl_item = self.tcx.hir().impl_item(impl_item_ref.id); diff --git a/src/librustc/ty/wf.rs b/src/librustc/ty/wf.rs index 276fc8c1dec..8af98c6117e 100644 --- a/src/librustc/ty/wf.rs +++ b/src/librustc/ty/wf.rs @@ -50,7 +50,7 @@ pub fn trait_obligations<'a, 'tcx>( body_id: hir::HirId, trait_ref: &ty::TraitRef<'tcx>, span: Span, - item: Option<&'tcx hir::Item>, + item: Option<&'tcx hir::Item<'tcx>>, ) -> Vec> { let mut wf = WfPredicates { infcx, param_env, body_id, span, out: vec![], item }; wf.compute_trait_ref(trait_ref, Elaborate::All); @@ -111,7 +111,7 @@ struct WfPredicates<'a, 'tcx> { body_id: hir::HirId, span: Span, out: Vec>, - item: Option<&'tcx hir::Item>, + item: Option<&'tcx hir::Item<'tcx>>, } /// Controls whether we "elaborate" supertraits and so forth on the WF diff --git a/src/librustc_codegen_utils/symbol_names_test.rs b/src/librustc_codegen_utils/symbol_names_test.rs index 51269be4e9f..d468717fe7c 100644 --- a/src/librustc_codegen_utils/symbol_names_test.rs +++ b/src/librustc_codegen_utils/symbol_names_test.rs @@ -57,7 +57,7 @@ impl SymbolNamesTest<'tcx> { } impl hir::itemlikevisit::ItemLikeVisitor<'tcx> for SymbolNamesTest<'tcx> { - fn visit_item(&mut self, item: &'tcx hir::Item) { + fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { self.process_attrs(item.hir_id); } diff --git a/src/librustc_incremental/assert_dep_graph.rs b/src/librustc_incremental/assert_dep_graph.rs index e3e3b0b1748..8b016b12550 100644 --- a/src/librustc_incremental/assert_dep_graph.rs +++ b/src/librustc_incremental/assert_dep_graph.rs @@ -162,7 +162,7 @@ impl Visitor<'tcx> for IfThisChanged<'tcx> { NestedVisitorMap::OnlyBodies(&self.tcx.hir()) } - fn visit_item(&mut self, item: &'tcx hir::Item) { + fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { self.process_attrs(item.hir_id, &item.attrs); intravisit::walk_item(self, item); } diff --git a/src/librustc_incremental/persist/dirty_clean.rs b/src/librustc_incremental/persist/dirty_clean.rs index c919db070a6..adb67b84087 100644 --- a/src/librustc_incremental/persist/dirty_clean.rs +++ b/src/librustc_incremental/persist/dirty_clean.rs @@ -532,7 +532,7 @@ impl DirtyCleanVisitor<'tcx> { } impl ItemLikeVisitor<'tcx> for DirtyCleanVisitor<'tcx> { - fn visit_item(&mut self, item: &'tcx hir::Item) { + fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { self.check_item(item.hir_id, item.span); } diff --git a/src/librustc_interface/proc_macro_decls.rs b/src/librustc_interface/proc_macro_decls.rs index 56180bcad06..9c2e8a3d47e 100644 --- a/src/librustc_interface/proc_macro_decls.rs +++ b/src/librustc_interface/proc_macro_decls.rs @@ -24,7 +24,7 @@ struct Finder { } impl<'v> ItemLikeVisitor<'v> for Finder { - fn visit_item(&mut self, item: &hir::Item) { + fn visit_item(&mut self, item: &hir::Item<'_>) { if attr::contains_name(&item.attrs, sym::rustc_proc_macro_decls) { self.decls = Some(item.hir_id); } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 2e4f8e7aabc..626c83713d0 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -117,7 +117,7 @@ impl BoxPointers { } impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxPointers { - fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item) { + fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item<'_>) { match it.kind { hir::ItemKind::Fn(..) | hir::ItemKind::TyAlias(..) | @@ -391,14 +391,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { } } - fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item) { + fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item<'_>) { let desc = match it.kind { hir::ItemKind::Fn(..) => "a function", hir::ItemKind::Mod(..) => "a module", hir::ItemKind::Enum(..) => "an enum", hir::ItemKind::Struct(..) => "a struct", hir::ItemKind::Union(..) => "a union", - hir::ItemKind::Trait(.., ref trait_item_refs) => { + hir::ItemKind::Trait(.., trait_item_refs) => { // Issue #11592: traits are always considered exported, even when private. if let hir::VisibilityKind::Inherited = it.vis.node { self.private_traits.insert(it.hir_id); @@ -410,7 +410,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { "a trait" } hir::ItemKind::TyAlias(..) => "a type alias", - hir::ItemKind::Impl(.., Some(ref trait_ref), _, ref impl_item_refs) => { + hir::ItemKind::Impl(.., Some(ref trait_ref), _, impl_item_refs) => { // If the trait is private, add the impl items to `private_traits` so they don't get // reported for missing docs. let real_trait = trait_ref.path.res.def_id(); @@ -501,7 +501,7 @@ declare_lint! { declare_lint_pass!(MissingCopyImplementations => [MISSING_COPY_IMPLEMENTATIONS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingCopyImplementations { - fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::Item) { + fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::Item<'_>) { if !cx.access_levels.is_reachable(item.hir_id) { return; } @@ -559,7 +559,7 @@ pub struct MissingDebugImplementations { impl_lint_pass!(MissingDebugImplementations => [MISSING_DEBUG_IMPLEMENTATIONS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations { - fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::Item) { + fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::Item<'_>) { if !cx.access_levels.is_reachable(item.hir_id) { return; } @@ -815,7 +815,7 @@ declare_lint! { declare_lint_pass!(InvalidNoMangleItems => [NO_MANGLE_CONST_ITEMS, NO_MANGLE_GENERIC_ITEMS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems { - fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item) { + fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item<'_>) { match it.kind { hir::ItemKind::Fn(.., ref generics, _) => { if let Some(no_mangle_attr) = attr::find_by_name(&it.attrs, sym::no_mangle) { @@ -992,7 +992,7 @@ impl UnreachablePub { } impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnreachablePub { - fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::Item) { + fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::Item<'_>) { self.perform_lint(cx, "item", item.hir_id, &item.vis, item.span, true); } @@ -1074,7 +1074,7 @@ impl TypeAliasBounds { } impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeAliasBounds { - fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::Item) { + fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::Item<'_>) { let (ty, type_alias_generics) = match item.kind { hir::ItemKind::TyAlias(ref ty, ref generics) => (&*ty, generics), _ => return, @@ -1150,7 +1150,7 @@ fn check_const(cx: &LateContext<'_, '_>, body_id: hir::BodyId) { } impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedBrokenConst { - fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item) { + fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item<'_>) { match it.kind { hir::ItemKind::Const(_, body_id) => { check_const(cx, body_id); @@ -1179,7 +1179,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TrivialConstraints { fn check_item( &mut self, cx: &LateContext<'a, 'tcx>, - item: &'tcx hir::Item, + item: &'tcx hir::Item<'tcx>, ) { use rustc::ty::fold::TypeFoldable; use rustc::ty::Predicate::*; @@ -1338,7 +1338,7 @@ impl UnnameableTestItems { } impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnameableTestItems { - fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item) { + fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item<'_>) { if self.items_nameable { if let hir::ItemKind::Mod(..) = it.kind {} else { @@ -1357,7 +1357,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnameableTestItems { } } - fn check_item_post(&mut self, _cx: &LateContext<'_, '_>, it: &hir::Item) { + fn check_item_post(&mut self, _cx: &LateContext<'_, '_>, it: &hir::Item<'_>) { if !self.items_nameable && self.boundary == it.hir_id { self.items_nameable = true; } @@ -1616,7 +1616,7 @@ impl ExplicitOutlivesRequirements { } impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitOutlivesRequirements { - fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) { + fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item<'_>) { use rustc::middle::resolve_lifetime::Region; let infer_static = cx.tcx.features().infer_static_outlives_requirements; diff --git a/src/librustc_lint/nonstandard_style.rs b/src/librustc_lint/nonstandard_style.rs index dceb79fd309..7235321b2b3 100644 --- a/src/librustc_lint/nonstandard_style.rs +++ b/src/librustc_lint/nonstandard_style.rs @@ -325,7 +325,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase { } } - fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item) { + fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item<'_>) { if let hir::ItemKind::Mod(_) = it.kind { self.check_snake_case(cx, "module", &it.ident); } @@ -386,7 +386,7 @@ impl NonUpperCaseGlobals { } impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals { - fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item) { + fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item<'_>) { match it.kind { hir::ItemKind::Static(..) if !attr::contains_name(&it.attrs, sym::no_mangle) => { NonUpperCaseGlobals::check_upper_case(cx, "static variable", &it.ident); diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index 34241b845be..b4ae379f1bb 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -1031,7 +1031,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImproperCTypes { declare_lint_pass!(VariantSizeDifferences => [VARIANT_SIZE_DIFFERENCES]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VariantSizeDifferences { - fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item) { + fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item<'_>) { if let hir::ItemKind::Enum(ref enum_definition, _) = it.kind { let item_def_id = cx.tcx.hir().local_def_id(it.hir_id); let t = cx.tcx.type_of(item_def_id); diff --git a/src/librustc_metadata/foreign_modules.rs b/src/librustc_metadata/foreign_modules.rs index fa1402584ed..acfcdd9a87f 100644 --- a/src/librustc_metadata/foreign_modules.rs +++ b/src/librustc_metadata/foreign_modules.rs @@ -18,7 +18,7 @@ struct Collector<'tcx> { } impl ItemLikeVisitor<'tcx> for Collector<'tcx> { - fn visit_item(&mut self, it: &'tcx hir::Item) { + fn visit_item(&mut self, it: &'tcx hir::Item<'tcx>) { let fm = match it.kind { hir::ItemKind::ForeignMod(ref fm) => fm, _ => return, diff --git a/src/librustc_metadata/link_args.rs b/src/librustc_metadata/link_args.rs index b40d58a6819..2283b772ea8 100644 --- a/src/librustc_metadata/link_args.rs +++ b/src/librustc_metadata/link_args.rs @@ -26,7 +26,7 @@ struct Collector { } impl<'tcx> ItemLikeVisitor<'tcx> for Collector { - fn visit_item(&mut self, it: &'tcx hir::Item) { + fn visit_item(&mut self, it: &'tcx hir::Item<'tcx>) { let fm = match it.kind { hir::ItemKind::ForeignMod(ref fm) => fm, _ => return, diff --git a/src/librustc_metadata/native_libs.rs b/src/librustc_metadata/native_libs.rs index 425e5d1d821..c9c3be46101 100644 --- a/src/librustc_metadata/native_libs.rs +++ b/src/librustc_metadata/native_libs.rs @@ -36,7 +36,7 @@ struct Collector<'tcx> { } impl ItemLikeVisitor<'tcx> for Collector<'tcx> { - fn visit_item(&mut self, it: &'tcx hir::Item) { + fn visit_item(&mut self, it: &'tcx hir::Item<'tcx>) { let fm = match it.kind { hir::ItemKind::ForeignMod(ref fm) => fm, _ => return, diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index 5649789e2c5..7937e57d188 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -1048,7 +1048,7 @@ impl EncodeContext<'tcx> { self.lazy(rendered_const) } - fn encode_info_for_item(&mut self, def_id: DefId, item: &'tcx hir::Item) { + fn encode_info_for_item(&mut self, def_id: DefId, item: &'tcx hir::Item<'tcx>) { let tcx = self.tcx; debug!("EncodeContext::encode_info_for_item({:?})", def_id); @@ -1580,7 +1580,7 @@ impl Visitor<'tcx> for EncodeContext<'tcx> { let def_id = self.tcx.hir().local_def_id(c.hir_id); self.encode_info_for_anon_const(def_id); } - fn visit_item(&mut self, item: &'tcx hir::Item) { + fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { intravisit::walk_item(self, item); let def_id = self.tcx.hir().local_def_id(item.hir_id); match item.kind { @@ -1649,7 +1649,7 @@ impl EncodeContext<'tcx> { /// encode some sub-items. Usually we want some info from the item /// so it's easier to do that here then to wait until we would encounter /// normally in the visitor walk. - fn encode_addl_info_for_item(&mut self, item: &hir::Item) { + fn encode_addl_info_for_item(&mut self, item: &hir::Item<'_>) { let def_id = self.tcx.hir().local_def_id(item.hir_id); match item.kind { hir::ItemKind::Static(..) | @@ -1713,7 +1713,7 @@ struct ImplVisitor<'tcx> { } impl<'tcx, 'v> ItemLikeVisitor<'v> for ImplVisitor<'tcx> { - fn visit_item(&mut self, item: &hir::Item) { + fn visit_item(&mut self, item: &hir::Item<'_>) { if let hir::ItemKind::Impl(..) = item.kind { let impl_id = self.tcx.hir().local_def_id(item.hir_id); if let Some(trait_ref) = self.tcx.impl_trait_ref(impl_id) { diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 3479ad6749a..df8e2b21285 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -55,6 +55,9 @@ pub fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> BodyAndCache<'_> { } Node::Item(hir::Item { kind: hir::ItemKind::Static(ty, _, body_id), .. }) | Node::Item(hir::Item { kind: hir::ItemKind::Const(ty, body_id), .. }) + => { + (*body_id, ty.span) + } | Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Const(ty, body_id), .. }) | Node::TraitItem( hir::TraitItem { kind: hir::TraitItemKind::Const(ty, Some(body_id)), .. } diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index 93a76712b28..d2b18ae0103 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -987,7 +987,7 @@ struct RootCollector<'a, 'tcx> { } impl ItemLikeVisitor<'v> for RootCollector<'_, 'v> { - fn visit_item(&mut self, item: &'v hir::Item) { + fn visit_item(&mut self, item: &'v hir::Item<'v>) { match item.kind { hir::ItemKind::ExternCrate(..) | hir::ItemKind::Use(..) | @@ -1145,7 +1145,7 @@ fn item_requires_monomorphization(tcx: TyCtxt<'_>, def_id: DefId) -> bool { fn create_mono_items_for_default_impls<'tcx>( tcx: TyCtxt<'tcx>, - item: &'tcx hir::Item, + item: &'tcx hir::Item<'tcx>, output: &mut Vec>, ) { match item.kind { diff --git a/src/librustc_passes/dead.rs b/src/librustc_passes/dead.rs index fb5052fedb2..c7f553069c2 100644 --- a/src/librustc_passes/dead.rs +++ b/src/librustc_passes/dead.rs @@ -362,7 +362,7 @@ struct LifeSeeder<'k, 'tcx> { } impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> { - fn visit_item(&mut self, item: &hir::Item) { + fn visit_item(&mut self, item: &hir::Item<'_>) { let allow_dead_code = has_allow_dead_code_or_lang_attr(self.tcx, item.hir_id, &item.attrs); @@ -381,7 +381,7 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> { } } } - hir::ItemKind::Trait(.., ref trait_item_refs) => { + hir::ItemKind::Trait(.., trait_item_refs) => { for trait_item_ref in trait_item_refs { let trait_item = self.krate.trait_item(trait_item_ref.id); match trait_item.kind { @@ -397,7 +397,7 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> { } } } - hir::ItemKind::Impl(.., ref opt_trait, _, ref impl_item_refs) => { + hir::ItemKind::Impl(.., ref opt_trait, _, impl_item_refs) => { for impl_item_ref in impl_item_refs { let impl_item = self.krate.impl_item(impl_item_ref.id); if opt_trait.is_some() || @@ -481,7 +481,7 @@ struct DeadVisitor<'tcx> { } impl DeadVisitor<'tcx> { - fn should_warn_about_item(&mut self, item: &hir::Item) -> bool { + fn should_warn_about_item(&mut self, item: &hir::Item<'_>) -> bool { let should_warn = match item.kind { hir::ItemKind::Static(..) | hir::ItemKind::Const(..) @@ -567,7 +567,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> { NestedVisitorMap::All(&self.tcx.hir()) } - fn visit_item(&mut self, item: &'tcx hir::Item) { + fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { if self.should_warn_about_item(item) { // For most items, we want to highlight its identifier let span = match item.kind { diff --git a/src/librustc_passes/entry.rs b/src/librustc_passes/entry.rs index d0cedc08162..89c1cc8e6b4 100644 --- a/src/librustc_passes/entry.rs +++ b/src/librustc_passes/entry.rs @@ -33,7 +33,7 @@ struct EntryContext<'a, 'tcx> { } impl<'a, 'tcx> ItemLikeVisitor<'tcx> for EntryContext<'a, 'tcx> { - fn visit_item(&mut self, item: &'tcx Item) { + fn visit_item(&mut self, item: &'tcx Item<'tcx>) { let def_id = self.map.local_def_id(item.hir_id); let def_key = self.map.def_key(def_id); let at_root = def_key.parent == Some(CRATE_DEF_INDEX); @@ -81,7 +81,7 @@ fn entry_fn(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<(DefId, EntryFnType)> { // Beware, this is duplicated in `libsyntax/entry.rs`, so make sure to keep // them in sync. -fn entry_point_type(item: &Item, at_root: bool) -> EntryPointType { +fn entry_point_type(item: &Item<'_>, at_root: bool) -> EntryPointType { match item.kind { ItemKind::Fn(..) => { if attr::contains_name(&item.attrs, sym::start) { @@ -104,7 +104,7 @@ fn entry_point_type(item: &Item, at_root: bool) -> EntryPointType { } -fn find_item(item: &Item, ctxt: &mut EntryContext<'_, '_>, at_root: bool) { +fn find_item(item: &Item<'_>, ctxt: &mut EntryContext<'_, '_>, at_root: bool) { match entry_point_type(item, at_root) { EntryPointType::MainNamed => { if ctxt.main_fn.is_none() { diff --git a/src/librustc_passes/hir_stats.rs b/src/librustc_passes/hir_stats.rs index 60c486b30d4..767d5cea2ff 100644 --- a/src/librustc_passes/hir_stats.rs +++ b/src/librustc_passes/hir_stats.rs @@ -123,7 +123,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { self.visit_body(nested_body) } - fn visit_item(&mut self, i: &'v hir::Item) { + fn visit_item(&mut self, i: &'v hir::Item<'v>) { self.record("Item", Id::Node(i.hir_id), i); hir_visit::walk_item(self, i) } diff --git a/src/librustc_passes/layout_test.rs b/src/librustc_passes/layout_test.rs index 06683c16e4a..0e0725ccd67 100644 --- a/src/librustc_passes/layout_test.rs +++ b/src/librustc_passes/layout_test.rs @@ -28,7 +28,7 @@ struct VarianceTest<'tcx> { } impl ItemLikeVisitor<'tcx> for VarianceTest<'tcx> { - fn visit_item(&mut self, item: &'tcx hir::Item) { + fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { let item_def_id = self.tcx.hir().local_def_id(item.hir_id); if let ItemKind::TyAlias(..) = item.kind { @@ -45,7 +45,7 @@ impl ItemLikeVisitor<'tcx> for VarianceTest<'tcx> { } impl VarianceTest<'tcx> { - fn dump_layout_of(&self, item_def_id: DefId, item: &hir::Item, attr: &Attribute) { + fn dump_layout_of(&self, item_def_id: DefId, item: &hir::Item<'tcx>, attr: &Attribute) { let tcx = self.tcx; let param_env = self.tcx.param_env(item_def_id); let ty = self.tcx.type_of(item_def_id); diff --git a/src/librustc_plugin_impl/build.rs b/src/librustc_plugin_impl/build.rs index 01559a95c9c..02e2266d8f4 100644 --- a/src/librustc_plugin_impl/build.rs +++ b/src/librustc_plugin_impl/build.rs @@ -14,7 +14,7 @@ struct RegistrarFinder { } impl<'v> ItemLikeVisitor<'v> for RegistrarFinder { - fn visit_item(&mut self, item: &hir::Item) { + fn visit_item(&mut self, item: &hir::Item<'_>) { if let hir::ItemKind::Fn(..) = item.kind { if attr::contains_name(&item.attrs, sym::plugin_registrar) { self.registrars.push((item.hir_id, item.span)); diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index fcbc2a3301a..b54d528eb8d 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -652,7 +652,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { NestedVisitorMap::All(&self.tcx.hir()) } - fn visit_item(&mut self, item: &'tcx hir::Item) { + fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { let inherited_item_level = match item.kind { hir::ItemKind::Impl(..) => Option::::of_impl(item.hir_id, self.tcx, &self.access_levels), @@ -685,14 +685,14 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { } } } - hir::ItemKind::Impl(.., ref trait_ref, _, ref impl_item_refs) => { + hir::ItemKind::Impl(.., ref trait_ref, _, impl_item_refs) => { for impl_item_ref in impl_item_refs { if trait_ref.is_some() || impl_item_ref.vis.node.is_pub() { self.update(impl_item_ref.id.hir_id, item_level); } } } - hir::ItemKind::Trait(.., ref trait_item_refs) => { + hir::ItemKind::Trait(.., trait_item_refs) => { for trait_item_ref in trait_item_refs { self.update(trait_item_ref.id.hir_id, item_level); } @@ -756,7 +756,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { self.reach(item.hir_id, item_level).generics().predicates().ty(); } } - hir::ItemKind::Trait(.., ref trait_item_refs) => { + hir::ItemKind::Trait(.., trait_item_refs) => { if item_level.is_some() { self.reach(item.hir_id, item_level).generics().predicates(); @@ -779,7 +779,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { } } // Visit everything except for private impl items. - hir::ItemKind::Impl(.., ref impl_item_refs) => { + hir::ItemKind::Impl(.., impl_item_refs) => { if item_level.is_some() { self.reach(item.hir_id, item_level).generics().predicates().ty().trait_ref(); @@ -1004,7 +1004,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> { self.tables = orig_tables; } - fn visit_item(&mut self, item: &'tcx hir::Item) { + fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { let orig_current_item = mem::replace(&mut self.current_item, item.hir_id); let orig_tables = mem::replace(&mut self.tables, item_tables(self.tcx, item.hir_id, self.empty_tables)); @@ -1283,7 +1283,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> { } // Check types in item interfaces. - fn visit_item(&mut self, item: &'tcx hir::Item) { + fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { let orig_current_item = mem::replace(&mut self.current_item, self.tcx.hir().local_def_id(item.hir_id)); let orig_in_body = mem::replace(&mut self.in_body, false); @@ -1416,7 +1416,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { NestedVisitorMap::All(&self.tcx.hir()) } - fn visit_item(&mut self, item: &'tcx hir::Item) { + fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { match item.kind { // Contents of a private mod can be re-exported, so we need // to check internals. @@ -1441,7 +1441,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { // (i.e., we could just return here to not check them at // all, or some worse estimation of whether an impl is // publicly visible). - hir::ItemKind::Impl(.., ref g, ref trait_ref, ref self_, ref impl_item_refs) => { + hir::ItemKind::Impl(.., ref g, ref trait_ref, ref self_, impl_item_refs) => { // `impl [... for] Private` is never visible. let self_contains_private; // `impl [... for] Public<...>`, but not `impl [... for] @@ -1849,7 +1849,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> NestedVisitorMap::OnlyBodies(&self.tcx.hir()) } - fn visit_item(&mut self, item: &'tcx hir::Item) { + fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { let tcx = self.tcx; let item_visibility = ty::Visibility::from_hir(&item.vis, item.hir_id, tcx); @@ -1872,7 +1872,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> // it's not a part of interface, so we skip it. self.check(item.hir_id, item_visibility).generics().predicates(); } - hir::ItemKind::Trait(.., ref trait_item_refs) => { + hir::ItemKind::Trait(.., trait_item_refs) => { self.check(item.hir_id, item_visibility).generics().predicates(); for trait_item_ref in trait_item_refs { @@ -1917,7 +1917,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> // Subitems of inherent impls have their own publicity. // A trait impl is public when both its type and its trait are public // Subitems of trait impls have inherited publicity. - hir::ItemKind::Impl(.., ref trait_ref, _, ref impl_item_refs) => { + hir::ItemKind::Impl(.., ref trait_ref, _, impl_item_refs) => { let impl_vis = ty::Visibility::of_impl(item.hir_id, tcx, &Default::default()); self.check(item.hir_id, impl_vis).generics().predicates(); for impl_item_ref in impl_item_refs { diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 0509748020a..0e839d35b99 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -614,9 +614,9 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> { Node::TraitRef(tr) => tr.path.res, Node::Item(&hir::Item { - kind: hir::ItemKind::Use(ref path, _), + kind: hir::ItemKind::Use(path, _), .. - }) | + }) => path.res, Node::Visibility(&Spanned { node: hir::VisibilityKind::Restricted { ref path, .. }, .. }) => path.res, diff --git a/src/librustc_traits/lowering/mod.rs b/src/librustc_traits/lowering/mod.rs index 0df367fcca8..ecd3112cd79 100644 --- a/src/librustc_traits/lowering/mod.rs +++ b/src/librustc_traits/lowering/mod.rs @@ -669,7 +669,7 @@ impl Visitor<'tcx> for ClauseDumper<'tcx> { NestedVisitorMap::OnlyBodies(&self.tcx.hir()) } - fn visit_item(&mut self, item: &'tcx hir::Item) { + fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { self.process_attrs(item.hir_id, &item.attrs); intravisit::walk_item(self, item); } diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 1ab703db83c..3e4c26e4a8f 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -1002,7 +1002,7 @@ fn compute_all_traits(tcx: TyCtxt<'_>) -> Vec { } impl<'v, 'a, 'tcx> itemlikevisit::ItemLikeVisitor<'v> for Visitor<'a, 'tcx> { - fn visit_item(&mut self, i: &'v hir::Item) { + fn visit_item(&mut self, i: &'v hir::Item<'v>) { match i.kind { hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..) => { diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index afd027e3438..90e31f85a12 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -751,7 +751,7 @@ struct CheckItemTypesVisitor<'tcx> { } impl ItemLikeVisitor<'tcx> for CheckItemTypesVisitor<'tcx> { - fn visit_item(&mut self, i: &'tcx hir::Item) { + fn visit_item(&mut self, i: &'tcx hir::Item<'tcx>) { check_item_type(self.tcx, i); } fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem) { } @@ -1696,7 +1696,7 @@ fn fn_maybe_err(tcx: TyCtxt<'_>, sp: Span, abi: Abi) { } } -pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item) { +pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) { debug!( "check_item_type(it.hir_id={}, it.name={})", it.hir_id, @@ -1857,7 +1857,7 @@ fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: DefId, span: Span) } } -fn check_on_unimplemented(tcx: TyCtxt<'_>, trait_def_id: DefId, item: &hir::Item) { +fn check_on_unimplemented(tcx: TyCtxt<'_>, trait_def_id: DefId, item: &hir::Item<'_>) { let item_def_id = tcx.hir().local_def_id(item.hir_id); // an error would be reported if this fails. let _ = traits::OnUnimplementedDirective::of_item(tcx, trait_def_id, item_def_id); diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 20b6b01de57..9e69b0a2908 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -235,7 +235,7 @@ fn check_associated_item( }) } -fn for_item<'tcx>(tcx: TyCtxt<'tcx>, item: &hir::Item) -> CheckWfFcxBuilder<'tcx> { +fn for_item<'tcx>(tcx: TyCtxt<'tcx>, item: &hir::Item<'_>) -> CheckWfFcxBuilder<'tcx> { for_id(tcx, item.hir_id, item.span) } @@ -252,7 +252,7 @@ fn for_id(tcx: TyCtxt<'_>, id: hir::HirId, span: Span) -> CheckWfFcxBuilder<'_> /// In a type definition, we check that to ensure that the types of the fields are well-formed. fn check_type_defn<'tcx, F>( tcx: TyCtxt<'tcx>, - item: &hir::Item, + item: &hir::Item<'tcx>, all_sized: bool, mut lookup_fields: F, ) where @@ -325,7 +325,7 @@ fn check_type_defn<'tcx, F>( }); } -fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item) { +fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) { debug!("check_trait: {:?}", item.hir_id); let trait_def_id = tcx.hir().local_def_id(item.hir_id); @@ -348,7 +348,7 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item) { }); } -fn check_item_fn(tcx: TyCtxt<'_>, item: &hir::Item) { +fn check_item_fn(tcx: TyCtxt<'_>, item: &hir::Item<'_>) { for_item(tcx, item).with_fcx(|fcx, tcx| { let def_id = fcx.tcx.hir().local_def_id(item.hir_id); let sig = fcx.tcx.fn_sig(def_id); @@ -396,7 +396,7 @@ fn check_item_type( fn check_impl<'tcx>( tcx: TyCtxt<'tcx>, - item: &'tcx hir::Item, + item: &'tcx hir::Item<'tcx>, ast_self_ty: &hir::Ty, ast_trait_ref: &Option, ) { @@ -977,7 +977,7 @@ fn receiver_is_implemented( fn check_variances_for_type_defn<'tcx>( tcx: TyCtxt<'tcx>, - item: &hir::Item, + item: &hir::Item<'tcx>, hir_generics: &hir::Generics, ) { let item_def_id = tcx.hir().local_def_id(item.hir_id); @@ -1081,7 +1081,7 @@ impl CheckTypeWellFormedVisitor<'tcx> { } impl ParItemLikeVisitor<'tcx> for CheckTypeWellFormedVisitor<'tcx> { - fn visit_item(&self, i: &'tcx hir::Item) { + fn visit_item(&self, i: &'tcx hir::Item<'tcx>) { debug!("visit_item: {:?}", i); let def_id = self.tcx.hir().local_def_id(i.hir_id); self.tcx.ensure().check_item_well_formed(def_id); diff --git a/src/librustc_typeck/check_unused.rs b/src/librustc_typeck/check_unused.rs index 7af1a342ff3..bbb743cd3c7 100644 --- a/src/librustc_typeck/check_unused.rs +++ b/src/librustc_typeck/check_unused.rs @@ -29,7 +29,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) { } impl ItemLikeVisitor<'v> for CheckVisitor<'tcx> { - fn visit_item(&mut self, item: &hir::Item) { + fn visit_item(&mut self, item: &hir::Item<'_>) { if item.vis.node.is_pub() || item.span.is_dummy() { return; } @@ -217,7 +217,7 @@ struct ExternCrateToLint { } impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for CollectExternCrateVisitor<'a, 'tcx> { - fn visit_item(&mut self, item: &hir::Item) { + fn visit_item(&mut self, item: &hir::Item<'_>) { if let hir::ItemKind::ExternCrate(orig_name) = item.kind { let extern_crate_def_id = self.tcx.hir().local_def_id(item.hir_id); self.crates_to_lint.push( diff --git a/src/librustc_typeck/coherence/inherent_impls.rs b/src/librustc_typeck/coherence/inherent_impls.rs index 2e2e56e6dcf..13af3865225 100644 --- a/src/librustc_typeck/coherence/inherent_impls.rs +++ b/src/librustc_typeck/coherence/inherent_impls.rs @@ -50,7 +50,7 @@ struct InherentCollect<'tcx> { } impl ItemLikeVisitor<'v> for InherentCollect<'tcx> { - fn visit_item(&mut self, item: &hir::Item) { + fn visit_item(&mut self, item: &hir::Item<'_>) { let ty = match item.kind { hir::ItemKind::Impl(.., None, ref ty, _) => ty, _ => return @@ -262,7 +262,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> { } impl InherentCollect<'tcx> { - fn check_def_id(&mut self, item: &hir::Item, def_id: DefId) { + fn check_def_id(&mut self, item: &hir::Item<'_>, def_id: DefId) { if def_id.is_local() { // Add the implementation to the mapping from implementation to base // type def ID, if there is a base type for this implementation and diff --git a/src/librustc_typeck/coherence/inherent_impls_overlap.rs b/src/librustc_typeck/coherence/inherent_impls_overlap.rs index 39ecfad89bc..84ae0b296a1 100644 --- a/src/librustc_typeck/coherence/inherent_impls_overlap.rs +++ b/src/librustc_typeck/coherence/inherent_impls_overlap.rs @@ -85,7 +85,7 @@ impl InherentOverlapChecker<'tcx> { } impl ItemLikeVisitor<'v> for InherentOverlapChecker<'tcx> { - fn visit_item(&mut self, item: &'v hir::Item) { + fn visit_item(&mut self, item: &'v hir::Item<'v>) { match item.kind { hir::ItemKind::Enum(..) | hir::ItemKind::Struct(..) | diff --git a/src/librustc_typeck/coherence/orphan.rs b/src/librustc_typeck/coherence/orphan.rs index c5d9ef2030c..17487244ee7 100644 --- a/src/librustc_typeck/coherence/orphan.rs +++ b/src/librustc_typeck/coherence/orphan.rs @@ -23,7 +23,7 @@ impl ItemLikeVisitor<'v> for OrphanChecker<'tcx> { /// apply to a specific impl, so just return after reporting one /// to prevent inundating the user with a bunch of similar error /// reports. - fn visit_item(&mut self, item: &hir::Item) { + fn visit_item(&mut self, item: &hir::Item<'_>) { let def_id = self.tcx.hir().local_def_id(item.hir_id); // "Trait" impl if let hir::ItemKind::Impl(.., generics, Some(tr), impl_ty, _) = &item.kind { diff --git a/src/librustc_typeck/coherence/unsafety.rs b/src/librustc_typeck/coherence/unsafety.rs index 650e15ea8a7..5335253f5d6 100644 --- a/src/librustc_typeck/coherence/unsafety.rs +++ b/src/librustc_typeck/coherence/unsafety.rs @@ -18,7 +18,7 @@ struct UnsafetyChecker<'tcx> { impl UnsafetyChecker<'tcx> { fn check_unsafety_coherence(&mut self, - item: &'v hir::Item, + item: &'v hir::Item<'v>, impl_generics: Option<&hir::Generics>, unsafety: hir::Unsafety, polarity: hir::ImplPolarity) @@ -72,7 +72,7 @@ impl UnsafetyChecker<'tcx> { } impl ItemLikeVisitor<'v> for UnsafetyChecker<'tcx> { - fn visit_item(&mut self, item: &'v hir::Item) { + fn visit_item(&mut self, item: &'v hir::Item<'v>) { if let hir::ItemKind::Impl(unsafety, polarity, _, ref generics, ..) = item.kind { self.check_unsafety_coherence(item, Some(generics), unsafety, polarity); } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index b9829793cbe..701f16f37b5 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -111,7 +111,7 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> { NestedVisitorMap::OnlyBodies(&self.tcx.hir()) } - fn visit_item(&mut self, item: &'tcx hir::Item) { + fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { convert_item(self.tcx, item.hir_id); intravisit::walk_item(self, item); } @@ -1693,7 +1693,7 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> { intravisit::NestedVisitorMap::All(&self.tcx.hir()) } - fn visit_item(&mut self, it: &'tcx Item) { + fn visit_item(&mut self, it: &'tcx Item<'tcx>) { debug!("find_existential_constraints: visiting {:?}", it); let def_id = self.tcx.hir().local_def_id(it.hir_id); // The opaque type itself or its children are not within its reveal scope. @@ -2052,8 +2052,6 @@ fn explicit_predicates_of( const NO_GENERICS: &hir::Generics = &hir::Generics::empty(); - let empty_trait_items = HirVec::new(); - let mut predicates = UniquePredicates::new(); let ast_generics = match node { @@ -2098,12 +2096,12 @@ fn explicit_predicates_of( | ItemKind::Struct(_, ref generics) | ItemKind::Union(_, ref generics) => generics, - ItemKind::Trait(_, _, ref generics, .., ref items) => { + ItemKind::Trait(_, _, ref generics, .., items) => { is_trait = Some((ty::TraitRef::identity(tcx, def_id), items)); generics } ItemKind::TraitAlias(ref generics, _) => { - is_trait = Some((ty::TraitRef::identity(tcx, def_id), &empty_trait_items)); + is_trait = Some((ty::TraitRef::identity(tcx, def_id), &[])); generics } ItemKind::OpaqueTy(OpaqueTy { diff --git a/src/librustc_typeck/impl_wf_check.rs b/src/librustc_typeck/impl_wf_check.rs index 28fc44dfad5..98438945d11 100644 --- a/src/librustc_typeck/impl_wf_check.rs +++ b/src/librustc_typeck/impl_wf_check.rs @@ -79,7 +79,7 @@ struct ImplWfCheck<'tcx> { } impl ItemLikeVisitor<'tcx> for ImplWfCheck<'tcx> { - fn visit_item(&mut self, item: &'tcx hir::Item) { + fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { if let hir::ItemKind::Impl(.., ref impl_item_refs) = item.kind { let impl_def_id = self.tcx.hir().local_def_id(item.hir_id); enforce_impl_params_are_constrained(self.tcx, diff --git a/src/librustc_typeck/outlives/implicit_infer.rs b/src/librustc_typeck/outlives/implicit_infer.rs index 74048b8d20c..4ed631232b4 100644 --- a/src/librustc_typeck/outlives/implicit_infer.rs +++ b/src/librustc_typeck/outlives/implicit_infer.rs @@ -51,7 +51,7 @@ pub struct InferVisitor<'cx, 'tcx> { } impl<'cx, 'tcx> ItemLikeVisitor<'tcx> for InferVisitor<'cx, 'tcx> { - fn visit_item(&mut self, item: &hir::Item) { + fn visit_item(&mut self, item: &hir::Item<'_>) { let item_did = self.tcx.hir().local_def_id(item.hir_id); debug!("InferVisitor::visit_item(item={:?})", item_did); diff --git a/src/librustc_typeck/outlives/test.rs b/src/librustc_typeck/outlives/test.rs index aa5272fd4e0..86f61158f5f 100644 --- a/src/librustc_typeck/outlives/test.rs +++ b/src/librustc_typeck/outlives/test.rs @@ -16,7 +16,7 @@ struct OutlivesTest<'tcx> { } impl ItemLikeVisitor<'tcx> for OutlivesTest<'tcx> { - fn visit_item(&mut self, item: &'tcx hir::Item) { + fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { let item_def_id = self.tcx.hir().local_def_id(item.hir_id); // For unit testing: check for a special "rustc_outlives" diff --git a/src/librustc_typeck/variance/constraints.rs b/src/librustc_typeck/variance/constraints.rs index 30558a0f5f6..41854407a09 100644 --- a/src/librustc_typeck/variance/constraints.rs +++ b/src/librustc_typeck/variance/constraints.rs @@ -67,7 +67,7 @@ pub fn add_constraints_from_crate<'a, 'tcx>(terms_cx: TermsContext<'a, 'tcx>) } impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> { - fn visit_item(&mut self, item: &hir::Item) { + fn visit_item(&mut self, item: &hir::Item<'_>) { match item.kind { hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => { diff --git a/src/librustc_typeck/variance/terms.rs b/src/librustc_typeck/variance/terms.rs index 863a0b267fd..e122b334b31 100644 --- a/src/librustc_typeck/variance/terms.rs +++ b/src/librustc_typeck/variance/terms.rs @@ -127,7 +127,7 @@ impl<'a, 'tcx> TermsContext<'a, 'tcx> { } impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for TermsContext<'a, 'tcx> { - fn visit_item(&mut self, item: &hir::Item) { + fn visit_item(&mut self, item: &hir::Item<'_>) { debug!("add_inferreds for item {}", self.tcx.hir().node_to_string(item.hir_id)); diff --git a/src/librustc_typeck/variance/test.rs b/src/librustc_typeck/variance/test.rs index a7fadb5459e..01088db0efb 100644 --- a/src/librustc_typeck/variance/test.rs +++ b/src/librustc_typeck/variance/test.rs @@ -14,7 +14,7 @@ struct VarianceTest<'tcx> { } impl ItemLikeVisitor<'tcx> for VarianceTest<'tcx> { - fn visit_item(&mut self, item: &'tcx hir::Item) { + fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { let item_def_id = self.tcx.hir().local_def_id(item.hir_id); // For unit testing: check for a special "rustc_variance" diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index 002ca6fe983..83a33c840e3 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -9,7 +9,6 @@ use syntax_pos::{self, Span}; use rustc::hir; use rustc::hir::def_id::CrateNum; -use rustc::hir::ptr::P; pub struct Module<'hir> { pub name: Option, @@ -136,7 +135,7 @@ pub struct Function<'hir> { } pub struct Typedef<'hir> { - pub ty: &'hir P, + pub ty: &'hir hir::Ty, pub gen: &'hir hir::Generics, pub name: Name, pub id: hir::HirId, @@ -156,7 +155,7 @@ pub struct OpaqueTy<'hir> { #[derive(Debug)] pub struct Static<'hir> { - pub type_: &'hir P, + pub type_: &'hir hir::Ty, pub mutability: hir::Mutability, pub expr: hir::BodyId, pub name: Name, @@ -167,7 +166,7 @@ pub struct Static<'hir> { } pub struct Constant<'hir> { - pub type_: &'hir P, + pub type_: &'hir hir::Ty, pub expr: hir::BodyId, pub name: Name, pub attrs: &'hir [ast::Attribute], @@ -206,7 +205,7 @@ pub struct Impl<'hir> { pub defaultness: hir::Defaultness, pub generics: &'hir hir::Generics, pub trait_: &'hir Option, - pub for_: &'hir P, + pub for_: &'hir hir::Ty, pub items: Vec<&'hir hir::ImplItem>, pub attrs: &'hir [ast::Attribute], pub whence: Span, diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 7ec7f460987..b9e409f3d58 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -440,7 +440,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { om.unions.push(self.visit_union_data(item, ident.name, sd, gen)), hir::ItemKind::Fn(ref sig, ref gen, body) => self.visit_fn(om, item, ident.name, &sig.decl, sig.header, gen, body), - hir::ItemKind::TyAlias(ref ty, ref gen) => { + hir::ItemKind::TyAlias(ty, ref gen) => { let t = Typedef { ty, gen, @@ -463,7 +463,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { }; om.opaque_tys.push(t); }, - hir::ItemKind::Static(ref type_, mutability, expr) => { + hir::ItemKind::Static(type_, mutability, expr) => { let s = Static { type_, mutability, @@ -476,7 +476,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { }; om.statics.push(s); }, - hir::ItemKind::Const(ref type_, expr) => { + hir::ItemKind::Const(type_, expr) => { let s = Constant { type_, expr, @@ -524,7 +524,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { defaultness, ref generics, ref trait_, - ref for_, + for_, ref item_ids) => { // Don't duplicate impls when inlining or if it's implementing a trait, we'll pick // them up regardless of where they're located. From abbe6259e1a4e7bf6e2eccbae0748c0e5c15ebb0 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 28 Nov 2019 23:50:47 +0100 Subject: [PATCH 03/12] Handle Attributes in arena. --- src/librustc/arena.rs | 2 +- src/librustc/hir/check_attr.rs | 12 ++++++------ src/librustc/hir/intravisit.rs | 8 ++++---- src/librustc/hir/lowering.rs | 13 ++++++------- src/librustc/hir/lowering/item.rs | 14 +++++++------- src/librustc/hir/map/collector.rs | 2 +- src/librustc/hir/mod.rs | 10 +++++----- src/librustc/middle/stability.rs | 4 ++-- src/librustc_codegen_llvm/consts.rs | 4 ++-- src/librustc_metadata/rmeta/encoder.rs | 8 ++++---- src/librustc_passes/hir_stats.rs | 2 +- src/librustc_privacy/lib.rs | 2 +- src/librustc_typeck/check/method/suggest.rs | 2 +- 13 files changed, 41 insertions(+), 42 deletions(-) diff --git a/src/librustc/arena.rs b/src/librustc/arena.rs index d95e5f64f0c..56e089f20ba 100644 --- a/src/librustc/arena.rs +++ b/src/librustc/arena.rs @@ -127,7 +127,7 @@ macro_rules! arena_types { [] attribute: syntax::ast::Attribute, [] global_asm: rustc::hir::GlobalAsm, [] impl_item_ref: rustc::hir::ImplItemRef, - [] macro_def: rustc::hir::MacroDef, + [] macro_def: rustc::hir::MacroDef<$tcx>, [] path: rustc::hir::Path, [] trait_item_ref: rustc::hir::TraitItemRef, [] ty: rustc::hir::Ty, diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index d50d60e88c2..becbada225d 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -4,7 +4,7 @@ //! conflicts between multiple such attributes attached to the same //! item. -use crate::hir::{self, HirId, HirVec, Attribute, Item, ItemKind, TraitItem, TraitItemKind}; +use crate::hir::{self, HirId, Attribute, Item, ItemKind, TraitItem, TraitItemKind}; use crate::hir::DUMMY_HIR_ID; use crate::hir::def_id::DefId; use crate::hir::intravisit::{self, Visitor, NestedVisitorMap}; @@ -158,7 +158,7 @@ impl CheckAttrVisitor<'tcx> { fn check_attributes( &self, hir_id: HirId, - attrs: &HirVec, + attrs: &'hir [Attribute], span: &Span, target: Target, item: Option<&Item<'_>>, @@ -241,7 +241,7 @@ impl CheckAttrVisitor<'tcx> { fn check_track_caller( &self, attr_span: &Span, - attrs: &HirVec, + attrs: &'hir [Attribute], span: &Span, target: Target, ) -> bool { @@ -332,7 +332,7 @@ impl CheckAttrVisitor<'tcx> { /// Checks if the `#[repr]` attributes on `item` are valid. fn check_repr( &self, - attrs: &HirVec, + attrs: &'hir [Attribute], span: &Span, target: Target, item: Option<&Item<'_>>, @@ -477,7 +477,7 @@ impl CheckAttrVisitor<'tcx> { } } - fn check_used(&self, attrs: &HirVec, target: Target) { + fn check_used(&self, attrs: &'hir [Attribute], target: Target) { for attr in attrs { if attr.check_name(sym::used) && target != Target::Static { self.tcx.sess @@ -494,7 +494,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> { fn visit_item(&mut self, item: &'tcx Item<'tcx>) { let target = Target::from_item(item); - self.check_attributes(item.hir_id, &item.attrs, &item.span, target, Some(item)); + self.check_attributes(item.hir_id, item.attrs, &item.span, target, Some(item)); intravisit::walk_item(self, item) } diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 28c8e58feaf..8fe3c7232b1 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -367,7 +367,7 @@ pub trait Visitor<'v>: Sized { } fn visit_attribute(&mut self, _attr: &'v Attribute) { } - fn visit_macro_def(&mut self, macro_def: &'v MacroDef) { + fn visit_macro_def(&mut self, macro_def: &'v MacroDef<'v>) { walk_macro_def(self, macro_def) } fn visit_vis(&mut self, vis: &'v Visibility) { @@ -388,10 +388,10 @@ pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate<'v>) { 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<'v>) { visitor.visit_id(macro_def.hir_id); visitor.visit_name(macro_def.span, macro_def.name); - walk_list!(visitor, visit_attribute, ¯o_def.attrs); + 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) { @@ -554,7 +554,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) { walk_list!(visitor, visit_param_bound, bounds); } } - walk_list!(visitor, visit_attribute, &item.attrs); + walk_list!(visitor, visit_attribute, item.attrs); } pub fn walk_use<'v, V: Visitor<'v>>(visitor: &mut V, diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 6ab2bb53e2a..522f9adbaef 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -100,7 +100,7 @@ pub struct LoweringContext<'a, 'hir: 'a> { trait_items: BTreeMap, impl_items: BTreeMap, bodies: BTreeMap, - exported_macros: Vec, + exported_macros: Vec>, non_exported_macro_attrs: Vec, trait_impls: BTreeMap>, @@ -989,15 +989,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } } - fn lower_attrs_extendable(&mut self, attrs: &[Attribute]) -> Vec { - attrs - .iter() - .map(|a| self.lower_attr(a)) - .collect() + fn lower_attrs_arena(&mut self, attrs: &[Attribute]) -> &'hir [Attribute] { + self.arena.alloc_from_iter( + attrs.iter().map(|a| self.lower_attr(a)) + ) } fn lower_attrs(&mut self, attrs: &[Attribute]) -> hir::HirVec { - self.lower_attrs_extendable(attrs).into() + attrs.iter().map(|a| self.lower_attr(a)).collect::>().into() } fn lower_attr(&mut self, attr: &Attribute) -> Attribute { diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index 7e5ac42d13e..0bc08dac151 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -228,7 +228,7 @@ impl LoweringContext<'_, 'hir> { pub fn lower_item(&mut self, i: &Item) -> Option> { let mut ident = i.ident; let mut vis = self.lower_visibility(&i.vis, None); - let attrs = self.lower_attrs(&i.attrs); + let attrs = self.lower_attrs_arena(&i.attrs); if let ItemKind::MacroDef(ref def) = i.kind { if !def.legacy || attr::contains_name(&i.attrs, sym::macro_export) { @@ -244,12 +244,12 @@ impl LoweringContext<'_, 'hir> { legacy: def.legacy, }); } else { - self.non_exported_macro_attrs.extend(attrs.into_iter()); + self.non_exported_macro_attrs.extend(attrs.iter().cloned()); } return None; } - let kind = self.lower_item_kind(i.span, i.id, &mut ident, &attrs, &mut vis, &i.kind); + let kind = self.lower_item_kind(i.span, i.id, &mut ident, attrs, &mut vis, &i.kind); Some(hir::Item { hir_id: self.lower_node_id(i.id), @@ -266,7 +266,7 @@ impl LoweringContext<'_, 'hir> { span: Span, id: NodeId, ident: &mut Ident, - attrs: &hir::HirVec, + attrs: &'hir [Attribute], vis: &mut hir::Visibility, i: &ItemKind, ) -> hir::ItemKind<'hir> { @@ -487,7 +487,7 @@ impl LoweringContext<'_, 'hir> { id: NodeId, vis: &mut hir::Visibility, ident: &mut Ident, - attrs: &hir::HirVec, + attrs: &'hir [Attribute], ) -> hir::ItemKind<'hir> { debug!("lower_use_tree(tree={:?})", tree); debug!("lower_use_tree: vis = {:?}", vis); @@ -550,7 +550,7 @@ impl LoweringContext<'_, 'hir> { hir::Item { hir_id: new_id, ident, - attrs: attrs.into_iter().cloned().collect(), + attrs, kind, vis, span, @@ -634,7 +634,7 @@ impl LoweringContext<'_, 'hir> { hir::Item { hir_id: new_hir_id, ident, - attrs: attrs.into_iter().cloned().collect(), + attrs, kind, vis, span: use_tree.span, diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index b56adf25e8a..c460d9ef6cc 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -530,7 +530,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> { } } - fn visit_macro_def(&mut self, macro_def: &'hir MacroDef) { + fn visit_macro_def(&mut self, macro_def: &'hir MacroDef<'hir>) { let node_id = self.hir_to_node_id[¯o_def.hir_id]; let def_index = self.definitions.opt_def_index(node_id).unwrap(); diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 4fb9f27c27d..063c0f9b278 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -746,7 +746,7 @@ pub struct Crate<'hir> { pub module: Mod, pub attrs: &'hir [Attribute], pub span: Span, - pub exported_macros: &'hir [MacroDef], + pub exported_macros: &'hir [MacroDef<'hir>], // Attributes from non-exported macros, kept only for collecting the library feature list. pub non_exported_macro_attrs: &'hir [Attribute], @@ -841,10 +841,10 @@ impl Crate<'_> { /// /// Not parsed directly, but created on macro import or `macro_rules!` expansion. #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] -pub struct MacroDef { +pub struct MacroDef<'hir> { pub name: Name, pub vis: Visibility, - pub attrs: HirVec, + pub attrs: &'hir [Attribute], pub hir_id: HirId, pub span: Span, pub body: TokenStream, @@ -2445,7 +2445,7 @@ pub struct ItemId { pub struct Item<'hir> { pub ident: Ident, pub hir_id: HirId, - pub attrs: HirVec, + pub attrs: &'hir [Attribute], pub kind: ItemKind<'hir>, pub vis: Visibility, pub span: Span, @@ -2804,7 +2804,7 @@ pub enum Node<'hir> { Arm(&'hir Arm), Block(&'hir Block), Local(&'hir Local), - MacroDef(&'hir MacroDef), + MacroDef(&'hir MacroDef<'hir>), /// `Ctor` refers to the constructor of an enum variant or struct. Only tuple or unit variants /// with synthesized constructors. diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 6aa84b59338..1c717f0f1f5 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -324,7 +324,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { }); } - fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef) { + fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef<'tcx>) { self.annotate(md.hir_id, &md.attrs, md.span, AnnotationKind::Required, |_| {}); } } @@ -397,7 +397,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> { intravisit::walk_foreign_item(self, i); } - fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef) { + fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef<'tcx>) { self.check_missing_stability(md.hir_id, md.span, "macro"); } } diff --git a/src/librustc_codegen_llvm/consts.rs b/src/librustc_codegen_llvm/consts.rs index 11a105c1828..e1750887ac4 100644 --- a/src/librustc_codegen_llvm/consts.rs +++ b/src/librustc_codegen_llvm/consts.rs @@ -232,7 +232,7 @@ impl CodegenCx<'ll, 'tcx> { let llty = self.layout_of(ty).llvm_type(self); let (g, attrs) = match self.tcx.hir().get(id) { Node::Item(&hir::Item { - ref attrs, span, kind: hir::ItemKind::Static(..), .. + attrs, span, kind: hir::ItemKind::Static(..), .. }) => { let sym_str = sym.as_str(); if let Some(g) = self.get_declared_value(&sym_str) { @@ -256,7 +256,7 @@ impl CodegenCx<'ll, 'tcx> { ref attrs, span, kind: hir::ForeignItemKind::Static(..), .. }) => { let fn_attrs = self.tcx.codegen_fn_attrs(def_id); - (check_and_apply_linkage(&self, &fn_attrs, ty, sym, span), attrs) + (check_and_apply_linkage(&self, &fn_attrs, ty, sym, span), &**attrs) } item => bug!("get_static: expected static, found {:?}", item) diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index 7937e57d188..4d7e18828d1 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -1160,7 +1160,7 @@ impl EncodeContext<'tcx> { record!(self.per_def.visibility[def_id] <- ty::Visibility::from_hir(&item.vis, item.hir_id, tcx)); record!(self.per_def.span[def_id] <- item.span); - record!(self.per_def.attributes[def_id] <- &item.attrs); + record!(self.per_def.attributes[def_id] <- item.attrs); // FIXME(eddyb) there should be a nicer way to do this. match item.kind { hir::ItemKind::ForeignMod(ref fm) => record!(self.per_def.children[def_id] <- @@ -1271,7 +1271,7 @@ impl EncodeContext<'tcx> { } /// Serialize the text of exported macros - fn encode_info_for_macro_def(&mut self, macro_def: &hir::MacroDef) { + fn encode_info_for_macro_def(&mut self, macro_def: &hir::MacroDef<'_>) { use syntax::print::pprust; let def_id = self.tcx.hir().local_def_id(macro_def.hir_id); record!(self.per_def.kind[def_id] <- EntryKind::MacroDef(self.lazy(MacroDef { @@ -1280,7 +1280,7 @@ impl EncodeContext<'tcx> { }))); record!(self.per_def.visibility[def_id] <- ty::Visibility::Public); record!(self.per_def.span[def_id] <- macro_def.span); - record!(self.per_def.attributes[def_id] <- ¯o_def.attrs); + record!(self.per_def.attributes[def_id] <- macro_def.attrs); self.encode_stability(def_id); self.encode_deprecation(def_id); } @@ -1599,7 +1599,7 @@ impl Visitor<'tcx> for EncodeContext<'tcx> { intravisit::walk_generics(self, generics); self.encode_info_for_generics(generics); } - fn visit_macro_def(&mut self, macro_def: &'tcx hir::MacroDef) { + fn visit_macro_def(&mut self, macro_def: &'tcx hir::MacroDef<'tcx>) { self.encode_info_for_macro_def(macro_def); } } diff --git a/src/librustc_passes/hir_stats.rs b/src/librustc_passes/hir_stats.rs index 767d5cea2ff..d7639362c57 100644 --- a/src/librustc_passes/hir_stats.rs +++ b/src/librustc_passes/hir_stats.rs @@ -247,7 +247,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { self.record("Attribute", Id::Attr(attr.id), attr); } - fn visit_macro_def(&mut self, macro_def: &'v hir::MacroDef) { + fn visit_macro_def(&mut self, macro_def: &'v hir::MacroDef<'v>) { self.record("MacroDef", Id::Node(macro_def.hir_id), macro_def); hir_visit::walk_macro_def(self, macro_def) } diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index b54d528eb8d..b60c6fe183f 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -870,7 +870,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { intravisit::walk_mod(self, m, id); } - fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef) { + fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef<'tcx>) { if attr::find_transparency(&md.attrs, md.legacy).0 != Transparency::Opaque { self.update(md.hir_id, Some(AccessLevel::Public)); return diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 3e4c26e4a8f..99525cc30fd 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -1127,7 +1127,7 @@ impl hir::intravisit::Visitor<'tcx> for UsePlacementFinder<'tcx> { self.span = Some(item.span.shrink_to_lo()); } else { // Find the first attribute on the item. - for attr in &item.attrs { + for attr in item.attrs { if self.span.map_or(true, |span| attr.span < span) { self.span = Some(attr.span.shrink_to_lo()); } From acf33f2d6bca429196692d2b557c8e53e10bb9fe Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 28 Nov 2019 20:18:29 +0100 Subject: [PATCH 04/12] Use Arena inside hir::ForeignItem. --- src/librustc/arena.rs | 2 ++ src/librustc/hir/check_attr.rs | 4 ++-- src/librustc/hir/intravisit.rs | 10 +++++----- src/librustc/hir/lowering/item.rs | 15 +++++++------- src/librustc/hir/map/collector.rs | 2 +- src/librustc/hir/map/mod.rs | 4 ++-- src/librustc/hir/mod.rs | 22 ++++++++++----------- src/librustc/hir/print.rs | 6 +++--- src/librustc/lint/context.rs | 2 +- src/librustc/lint/mod.rs | 6 +++--- src/librustc/middle/resolve_lifetime.rs | 2 +- src/librustc/middle/stability.rs | 4 ++-- src/librustc/middle/weak_lang_items.rs | 2 +- src/librustc_lint/builtin.rs | 2 +- src/librustc_lint/types.rs | 2 +- src/librustc_metadata/rmeta/encoder.rs | 6 +++--- src/librustc_passes/dead.rs | 4 ++-- src/librustc_passes/hir_stats.rs | 2 +- src/librustc_privacy/lib.rs | 8 ++++---- src/librustc_typeck/check/intrinsic.rs | 6 +++--- src/librustc_typeck/check/mod.rs | 14 +++++++++---- src/librustc_typeck/collect.rs | 2 +- src/librustc_typeck/variance/constraints.rs | 2 +- src/librustc_typeck/variance/terms.rs | 2 +- src/librustdoc/doctree.rs | 2 +- src/librustdoc/visit_ast.rs | 2 +- 26 files changed, 72 insertions(+), 63 deletions(-) diff --git a/src/librustc/arena.rs b/src/librustc/arena.rs index 56e089f20ba..3f0c0277f8a 100644 --- a/src/librustc/arena.rs +++ b/src/librustc/arena.rs @@ -126,6 +126,8 @@ macro_rules! arena_types { [few] hir_forest: rustc::hir::map::Forest<$tcx>, [] attribute: syntax::ast::Attribute, [] global_asm: rustc::hir::GlobalAsm, + [] fn_decl: rustc::hir::FnDecl, + [] foreign_item: rustc::hir::ForeignItem<$tcx>, [] impl_item_ref: rustc::hir::ImplItemRef, [] macro_def: rustc::hir::MacroDef<$tcx>, [] path: rustc::hir::Path, diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index becbada225d..d5acde2f463 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -120,7 +120,7 @@ impl Target { } } - fn from_foreign_item(foreign_item: &hir::ForeignItem) -> Target { + fn from_foreign_item(foreign_item: &hir::ForeignItem<'_>) -> Target { match foreign_item.kind { hir::ForeignItemKind::Fn(..) => Target::ForeignFn, hir::ForeignItemKind::Static(..) => Target::ForeignStatic, @@ -504,7 +504,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> { intravisit::walk_trait_item(self, trait_item) } - fn visit_foreign_item(&mut self, f_item: &'tcx hir::ForeignItem) { + fn visit_foreign_item(&mut self, f_item: &'tcx hir::ForeignItem<'tcx>) { let target = Target::from_foreign_item(f_item); self.check_attributes(f_item.hir_id, &f_item.attrs, &f_item.span, target, None); intravisit::walk_foreign_item(self, f_item) diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 8fe3c7232b1..d10b5cd0373 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -250,7 +250,7 @@ pub trait Visitor<'v>: Sized { fn visit_mod(&mut self, m: &'v Mod, _s: Span, n: HirId) { walk_mod(self, m, n) } - fn visit_foreign_item(&mut self, i: &'v ForeignItem) { + fn visit_foreign_item(&mut self, i: &'v ForeignItem<'v>) { walk_foreign_item(self, i) } fn visit_local(&mut self, l: &'v Local) { @@ -498,7 +498,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) { } ItemKind::ForeignMod(ref foreign_module) => { visitor.visit_id(item.hir_id); - walk_list!(visitor, visit_foreign_item, &foreign_module.items); + walk_list!(visitor, visit_foreign_item, foreign_module.items); } ItemKind::GlobalAsm(_) => { visitor.visit_id(item.hir_id); @@ -735,13 +735,13 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) { } } -pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v ForeignItem) { +pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v ForeignItem<'v>) { visitor.visit_id(foreign_item.hir_id); visitor.visit_vis(&foreign_item.vis); visitor.visit_ident(foreign_item.ident); match foreign_item.kind { - ForeignItemKind::Fn(ref function_declaration, ref param_names, ref generics) => { + ForeignItemKind::Fn(ref function_declaration, param_names, ref generics) => { visitor.visit_generics(generics); visitor.visit_fn_decl(function_declaration); for ¶m_name in param_names { @@ -752,7 +752,7 @@ pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v ForeignItemKind::Type => (), } - walk_list!(visitor, visit_attribute, &foreign_item.attrs); + walk_list!(visitor, visit_attribute, foreign_item.attrs); } pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v GenericBound) { diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index 0bc08dac151..a19ddd5fd94 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -706,12 +706,12 @@ impl LoweringContext<'_, 'hir> { respan(vis.span, vis_kind) } - fn lower_foreign_item(&mut self, i: &ForeignItem) -> hir::ForeignItem { + fn lower_foreign_item(&mut self, i: &ForeignItem) -> hir::ForeignItem<'hir> { let def_id = self.resolver.definitions().local_def_id(i.id); hir::ForeignItem { hir_id: self.lower_node_id(i.id), ident: i.ident, - attrs: self.lower_attrs(&i.attrs), + attrs: self.lower_attrs_arena(&i.attrs), kind: match i.kind { ForeignItemKind::Fn(ref fdec, ref generics) => { let (generics, (fn_dec, fn_args)) = self.add_in_band_defs( @@ -726,12 +726,14 @@ impl LoweringContext<'_, 'hir> { ) }, ); + let fn_dec = self.arena.alloc(fn_dec.into_inner()); + let fn_args = self.arena.alloc_from_iter(fn_args.into_iter()); hir::ForeignItemKind::Fn(fn_dec, fn_args, generics) } ForeignItemKind::Static(ref t, m) => { hir::ForeignItemKind::Static( - self.lower_ty(t, ImplTraitContext::disallowed()), m) + self.arena.alloc(self.lower_ty(t, ImplTraitContext::disallowed()).into_inner()), m) } ForeignItemKind::Ty => hir::ForeignItemKind::Type, ForeignItemKind::Macro(_) => panic!("macro shouldn't exist here"), @@ -741,13 +743,12 @@ impl LoweringContext<'_, 'hir> { } } - fn lower_foreign_mod(&mut self, fm: &ForeignMod) -> hir::ForeignMod { + fn lower_foreign_mod(&mut self, fm: &ForeignMod) -> hir::ForeignMod<'hir> { hir::ForeignMod { abi: fm.abi.map_or(abi::Abi::C, |abi| self.lower_abi(abi)), - items: fm.items + items: self.arena.alloc_from_iter(fm.items .iter() - .map(|x| self.lower_foreign_item(x)) - .collect(), + .map(|x| self.lower_foreign_item(x))), } } diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index c460d9ef6cc..c29ad49aca1 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -385,7 +385,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> { }); } - fn visit_foreign_item(&mut self, foreign_item: &'hir ForeignItem) { + fn visit_foreign_item(&mut self, foreign_item: &'hir ForeignItem<'hir>) { self.insert(foreign_item.span, foreign_item.hir_id, Node::ForeignItem(foreign_item)); self.with_parent(foreign_item.hir_id, |this| { diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 982753da5f6..df4bc7cc817 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -1002,7 +1002,7 @@ impl<'hir> Map<'hir> { } } - pub fn expect_foreign_item(&self, id: HirId) -> &'hir ForeignItem { + pub fn expect_foreign_item(&self, id: HirId) -> &'hir ForeignItem<'hir> { match self.find(id) { Some(Node::ForeignItem(item)) => item, _ => bug!("expected foreign item, found {}", self.node_to_string(id)) @@ -1249,7 +1249,7 @@ trait Named { impl Named for Spanned { fn name(&self) -> Name { self.node.name() } } impl Named for Item<'_> { fn name(&self) -> Name { self.ident.name } } -impl Named for ForeignItem { fn name(&self) -> Name { self.ident.name } } +impl Named for ForeignItem<'_> { fn name(&self) -> Name { self.ident.name } } impl Named for Variant { fn name(&self) -> Name { self.ident.name } } impl Named for StructField { fn name(&self) -> Name { self.ident.name } } impl Named for TraitItem { fn name(&self) -> Name { self.ident.name } } diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 063c0f9b278..d3137ee6ac1 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -2252,9 +2252,9 @@ pub struct Mod { } #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] -pub struct ForeignMod { +pub struct ForeignMod<'hir> { pub abi: Abi, - pub items: HirVec, + pub items: &'hir [ForeignItem<'hir>], } #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] @@ -2491,7 +2491,7 @@ pub enum ItemKind<'hir> { /// A module. Mod(Mod), /// An external module, e.g. `extern { .. }`. - ForeignMod(ForeignMod), + ForeignMod(ForeignMod<'hir>), /// Module-level inline assembly (from `global_asm!`). GlobalAsm(&'hir GlobalAsm), /// A type alias, e.g., `type Foo = Bar`. @@ -2607,11 +2607,11 @@ pub enum AssocItemKind { } #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] -pub struct ForeignItem { +pub struct ForeignItem<'hir> { #[stable_hasher(project(name))] pub ident: Ident, - pub attrs: HirVec, - pub kind: ForeignItemKind, + pub attrs: &'hir [Attribute], + pub kind: ForeignItemKind<'hir>, pub hir_id: HirId, pub span: Span, pub vis: Visibility, @@ -2619,16 +2619,16 @@ pub struct ForeignItem { /// An item within an `extern` block. #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] -pub enum ForeignItemKind { +pub enum ForeignItemKind<'hir> { /// A foreign function. - Fn(P, HirVec, Generics), + Fn(&'hir FnDecl, &'hir [Ident], Generics), /// A foreign static item (`static ext: u8`). - Static(P, Mutability), + Static(&'hir Ty, Mutability), /// A foreign type. Type, } -impl ForeignItemKind { +impl ForeignItemKind<'hir> { pub fn descriptive_variant(&self) -> &str { match *self { ForeignItemKind::Fn(..) => "foreign function", @@ -2788,7 +2788,7 @@ impl CodegenFnAttrs { pub enum Node<'hir> { Param(&'hir Param), Item(&'hir Item<'hir>), - ForeignItem(&'hir ForeignItem), + ForeignItem(&'hir ForeignItem<'hir>), TraitItem(&'hir TraitItem), ImplItem(&'hir ImplItem), Variant(&'hir Variant), diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index e6398b8c2e9..b6f7f840d08 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -267,11 +267,11 @@ impl<'a> State<'a> { } pub fn print_foreign_mod(&mut self, - nmod: &hir::ForeignMod, + nmod: &hir::ForeignMod<'_>, attrs: &[ast::Attribute]) { self.print_inner_attributes(attrs); - for item in &nmod.items { + for item in nmod.items { self.print_foreign_item(item); } } @@ -361,7 +361,7 @@ impl<'a> State<'a> { self.end() } - pub fn print_foreign_item(&mut self, item: &hir::ForeignItem) { + pub fn print_foreign_item(&mut self, item: &hir::ForeignItem<'_>) { self.hardbreak_if_not_bol(); self.maybe_print_comment(item.span.lo()); self.print_outer_attributes(&item.attrs); diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 4b7d2f67332..c3cd50b4885 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -943,7 +943,7 @@ for LateContextAndPass<'a, 'tcx, T> { self.context.generics = generics; } - fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem) { + fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem<'tcx>) { self.with_lint_attrs(it.hir_id, &it.attrs, |cx| { cx.with_param_env(it.hir_id, |cx| { lint_callback!(cx, check_foreign_item, it); diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index c8dc761eef9..79fb53c92b0 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -94,8 +94,8 @@ macro_rules! late_lint_methods { 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_foreign_item(a: &$hir hir::ForeignItem); - fn check_foreign_item_post(a: &$hir hir::ForeignItem); + 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>); fn check_item_post(a: &$hir hir::Item<$hir>); fn check_local(a: &$hir hir::Local); @@ -610,7 +610,7 @@ impl intravisit::Visitor<'tcx> for LintLevelMapBuilder<'_, 'tcx> { }); } - fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem) { + fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem<'tcx>) { self.with_lint_attrs(it.hir_id, &it.attrs, |builder| { intravisit::walk_foreign_item(builder, it); }) diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 4fd117b5980..7a852ef9ef4 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -536,7 +536,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { } } - fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem) { + fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem<'tcx>) { match item.kind { hir::ForeignItemKind::Fn(ref decl, _, ref generics) => { self.visit_early_late(None, decl, generics, |this| { diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 1c717f0f1f5..27830c86ed1 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -318,7 +318,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { }); } - fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem) { + fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem<'tcx>) { self.annotate(i.hir_id, &i.attrs, i.span, AnnotationKind::Required, |v| { intravisit::walk_foreign_item(v, i); }); @@ -392,7 +392,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> { intravisit::walk_struct_field(self, s); } - fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem) { + fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem<'tcx>) { self.check_missing_stability(i.hir_id, i.span, i.kind.descriptive_variant()); intravisit::walk_foreign_item(self, i); } diff --git a/src/librustc/middle/weak_lang_items.rs b/src/librustc/middle/weak_lang_items.rs index 48c1226232f..2acea7c5b68 100644 --- a/src/librustc/middle/weak_lang_items.rs +++ b/src/librustc/middle/weak_lang_items.rs @@ -136,7 +136,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> { NestedVisitorMap::None } - fn visit_foreign_item(&mut self, i: &hir::ForeignItem) { + fn visit_foreign_item(&mut self, i: &hir::ForeignItem<'_>) { if let Some((lang_item, _)) = lang_items::extract(&i.attrs) { self.register(lang_item, i.span); } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 626c83713d0..030fb8dc339 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -996,7 +996,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnreachablePub { self.perform_lint(cx, "item", item.hir_id, &item.vis, item.span, true); } - fn check_foreign_item(&mut self, cx: &LateContext<'_, '_>, foreign_item: &hir::ForeignItem) { + fn check_foreign_item(&mut self, cx: &LateContext<'_, '_>, foreign_item: &hir::ForeignItem<'tcx>) { self.perform_lint(cx, "item", foreign_item.hir_id, &foreign_item.vis, foreign_item.span, true); } diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index b4ae379f1bb..f1cd2037edd 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -1009,7 +1009,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { } impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImproperCTypes { - fn check_foreign_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::ForeignItem) { + fn check_foreign_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::ForeignItem<'_>) { let mut vis = ImproperCTypesVisitor { cx }; let abi = cx.tcx.hir().get_foreign_abi(it.hir_id); if let Abi::Rust | Abi::RustCall | Abi::RustIntrinsic | Abi::PlatformIntrinsic = abi { diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index 4d7e18828d1..93e04c18f5f 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -1525,7 +1525,7 @@ impl EncodeContext<'tcx> { fn encode_info_for_foreign_item( &mut self, def_id: DefId, - nitem: &hir::ForeignItem, + nitem: &hir::ForeignItem<'_>, ) { let tcx = self.tcx; @@ -1551,7 +1551,7 @@ impl EncodeContext<'tcx> { record!(self.per_def.visibility[def_id] <- ty::Visibility::from_hir(&nitem.vis, nitem.hir_id, self.tcx)); record!(self.per_def.span[def_id] <- nitem.span); - record!(self.per_def.attributes[def_id] <- &nitem.attrs); + record!(self.per_def.attributes[def_id] <- nitem.attrs); self.encode_stability(def_id); self.encode_const_stability(def_id); self.encode_deprecation(def_id); @@ -1590,7 +1590,7 @@ impl Visitor<'tcx> for EncodeContext<'tcx> { } self.encode_addl_info_for_item(item); } - fn visit_foreign_item(&mut self, ni: &'tcx hir::ForeignItem) { + fn visit_foreign_item(&mut self, ni: &'tcx hir::ForeignItem<'tcx>) { intravisit::walk_foreign_item(self, ni); let def_id = self.tcx.hir().local_def_id(ni.hir_id); self.encode_info_for_foreign_item(def_id, ni); diff --git a/src/librustc_passes/dead.rs b/src/librustc_passes/dead.rs index c7f553069c2..ee67e44afc8 100644 --- a/src/librustc_passes/dead.rs +++ b/src/librustc_passes/dead.rs @@ -510,7 +510,7 @@ impl DeadVisitor<'tcx> { &variant.attrs) } - fn should_warn_about_foreign_item(&mut self, fi: &hir::ForeignItem) -> bool { + fn should_warn_about_foreign_item(&mut self, fi: &hir::ForeignItem<'_>) -> bool { !self.symbol_is_live(fi.hir_id) && !has_allow_dead_code_or_lang_attr(self.tcx, fi.hir_id, &fi.attrs) } @@ -621,7 +621,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> { } } - fn visit_foreign_item(&mut self, fi: &'tcx hir::ForeignItem) { + fn visit_foreign_item(&mut self, fi: &'tcx hir::ForeignItem<'tcx>) { if self.should_warn_about_foreign_item(fi) { self.warn_dead_code(fi.hir_id, fi.span, fi.ident.name, fi.kind.descriptive_variant(), "used"); diff --git a/src/librustc_passes/hir_stats.rs b/src/librustc_passes/hir_stats.rs index d7639362c57..4cde255fc83 100644 --- a/src/librustc_passes/hir_stats.rs +++ b/src/librustc_passes/hir_stats.rs @@ -133,7 +133,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { hir_visit::walk_mod(self, m, n) } - fn visit_foreign_item(&mut self, i: &'v hir::ForeignItem) { + fn visit_foreign_item(&mut self, i: &'v hir::ForeignItem<'v>) { self.record("ForeignItem", Id::Node(i.hir_id), i); hir_visit::walk_foreign_item(self, i) } diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index b60c6fe183f..5963561c5bb 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -708,7 +708,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { } } hir::ItemKind::ForeignMod(ref foreign_mod) => { - for foreign_item in &foreign_mod.items { + for foreign_item in foreign_mod.items { if foreign_item.vis.node.is_pub() { self.update(foreign_item.hir_id, item_level); } @@ -812,7 +812,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { } // Visit everything, but foreign items have their own levels. hir::ItemKind::ForeignMod(ref foreign_mod) => { - for foreign_item in &foreign_mod.items { + for foreign_item in foreign_mod.items { let foreign_item_level = self.get(foreign_item.hir_id); if foreign_item_level.is_some() { self.reach(foreign_item.hir_id, foreign_item_level) @@ -1621,7 +1621,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { } } - fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem) { + fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem<'tcx>) { if self.access_levels.is_reachable(item.hir_id) { intravisit::walk_foreign_item(self, item) } @@ -1898,7 +1898,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> } // Subitems of foreign modules have their own publicity. hir::ItemKind::ForeignMod(ref foreign_mod) => { - for foreign_item in &foreign_mod.items { + for foreign_item in foreign_mod.items { let vis = ty::Visibility::from_hir(&foreign_item.vis, item.hir_id, tcx); self.check(foreign_item.hir_id, vis).generics().predicates().ty(); } diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index c5eb94e2165..d6661a7ec6a 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -17,7 +17,7 @@ use std::iter; fn equate_intrinsic_type<'tcx>( tcx: TyCtxt<'tcx>, - it: &hir::ForeignItem, + it: &hir::ForeignItem<'_>, n_tps: usize, abi: Abi, safety: hir::Unsafety, @@ -83,7 +83,7 @@ pub fn intrinsic_operation_unsafety(intrinsic: &str) -> hir::Unsafety { /// Remember to add all intrinsics here, in librustc_codegen_llvm/intrinsic.rs, /// and in libcore/intrinsics.rs -pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) { +pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { let param = |n| tcx.mk_ty_param(n, Symbol::intern(&format!("P{}", n))); let name = it.ident.as_str(); @@ -399,7 +399,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) { } /// Type-check `extern "platform-intrinsic" { ... }` functions. -pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) { +pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { let param = |n| { let name = Symbol::intern(&format!("P{}", n)); tcx.mk_ty_param(n, name) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 90e31f85a12..4c83ee1c644 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1766,15 +1766,15 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) { check_abi(tcx, it.span, m.abi); if m.abi == Abi::RustIntrinsic { - for item in &m.items { + for item in m.items { intrinsic::check_intrinsic_type(tcx, item); } } else if m.abi == Abi::PlatformIntrinsic { - for item in &m.items { + for item in m.items { intrinsic::check_platform_intrinsic_type(tcx, item); } } else { - for item in &m.items { + for item in m.items { let generics = tcx.generics_of(tcx.hir().local_def_id(item.hir_id)); let own_counts = generics.own_counts(); if generics.params.len() - own_counts.lifetimes != 0 { @@ -4689,7 +4689,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Some(Node::ForeignItem(hir::ForeignItem { kind: hir::ForeignItemKind::Fn(_, idents, _), .. - })) | + })) => sugg_call = idents.iter() + .map(|ident| if ident.name != kw::SelfLower { + ident.to_string() + } else { + "_".to_string() + }).collect::>() + .join(", "), Some(Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Method(.., hir::TraitMethod::Required(idents)), .. diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 701f16f37b5..02831784c96 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -417,7 +417,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) { | hir::ItemKind::Mod(_) | hir::ItemKind::GlobalAsm(_) => {} hir::ItemKind::ForeignMod(ref foreign_mod) => { - for item in &foreign_mod.items { + for item in foreign_mod.items { let def_id = tcx.hir().local_def_id(item.hir_id); tcx.generics_of(def_id); tcx.type_of(def_id); diff --git a/src/librustc_typeck/variance/constraints.rs b/src/librustc_typeck/variance/constraints.rs index 41854407a09..d15d8d09df7 100644 --- a/src/librustc_typeck/variance/constraints.rs +++ b/src/librustc_typeck/variance/constraints.rs @@ -93,7 +93,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> { } hir::ItemKind::ForeignMod(ref foreign_mod) => { - for foreign_item in &foreign_mod.items { + for foreign_item in foreign_mod.items { if let hir::ForeignItemKind::Fn(..) = foreign_item.kind { self.visit_node_helper(foreign_item.hir_id); } diff --git a/src/librustc_typeck/variance/terms.rs b/src/librustc_typeck/variance/terms.rs index e122b334b31..7567bb791fa 100644 --- a/src/librustc_typeck/variance/terms.rs +++ b/src/librustc_typeck/variance/terms.rs @@ -156,7 +156,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for TermsContext<'a, 'tcx> { } hir::ItemKind::ForeignMod(ref foreign_mod) => { - for foreign_item in &foreign_mod.items { + for foreign_item in foreign_mod.items { if let hir::ForeignItemKind::Fn(..) = foreign_item.kind { self.add_inferreds_for_item(foreign_item.hir_id); } diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index 83a33c840e3..57208bd5966 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -217,7 +217,7 @@ pub struct ForeignItem<'hir> { pub vis: &'hir hir::Visibility, pub id: hir::HirId, pub name: Name, - pub kind: &'hir hir::ForeignItemKind, + pub kind: &'hir hir::ForeignItemKind<'hir>, pub attrs: &'hir [ast::Attribute], pub whence: Span, } diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index b9e409f3d58..2c2a51928d9 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -363,7 +363,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { match item.kind { hir::ItemKind::ForeignMod(ref fm) => { - for item in &fm.items { + for item in fm.items { self.visit_foreign_item(item, None, om); } } From 0f7d77363b551eb9a1dc4ae348d213180eae070d Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 28 Nov 2019 21:47:10 +0100 Subject: [PATCH 05/12] Use Arena inside hir::TraitItem. --- src/librustc/hir/check_attr.rs | 4 ++-- src/librustc/hir/intravisit.rs | 6 +++--- src/librustc/hir/itemlikevisit.rs | 8 ++++---- src/librustc/hir/lowering.rs | 2 +- src/librustc/hir/lowering/item.rs | 13 +++++++------ src/librustc/hir/map/blocks.rs | 2 +- src/librustc/hir/map/collector.rs | 2 +- src/librustc/hir/map/hir_id_validator.rs | 2 +- src/librustc/hir/map/mod.rs | 6 +++--- src/librustc/hir/mod.rs | 18 +++++++++--------- src/librustc/hir/print.rs | 2 +- src/librustc/ich/impls_hir.rs | 2 +- src/librustc/infer/error_reporting/mod.rs | 2 +- src/librustc/lint/context.rs | 2 +- src/librustc/lint/mod.rs | 6 +++--- src/librustc/middle/diagnostic_items.rs | 2 +- src/librustc/middle/lang_items.rs | 2 +- src/librustc/middle/reachable.rs | 2 +- src/librustc/middle/resolve_lifetime.rs | 2 +- src/librustc/middle/stability.rs | 4 ++-- .../symbol_names_test.rs | 2 +- src/librustc_incremental/assert_dep_graph.rs | 2 +- .../persist/dirty_clean.rs | 2 +- src/librustc_interface/proc_macro_decls.rs | 2 +- src/librustc_lint/builtin.rs | 2 +- src/librustc_lint/nonstandard_style.rs | 4 ++-- src/librustc_metadata/foreign_modules.rs | 2 +- src/librustc_metadata/link_args.rs | 2 +- src/librustc_metadata/native_libs.rs | 2 +- src/librustc_metadata/rmeta/encoder.rs | 4 ++-- src/librustc_mir/build/mod.rs | 5 ++++- src/librustc_mir/monomorphize/collector.rs | 2 +- src/librustc_passes/dead.rs | 4 ++-- src/librustc_passes/entry.rs | 2 +- src/librustc_passes/hir_stats.rs | 2 +- src/librustc_passes/layout_test.rs | 2 +- src/librustc_plugin_impl/build.rs | 2 +- src/librustc_privacy/lib.rs | 4 ++-- src/librustc_traits/lowering/mod.rs | 2 +- src/librustc_typeck/check/method/suggest.rs | 2 +- src/librustc_typeck/check/mod.rs | 2 +- src/librustc_typeck/check/wfcheck.rs | 2 +- src/librustc_typeck/check_unused.rs | 4 ++-- .../coherence/inherent_impls.rs | 2 +- .../coherence/inherent_impls_overlap.rs | 2 +- src/librustc_typeck/coherence/orphan.rs | 2 +- src/librustc_typeck/coherence/unsafety.rs | 2 +- src/librustc_typeck/collect.rs | 4 ++-- src/librustc_typeck/impl_wf_check.rs | 2 +- src/librustc_typeck/outlives/implicit_infer.rs | 2 +- src/librustc_typeck/outlives/test.rs | 2 +- src/librustc_typeck/variance/constraints.rs | 2 +- src/librustc_typeck/variance/terms.rs | 2 +- src/librustc_typeck/variance/test.rs | 2 +- src/librustdoc/clean/mod.rs | 14 +++++++------- src/librustdoc/doctree.rs | 2 +- 56 files changed, 96 insertions(+), 92 deletions(-) diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index d5acde2f463..6fbb8d783d4 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -107,7 +107,7 @@ impl Target { } } - fn from_trait_item(trait_item: &TraitItem) -> Target { + fn from_trait_item(trait_item: &TraitItem<'_>) -> Target { match trait_item.kind { TraitItemKind::Const(..) => Target::AssocConst, TraitItemKind::Method(_, hir::TraitMethod::Required(_)) => { @@ -498,7 +498,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> { intravisit::walk_item(self, item) } - fn visit_trait_item(&mut self, trait_item: &'tcx TraitItem) { + fn visit_trait_item(&mut self, trait_item: &'tcx TraitItem<'tcx>) { let target = Target::from_trait_item(trait_item); self.check_attributes(trait_item.hir_id, &trait_item.attrs, &trait_item.span, target, None); intravisit::walk_trait_item(self, trait_item) diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index d10b5cd0373..6143e2281e4 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -295,7 +295,7 @@ pub trait Visitor<'v>: Sized { fn visit_use(&mut self, path: &'v Path, hir_id: HirId) { walk_use(self, path, hir_id) } - fn visit_trait_item(&mut self, ti: &'v TraitItem) { + fn visit_trait_item(&mut self, ti: &'v TraitItem<'v>) { walk_trait_item(self, ti) } fn visit_trait_item_ref(&mut self, ii: &'v TraitItemRef) { @@ -849,9 +849,9 @@ pub fn walk_fn<'v, V: Visitor<'v>>(visitor: &mut V, visitor.visit_nested_body(body_id) } -pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v TraitItem) { +pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v TraitItem<'v>) { visitor.visit_ident(trait_item.ident); - walk_list!(visitor, visit_attribute, &trait_item.attrs); + walk_list!(visitor, visit_attribute, trait_item.attrs); visitor.visit_generics(&trait_item.generics); match trait_item.kind { TraitItemKind::Const(ref ty, default) => { diff --git a/src/librustc/hir/itemlikevisit.rs b/src/librustc/hir/itemlikevisit.rs index 4d3fd5e05b4..723cede0be6 100644 --- a/src/librustc/hir/itemlikevisit.rs +++ b/src/librustc/hir/itemlikevisit.rs @@ -46,7 +46,7 @@ use super::intravisit::Visitor; /// needed. pub trait ItemLikeVisitor<'hir> { fn visit_item(&mut self, item: &'hir Item<'hir>); - fn visit_trait_item(&mut self, trait_item: &'hir TraitItem); + fn visit_trait_item(&mut self, trait_item: &'hir TraitItem<'hir>); fn visit_impl_item(&mut self, impl_item: &'hir ImplItem); } @@ -69,7 +69,7 @@ impl<'v, 'hir, V> ItemLikeVisitor<'hir> for DeepVisitor<'v, V> self.visitor.visit_item(item); } - fn visit_trait_item(&mut self, trait_item: &'hir TraitItem) { + fn visit_trait_item(&mut self, trait_item: &'hir TraitItem<'hir>) { self.visitor.visit_trait_item(trait_item); } @@ -81,7 +81,7 @@ impl<'v, 'hir, V> ItemLikeVisitor<'hir> for DeepVisitor<'v, V> /// A parallel variant of `ItemLikeVisitor`. pub trait ParItemLikeVisitor<'hir> { fn visit_item(&self, item: &'hir Item<'hir>); - fn visit_trait_item(&self, trait_item: &'hir TraitItem); + fn visit_trait_item(&self, trait_item: &'hir TraitItem<'hir>); fn visit_impl_item(&self, impl_item: &'hir ImplItem); } @@ -99,7 +99,7 @@ impl<'hir, V> ParItemLikeVisitor<'hir> for ParDeepVisitor self.0.into_visitor().visit_item(item); } - fn visit_trait_item(&self, trait_item: &'hir TraitItem) { + fn visit_trait_item(&self, trait_item: &'hir TraitItem<'hir>) { self.0.into_visitor().visit_trait_item(trait_item); } diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 522f9adbaef..d380b87916c 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -97,7 +97,7 @@ pub struct LoweringContext<'a, 'hir: 'a> { /// The items being lowered are collected here. items: BTreeMap>, - trait_items: BTreeMap, + trait_items: BTreeMap>, impl_items: BTreeMap, bodies: BTreeMap, exported_macros: Vec>, diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index a19ddd5fd94..35a4f7cde6f 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -816,14 +816,14 @@ impl LoweringContext<'_, 'hir> { } } - fn lower_trait_item(&mut self, i: &AssocItem) -> hir::TraitItem { + fn lower_trait_item(&mut self, i: &AssocItem) -> hir::TraitItem<'hir> { let trait_item_def_id = self.resolver.definitions().local_def_id(i.id); let (generics, kind) = match i.kind { AssocItemKind::Const(ref ty, ref default) => ( self.lower_generics(&i.generics, ImplTraitContext::disallowed()), hir::TraitItemKind::Const( - self.lower_ty(ty, ImplTraitContext::disallowed()), + self.arena.alloc(self.lower_ty(ty, ImplTraitContext::disallowed()).into_inner()), default .as_ref() .map(|x| self.lower_const_body(i.span, Some(x))), @@ -852,12 +852,13 @@ impl LoweringContext<'_, 'hir> { (generics, hir::TraitItemKind::Method(sig, hir::TraitMethod::Provided(body_id))) } AssocItemKind::TyAlias(ref bounds, ref default) => { + let ty = default.as_ref().map(|x| -> &'hir hir::Ty { self.arena.alloc( + self.lower_ty(x, ImplTraitContext::disallowed()).into_inner()) + }); let generics = self.lower_generics(&i.generics, ImplTraitContext::disallowed()); let kind = hir::TraitItemKind::Type( self.lower_param_bounds(bounds, ImplTraitContext::disallowed()), - default - .as_ref() - .map(|x| self.lower_ty(x, ImplTraitContext::disallowed())), + ty, ); (generics, kind) @@ -868,7 +869,7 @@ impl LoweringContext<'_, 'hir> { hir::TraitItem { hir_id: self.lower_node_id(i.id), ident: i.ident, - attrs: self.lower_attrs(&i.attrs), + attrs: self.lower_attrs_arena(&i.attrs), generics, kind, span: i.span, diff --git a/src/librustc/hir/map/blocks.rs b/src/librustc/hir/map/blocks.rs index ee2c3b9879f..a9388825f16 100644 --- a/src/librustc/hir/map/blocks.rs +++ b/src/librustc/hir/map/blocks.rs @@ -53,7 +53,7 @@ impl MaybeFnLike for ast::ImplItem { } } -impl MaybeFnLike for ast::TraitItem { +impl MaybeFnLike for ast::TraitItem<'_> { fn is_fn_like(&self) -> bool { match self.kind { ast::TraitItemKind::Method(_, ast::TraitMethod::Provided(_)) => true, diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index c29ad49aca1..95b44ba403a 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -398,7 +398,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> { intravisit::walk_generic_param(self, param); } - fn visit_trait_item(&mut self, ti: &'hir TraitItem) { + fn visit_trait_item(&mut self, ti: &'hir TraitItem<'hir>) { debug_assert_eq!(ti.hir_id.owner, self.definitions.opt_def_index(self.hir_to_node_id[&ti.hir_id]).unwrap()); self.with_dep_node_owner(ti.hir_id.owner, ti, |this| { diff --git a/src/librustc/hir/map/hir_id_validator.rs b/src/librustc/hir/map/hir_id_validator.rs index 865b0198493..4657f8b03b0 100644 --- a/src/librustc/hir/map/hir_id_validator.rs +++ b/src/librustc/hir/map/hir_id_validator.rs @@ -58,7 +58,7 @@ impl<'a, 'hir> ItemLikeVisitor<'hir> for OuterVisitor<'a, 'hir> { inner_visitor.check(i.hir_id, |this| intravisit::walk_item(this, i)); } - fn visit_trait_item(&mut self, i: &'hir hir::TraitItem) { + fn visit_trait_item(&mut self, i: &'hir hir::TraitItem<'hir>) { let mut inner_visitor = self.new_inner_visitor(self.hir_map); inner_visitor.check(i.hir_id, |this| intravisit::walk_trait_item(this, i)); } diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index df4bc7cc817..d15d59b2210 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -443,7 +443,7 @@ impl<'hir> Map<'hir> { self.forest.krate() } - pub fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem { + pub fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir> { self.read(id.hir_id); // N.B., intentionally bypass `self.forest.krate()` so that we @@ -973,7 +973,7 @@ impl<'hir> Map<'hir> { } } - pub fn expect_trait_item(&self, id: HirId) -> &'hir TraitItem { + pub fn expect_trait_item(&self, id: HirId) -> &'hir TraitItem<'hir> { match self.find(id) { Some(Node::TraitItem(item)) => item, _ => bug!("expected trait item, found {}", self.node_to_string(id)) @@ -1252,7 +1252,7 @@ impl Named for Item<'_> { fn name(&self) -> Name { self.ident.name } } impl Named for ForeignItem<'_> { fn name(&self) -> Name { self.ident.name } } impl Named for Variant { fn name(&self) -> Name { self.ident.name } } impl Named for StructField { fn name(&self) -> Name { self.ident.name } } -impl Named for TraitItem { fn name(&self) -> Name { self.ident.name } } +impl Named for TraitItem<'_> { fn name(&self) -> Name { self.ident.name } } impl Named for ImplItem { fn name(&self) -> Name { self.ident.name } } pub fn map_crate<'hir>(sess: &crate::session::Session, diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index d3137ee6ac1..991e51e6dc3 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -758,7 +758,7 @@ pub struct Crate<'hir> { // slightly different results. pub items: BTreeMap>, - pub trait_items: BTreeMap, + pub trait_items: BTreeMap>, pub impl_items: BTreeMap, pub bodies: BTreeMap, pub trait_impls: BTreeMap>, @@ -779,7 +779,7 @@ impl Crate<'hir> { &self.items[&id] } - pub fn trait_item(&self, id: TraitItemId) -> &TraitItem { + pub fn trait_item(&self, id: TraitItemId) -> &TraitItem<'hir> { &self.trait_items[&id] } @@ -1897,12 +1897,12 @@ pub struct TraitItemId { /// either required (meaning it doesn't have an implementation, just a /// signature) or provided (meaning it has a default implementation). #[derive(RustcEncodable, RustcDecodable, Debug)] -pub struct TraitItem { +pub struct TraitItem<'hir> { pub ident: Ident, pub hir_id: HirId, - pub attrs: HirVec, + pub attrs: &'hir [Attribute], pub generics: Generics, - pub kind: TraitItemKind, + pub kind: TraitItemKind<'hir>, pub span: Span, } @@ -1918,14 +1918,14 @@ pub enum TraitMethod { /// Represents a trait method or associated constant or type #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] -pub enum TraitItemKind { +pub enum TraitItemKind<'hir> { /// An associated constant with an optional value (otherwise `impl`s must contain a value). - Const(P, Option), + Const(&'hir Ty, Option), /// A method with an optional body. Method(FnSig, TraitMethod), /// An associated type with (possibly empty) bounds and optional concrete /// type. - Type(GenericBounds, Option>), + Type(GenericBounds, Option<&'hir Ty>), } // The bodies for items are stored "out of line", in a separate @@ -2789,7 +2789,7 @@ pub enum Node<'hir> { Param(&'hir Param), Item(&'hir Item<'hir>), ForeignItem(&'hir ForeignItem<'hir>), - TraitItem(&'hir TraitItem), + TraitItem(&'hir TraitItem<'hir>), ImplItem(&'hir ImplItem), Variant(&'hir Variant), Field(&'hir StructField), diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index b6f7f840d08..d24d08575e7 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -846,7 +846,7 @@ impl<'a> State<'a> { body_id) } - pub fn print_trait_item(&mut self, ti: &hir::TraitItem) { + pub fn print_trait_item(&mut self, ti: &hir::TraitItem<'_>) { self.ann.pre(self, AnnNode::SubItem(ti.hir_id)); self.hardbreak_if_not_bol(); self.maybe_print_comment(ti.span.lo()); diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index f2e893ec055..149e647ca74 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -150,7 +150,7 @@ impl<'a> HashStable> for hir::Expr { } } -impl<'a> HashStable> for hir::TraitItem { +impl<'a> HashStable> for hir::TraitItem<'_> { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let hir::TraitItem { hir_id: _, diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 1a1c718e55a..f5e52c4d4b2 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -264,7 +264,7 @@ impl<'tcx> TyCtxt<'tcx> { } } - fn trait_item_scope_tag(item: &hir::TraitItem) -> &'static str { + fn trait_item_scope_tag(item: &hir::TraitItem<'_>) -> &'static str { match item.kind { hir::TraitItemKind::Method(..) => "method body", hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(..) => "associated item", diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index c3cd50b4885..8327977d9b0 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -1072,7 +1072,7 @@ for LateContextAndPass<'a, 'tcx, T> { hir_visit::walk_poly_trait_ref(self, t, m); } - fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) { + fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) { let generics = self.context.generics.take(); self.context.generics = Some(&trait_item.generics); self.with_lint_attrs(trait_item.hir_id, &trait_item.attrs, |cx| { diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 79fb53c92b0..3dad72543f5 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -124,8 +124,8 @@ macro_rules! late_lint_methods { d: Span, e: hir::HirId ); - fn check_trait_item(a: &$hir hir::TraitItem); - fn check_trait_item_post(a: &$hir hir::TraitItem); + fn check_trait_item(a: &$hir hir::TraitItem<$hir>); + fn check_trait_item_post(a: &$hir hir::TraitItem<$hir>); fn check_impl_item(a: &$hir hir::ImplItem); fn check_impl_item_post(a: &$hir hir::ImplItem); fn check_struct_def(a: &$hir hir::VariantData); @@ -649,7 +649,7 @@ impl intravisit::Visitor<'tcx> for LintLevelMapBuilder<'_, 'tcx> { }) } - fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) { + fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) { self.with_lint_attrs(trait_item.hir_id, &trait_item.attrs, |builder| { intravisit::walk_trait_item(builder, trait_item); }); diff --git a/src/librustc/middle/diagnostic_items.rs b/src/librustc/middle/diagnostic_items.rs index 57b1f09626f..466c7a37d0f 100644 --- a/src/librustc/middle/diagnostic_items.rs +++ b/src/librustc/middle/diagnostic_items.rs @@ -29,7 +29,7 @@ impl<'v, 'tcx> ItemLikeVisitor<'v> for DiagnosticItemCollector<'tcx> { self.observe_item(&item.attrs, item.hir_id); } - fn visit_trait_item(&mut self, trait_item: &hir::TraitItem) { + fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) { self.observe_item(&trait_item.attrs, trait_item.hir_id); } diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index cfb54b15b3b..dadc9261a3e 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -151,7 +151,7 @@ impl ItemLikeVisitor<'v> for LanguageItemCollector<'tcx> { } } - fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem) { + fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) { // At present, lang items are always items, not trait items. } diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 9f045a59df6..643c92185c8 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -387,7 +387,7 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx } } - fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem) {} + fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) {} fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) { // processed in visit_item above diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 7a852ef9ef4..c6a4a926ae4 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -771,7 +771,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { } } - fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) { + fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) { use self::hir::TraitItemKind::*; match trait_item.kind { Method(ref sig, _) => { diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 27830c86ed1..03c6abfbb84 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -283,7 +283,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { self.in_trait_impl = orig_in_trait_impl; } - fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem) { + fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem<'tcx>) { self.annotate(ti.hir_id, &ti.attrs, ti.span, AnnotationKind::Required, |v| { intravisit::walk_trait_item(v, ti); }); @@ -368,7 +368,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> { intravisit::walk_item(self, i) } - fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem) { + fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem<'tcx>) { self.check_missing_stability(ti.hir_id, ti.span, "item"); intravisit::walk_trait_item(self, ti); } diff --git a/src/librustc_codegen_utils/symbol_names_test.rs b/src/librustc_codegen_utils/symbol_names_test.rs index d468717fe7c..1a21be66c43 100644 --- a/src/librustc_codegen_utils/symbol_names_test.rs +++ b/src/librustc_codegen_utils/symbol_names_test.rs @@ -61,7 +61,7 @@ impl hir::itemlikevisit::ItemLikeVisitor<'tcx> for SymbolNamesTest<'tcx> { self.process_attrs(item.hir_id); } - fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) { + fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) { self.process_attrs(trait_item.hir_id); } diff --git a/src/librustc_incremental/assert_dep_graph.rs b/src/librustc_incremental/assert_dep_graph.rs index 8b016b12550..db64e736a5c 100644 --- a/src/librustc_incremental/assert_dep_graph.rs +++ b/src/librustc_incremental/assert_dep_graph.rs @@ -167,7 +167,7 @@ impl Visitor<'tcx> for IfThisChanged<'tcx> { intravisit::walk_item(self, item); } - fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) { + fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) { self.process_attrs(trait_item.hir_id, &trait_item.attrs); intravisit::walk_trait_item(self, trait_item); } diff --git a/src/librustc_incremental/persist/dirty_clean.rs b/src/librustc_incremental/persist/dirty_clean.rs index adb67b84087..b8f58ca2e91 100644 --- a/src/librustc_incremental/persist/dirty_clean.rs +++ b/src/librustc_incremental/persist/dirty_clean.rs @@ -536,7 +536,7 @@ impl ItemLikeVisitor<'tcx> for DirtyCleanVisitor<'tcx> { self.check_item(item.hir_id, item.span); } - fn visit_trait_item(&mut self, item: &hir::TraitItem) { + fn visit_trait_item(&mut self, item: &hir::TraitItem<'_>) { self.check_item(item.hir_id, item.span); } diff --git a/src/librustc_interface/proc_macro_decls.rs b/src/librustc_interface/proc_macro_decls.rs index 9c2e8a3d47e..c13dd595834 100644 --- a/src/librustc_interface/proc_macro_decls.rs +++ b/src/librustc_interface/proc_macro_decls.rs @@ -30,7 +30,7 @@ impl<'v> ItemLikeVisitor<'v> for Finder { } } - fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem) { + fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) { } fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) { diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 030fb8dc339..0a38ca55a24 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -436,7 +436,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { self.check_missing_docs_attrs(cx, Some(it.hir_id), &it.attrs, it.span, desc); } - fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, trait_item: &hir::TraitItem) { + fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, trait_item: &hir::TraitItem<'_>) { if self.private_traits.contains(&trait_item.hir_id) { return; } diff --git a/src/librustc_lint/nonstandard_style.rs b/src/librustc_lint/nonstandard_style.rs index 7235321b2b3..e4805f1217b 100644 --- a/src/librustc_lint/nonstandard_style.rs +++ b/src/librustc_lint/nonstandard_style.rs @@ -331,7 +331,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase { } } - fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::TraitItem) { + fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::TraitItem<'_>) { if let hir::TraitItemKind::Method(_, hir::TraitMethod::Required(pnames)) = &item.kind { self.check_snake_case(cx, "trait method", &item.ident); for param_name in pnames { @@ -398,7 +398,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals { } } - fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, ti: &hir::TraitItem) { + fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, ti: &hir::TraitItem<'_>) { if let hir::TraitItemKind::Const(..) = ti.kind { NonUpperCaseGlobals::check_upper_case(cx, "associated constant", &ti.ident); } diff --git a/src/librustc_metadata/foreign_modules.rs b/src/librustc_metadata/foreign_modules.rs index acfcdd9a87f..14f83642f9c 100644 --- a/src/librustc_metadata/foreign_modules.rs +++ b/src/librustc_metadata/foreign_modules.rs @@ -33,6 +33,6 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> { }); } - fn visit_trait_item(&mut self, _it: &'tcx hir::TraitItem) {} + fn visit_trait_item(&mut self, _it: &'tcx hir::TraitItem<'tcx>) {} fn visit_impl_item(&mut self, _it: &'tcx hir::ImplItem) {} } diff --git a/src/librustc_metadata/link_args.rs b/src/librustc_metadata/link_args.rs index 2283b772ea8..2fb0790cb46 100644 --- a/src/librustc_metadata/link_args.rs +++ b/src/librustc_metadata/link_args.rs @@ -45,7 +45,7 @@ impl<'tcx> ItemLikeVisitor<'tcx> for Collector { } } - fn visit_trait_item(&mut self, _it: &'tcx hir::TraitItem) {} + fn visit_trait_item(&mut self, _it: &'tcx hir::TraitItem<'tcx>) {} fn visit_impl_item(&mut self, _it: &'tcx hir::ImplItem) {} } diff --git a/src/librustc_metadata/native_libs.rs b/src/librustc_metadata/native_libs.rs index c9c3be46101..d8230b67037 100644 --- a/src/librustc_metadata/native_libs.rs +++ b/src/librustc_metadata/native_libs.rs @@ -129,7 +129,7 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> { } } - fn visit_trait_item(&mut self, _it: &'tcx hir::TraitItem) {} + fn visit_trait_item(&mut self, _it: &'tcx hir::TraitItem<'tcx>) {} fn visit_impl_item(&mut self, _it: &'tcx hir::ImplItem) {} } diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index 93e04c18f5f..0f168ff906f 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -864,7 +864,7 @@ impl EncodeContext<'tcx> { }); record!(self.per_def.visibility[def_id] <- trait_item.vis); record!(self.per_def.span[def_id] <- ast_item.span); - record!(self.per_def.attributes[def_id] <- &ast_item.attrs); + record!(self.per_def.attributes[def_id] <- ast_item.attrs); self.encode_stability(def_id); self.encode_const_stability(def_id); self.encode_deprecation(def_id); @@ -1725,7 +1725,7 @@ impl<'tcx, 'v> ItemLikeVisitor<'v> for ImplVisitor<'tcx> { } } - fn visit_trait_item(&mut self, _trait_item: &'v hir::TraitItem) {} + fn visit_trait_item(&mut self, _trait_item: &'v hir::TraitItem<'v>) {} fn visit_impl_item(&mut self, _impl_item: &'v hir::ImplItem) { // handled in `visit_item` above diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index df8e2b21285..9645607e5ac 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -59,7 +59,10 @@ pub fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> BodyAndCache<'_> { (*body_id, ty.span) } | Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Const(ty, body_id), .. }) - | Node::TraitItem( + => { + (*body_id, ty.span) + } + Node::TraitItem( hir::TraitItem { kind: hir::TraitItemKind::Const(ty, Some(body_id)), .. } ) => { (*body_id, ty.span) diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index d2b18ae0103..18b811be465 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -1059,7 +1059,7 @@ impl ItemLikeVisitor<'v> for RootCollector<'_, 'v> { } } - fn visit_trait_item(&mut self, _: &'v hir::TraitItem) { + fn visit_trait_item(&mut self, _: &'v hir::TraitItem<'v>) { // Even if there's a default body with no explicit generics, // it's still generic over some `Self: Trait`, so not a root. } diff --git a/src/librustc_passes/dead.rs b/src/librustc_passes/dead.rs index ee67e44afc8..b36db76c7df 100644 --- a/src/librustc_passes/dead.rs +++ b/src/librustc_passes/dead.rs @@ -417,7 +417,7 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> { } } - fn visit_trait_item(&mut self, _item: &hir::TraitItem) { + fn visit_trait_item(&mut self, _item: &hir::TraitItem<'_>) { // ignore: we are handling this in `visit_item` above } @@ -662,7 +662,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> { } // Overwrite so that we don't warn the trait item itself. - fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) { + fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) { match trait_item.kind { hir::TraitItemKind::Const(_, Some(body_id)) | hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(body_id)) => { diff --git a/src/librustc_passes/entry.rs b/src/librustc_passes/entry.rs index 89c1cc8e6b4..ad9a924d5d3 100644 --- a/src/librustc_passes/entry.rs +++ b/src/librustc_passes/entry.rs @@ -40,7 +40,7 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for EntryContext<'a, 'tcx> { find_item(item, self, at_root); } - fn visit_trait_item(&mut self, _trait_item: &'tcx TraitItem) { + fn visit_trait_item(&mut self, _trait_item: &'tcx TraitItem<'tcx>) { // Entry fn is never a trait item. } diff --git a/src/librustc_passes/hir_stats.rs b/src/librustc_passes/hir_stats.rs index 4cde255fc83..5598613e5c9 100644 --- a/src/librustc_passes/hir_stats.rs +++ b/src/librustc_passes/hir_stats.rs @@ -188,7 +188,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { hir_visit::walk_where_predicate(self, predicate) } - fn visit_trait_item(&mut self, ti: &'v hir::TraitItem) { + fn visit_trait_item(&mut self, ti: &'v hir::TraitItem<'v>) { self.record("TraitItem", Id::Node(ti.hir_id), ti); hir_visit::walk_trait_item(self, ti) } diff --git a/src/librustc_passes/layout_test.rs b/src/librustc_passes/layout_test.rs index 0e0725ccd67..24b6753c0c7 100644 --- a/src/librustc_passes/layout_test.rs +++ b/src/librustc_passes/layout_test.rs @@ -40,7 +40,7 @@ impl ItemLikeVisitor<'tcx> for VarianceTest<'tcx> { } } - fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem) {} + fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem<'tcx>) {} fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem) {} } diff --git a/src/librustc_plugin_impl/build.rs b/src/librustc_plugin_impl/build.rs index 02e2266d8f4..6da3e872628 100644 --- a/src/librustc_plugin_impl/build.rs +++ b/src/librustc_plugin_impl/build.rs @@ -22,7 +22,7 @@ impl<'v> ItemLikeVisitor<'v> for RegistrarFinder { } } - fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem) { + fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) { } fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) { diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 5963561c5bb..b7c06609fa3 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -1013,7 +1013,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> { self.tables = orig_tables; } - fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem) { + fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem<'tcx>) { let orig_tables = mem::replace(&mut self.tables, item_tables(self.tcx, ti.hir_id, self.empty_tables)); intravisit::walk_trait_item(self, ti); @@ -1295,7 +1295,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> { self.current_item = orig_current_item; } - fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem) { + fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem<'tcx>) { let orig_tables = mem::replace(&mut self.tables, item_tables(self.tcx, ti.hir_id, self.empty_tables)); intravisit::walk_trait_item(self, ti); diff --git a/src/librustc_traits/lowering/mod.rs b/src/librustc_traits/lowering/mod.rs index ecd3112cd79..1f5958ef8fb 100644 --- a/src/librustc_traits/lowering/mod.rs +++ b/src/librustc_traits/lowering/mod.rs @@ -674,7 +674,7 @@ impl Visitor<'tcx> for ClauseDumper<'tcx> { intravisit::walk_item(self, item); } - fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) { + fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) { self.process_attrs(trait_item.hir_id, &trait_item.attrs); intravisit::walk_trait_item(self, trait_item); } diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 99525cc30fd..3c6e6d974d9 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -1013,7 +1013,7 @@ fn compute_all_traits(tcx: TyCtxt<'_>) -> Vec { } } - fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem) {} + fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) {} fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) {} } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 4c83ee1c644..ce5a385b587 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -754,7 +754,7 @@ impl ItemLikeVisitor<'tcx> for CheckItemTypesVisitor<'tcx> { fn visit_item(&mut self, i: &'tcx hir::Item<'tcx>) { check_item_type(self.tcx, i); } - fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem) { } + fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem<'tcx>) { } fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem) { } } diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 9e69b0a2908..207db48860f 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -1087,7 +1087,7 @@ impl ParItemLikeVisitor<'tcx> for CheckTypeWellFormedVisitor<'tcx> { self.tcx.ensure().check_item_well_formed(def_id); } - fn visit_trait_item(&self, trait_item: &'tcx hir::TraitItem) { + fn visit_trait_item(&self, trait_item: &'tcx hir::TraitItem<'tcx>) { debug!("visit_trait_item: {:?}", trait_item); let def_id = self.tcx.hir().local_def_id(trait_item.hir_id); self.tcx.ensure().check_trait_item_well_formed(def_id); diff --git a/src/librustc_typeck/check_unused.rs b/src/librustc_typeck/check_unused.rs index bbb743cd3c7..950954a66ef 100644 --- a/src/librustc_typeck/check_unused.rs +++ b/src/librustc_typeck/check_unused.rs @@ -38,7 +38,7 @@ impl ItemLikeVisitor<'v> for CheckVisitor<'tcx> { } } - fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem) { + fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) { } fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) { @@ -231,7 +231,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for CollectExternCrateVisitor<'a, 'tcx> { } } - fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem) { + fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) { } fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) { diff --git a/src/librustc_typeck/coherence/inherent_impls.rs b/src/librustc_typeck/coherence/inherent_impls.rs index 13af3865225..2e4c25cf0df 100644 --- a/src/librustc_typeck/coherence/inherent_impls.rs +++ b/src/librustc_typeck/coherence/inherent_impls.rs @@ -254,7 +254,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> { } } - fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem) { + fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) { } fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) { diff --git a/src/librustc_typeck/coherence/inherent_impls_overlap.rs b/src/librustc_typeck/coherence/inherent_impls_overlap.rs index 84ae0b296a1..11bd0209c0d 100644 --- a/src/librustc_typeck/coherence/inherent_impls_overlap.rs +++ b/src/librustc_typeck/coherence/inherent_impls_overlap.rs @@ -98,7 +98,7 @@ impl ItemLikeVisitor<'v> for InherentOverlapChecker<'tcx> { } } - fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem) { + fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'v>) { } fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) { diff --git a/src/librustc_typeck/coherence/orphan.rs b/src/librustc_typeck/coherence/orphan.rs index 17487244ee7..85e5dad0ccd 100644 --- a/src/librustc_typeck/coherence/orphan.rs +++ b/src/librustc_typeck/coherence/orphan.rs @@ -218,7 +218,7 @@ impl ItemLikeVisitor<'v> for OrphanChecker<'tcx> { } } - fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem) { + fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) { } fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) { diff --git a/src/librustc_typeck/coherence/unsafety.rs b/src/librustc_typeck/coherence/unsafety.rs index 5335253f5d6..0a7c907fe5d 100644 --- a/src/librustc_typeck/coherence/unsafety.rs +++ b/src/librustc_typeck/coherence/unsafety.rs @@ -78,7 +78,7 @@ impl ItemLikeVisitor<'v> for UnsafetyChecker<'tcx> { } } - fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem) { + fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) { } fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) { diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 02831784c96..c09d56b3984 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -145,7 +145,7 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> { intravisit::walk_expr(self, expr); } - fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) { + fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) { convert_trait_item(self.tcx, trait_item.hir_id); intravisit::walk_trait_item(self, trait_item); } @@ -1711,7 +1711,7 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { intravisit::walk_impl_item(self, it); } } - fn visit_trait_item(&mut self, it: &'tcx TraitItem) { + fn visit_trait_item(&mut self, it: &'tcx TraitItem<'tcx>) { debug!("find_existential_constraints: visiting {:?}", it); let def_id = self.tcx.hir().local_def_id(it.hir_id); self.check(def_id); diff --git a/src/librustc_typeck/impl_wf_check.rs b/src/librustc_typeck/impl_wf_check.rs index 98438945d11..b7691189865 100644 --- a/src/librustc_typeck/impl_wf_check.rs +++ b/src/librustc_typeck/impl_wf_check.rs @@ -89,7 +89,7 @@ impl ItemLikeVisitor<'tcx> for ImplWfCheck<'tcx> { } } - fn visit_trait_item(&mut self, _trait_item: &'tcx hir::TraitItem) { } + fn visit_trait_item(&mut self, _trait_item: &'tcx hir::TraitItem<'tcx>) { } fn visit_impl_item(&mut self, _impl_item: &'tcx hir::ImplItem) { } } diff --git a/src/librustc_typeck/outlives/implicit_infer.rs b/src/librustc_typeck/outlives/implicit_infer.rs index 4ed631232b4..edf83b1de1d 100644 --- a/src/librustc_typeck/outlives/implicit_infer.rs +++ b/src/librustc_typeck/outlives/implicit_infer.rs @@ -113,7 +113,7 @@ impl<'cx, 'tcx> ItemLikeVisitor<'tcx> for InferVisitor<'cx, 'tcx> { } } - fn visit_trait_item(&mut self, _trait_item: &'tcx hir::TraitItem) {} + fn visit_trait_item(&mut self, _trait_item: &'tcx hir::TraitItem<'tcx>) {} fn visit_impl_item(&mut self, _impl_item: &'tcx hir::ImplItem) {} } diff --git a/src/librustc_typeck/outlives/test.rs b/src/librustc_typeck/outlives/test.rs index 86f61158f5f..a8c4f9c0ebb 100644 --- a/src/librustc_typeck/outlives/test.rs +++ b/src/librustc_typeck/outlives/test.rs @@ -33,6 +33,6 @@ impl ItemLikeVisitor<'tcx> for OutlivesTest<'tcx> { } } - fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem) {} + fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem<'tcx>) {} fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem) {} } diff --git a/src/librustc_typeck/variance/constraints.rs b/src/librustc_typeck/variance/constraints.rs index d15d8d09df7..ff29c3ca4bd 100644 --- a/src/librustc_typeck/variance/constraints.rs +++ b/src/librustc_typeck/variance/constraints.rs @@ -104,7 +104,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> { } } - fn visit_trait_item(&mut self, trait_item: &hir::TraitItem) { + fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) { if let hir::TraitItemKind::Method(..) = trait_item.kind { self.visit_node_helper(trait_item.hir_id); } diff --git a/src/librustc_typeck/variance/terms.rs b/src/librustc_typeck/variance/terms.rs index 7567bb791fa..4de16e71553 100644 --- a/src/librustc_typeck/variance/terms.rs +++ b/src/librustc_typeck/variance/terms.rs @@ -167,7 +167,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for TermsContext<'a, 'tcx> { } } - fn visit_trait_item(&mut self, trait_item: &hir::TraitItem) { + fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) { if let hir::TraitItemKind::Method(..) = trait_item.kind { self.add_inferreds_for_item(trait_item.hir_id); } diff --git a/src/librustc_typeck/variance/test.rs b/src/librustc_typeck/variance/test.rs index 01088db0efb..416cb91c232 100644 --- a/src/librustc_typeck/variance/test.rs +++ b/src/librustc_typeck/variance/test.rs @@ -29,6 +29,6 @@ impl ItemLikeVisitor<'tcx> for VarianceTest<'tcx> { } } - fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem) { } + fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem<'tcx>) { } fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem) { } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index cebfd99452a..5dd82689369 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -70,6 +70,12 @@ impl, U, V: Idx> Clean> for IndexVec { } } +impl, U> Clean for &T { + fn clean(&self, cx: &DocContext<'_>) -> U { + (**self).clean(cx) + } +} + impl, U> Clean for P { fn clean(&self, cx: &DocContext<'_>) -> U { (**self).clean(cx) @@ -1080,7 +1086,7 @@ impl Clean for hir::PolyTraitRef { } } -impl Clean for hir::TraitItem { +impl Clean for hir::TraitItem<'_> { fn clean(&self, cx: &DocContext<'_>) -> Item { let inner = match self.kind { hir::TraitItemKind::Const(ref ty, default) => { @@ -2386,12 +2392,6 @@ impl Clean for attr::Stability { } } -impl<'a> Clean for &'a attr::Stability { - fn clean(&self, dc: &DocContext<'_>) -> Stability { - (**self).clean(dc) - } -} - impl Clean for attr::Deprecation { fn clean(&self, _: &DocContext<'_>) -> Deprecation { Deprecation { diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index 57208bd5966..f5de869cf13 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -179,7 +179,7 @@ pub struct Trait<'hir> { pub is_auto: hir::IsAuto, pub unsafety: hir::Unsafety, pub name: Name, - pub items: Vec<&'hir hir::TraitItem>, + pub items: Vec<&'hir hir::TraitItem<'hir>>, pub generics: &'hir hir::Generics, pub bounds: &'hir [hir::GenericBound], pub attrs: &'hir [ast::Attribute], From 5fec1ca0ff5727d1f4474f8dc3edf7c631baf712 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 28 Nov 2019 22:16:44 +0100 Subject: [PATCH 06/12] Use Arena inside hir::ImplItem. --- src/librustc/hir/check_attr.rs | 4 ++-- src/librustc/hir/intravisit.rs | 6 +++--- src/librustc/hir/itemlikevisit.rs | 8 ++++---- src/librustc/hir/lowering.rs | 2 +- src/librustc/hir/lowering/item.rs | 10 ++++++---- src/librustc/hir/map/blocks.rs | 2 +- src/librustc/hir/map/collector.rs | 2 +- src/librustc/hir/map/hir_id_validator.rs | 2 +- src/librustc/hir/map/mod.rs | 6 +++--- src/librustc/hir/mod.rs | 18 +++++++++--------- src/librustc/hir/print.rs | 2 +- src/librustc/ich/impls_hir.rs | 2 +- src/librustc/infer/error_reporting/mod.rs | 2 +- src/librustc/lint/context.rs | 2 +- src/librustc/lint/mod.rs | 6 +++--- src/librustc/middle/diagnostic_items.rs | 2 +- src/librustc/middle/lang_items.rs | 2 +- src/librustc/middle/reachable.rs | 4 ++-- src/librustc/middle/resolve_lifetime.rs | 2 +- src/librustc/middle/stability.rs | 4 ++-- .../symbol_names_test.rs | 2 +- src/librustc_incremental/assert_dep_graph.rs | 2 +- .../persist/dirty_clean.rs | 2 +- src/librustc_interface/proc_macro_decls.rs | 2 +- src/librustc_lint/builtin.rs | 4 ++-- src/librustc_lint/nonstandard_style.rs | 2 +- src/librustc_metadata/foreign_modules.rs | 2 +- src/librustc_metadata/link_args.rs | 2 +- src/librustc_metadata/native_libs.rs | 2 +- src/librustc_metadata/rmeta/encoder.rs | 4 ++-- src/librustc_mir/build/mod.rs | 8 +------- src/librustc_mir/monomorphize/collector.rs | 2 +- src/librustc_passes/dead.rs | 4 ++-- src/librustc_passes/entry.rs | 2 +- src/librustc_passes/hir_stats.rs | 2 +- src/librustc_passes/layout_test.rs | 2 +- src/librustc_plugin_impl/build.rs | 2 +- src/librustc_privacy/lib.rs | 4 ++-- src/librustc_traits/lowering/mod.rs | 2 +- src/librustc_typeck/check/method/suggest.rs | 2 +- src/librustc_typeck/check/mod.rs | 6 +++--- src/librustc_typeck/check/wfcheck.rs | 2 +- src/librustc_typeck/check_unused.rs | 4 ++-- .../coherence/inherent_impls.rs | 2 +- .../coherence/inherent_impls_overlap.rs | 2 +- src/librustc_typeck/coherence/orphan.rs | 2 +- src/librustc_typeck/coherence/unsafety.rs | 2 +- src/librustc_typeck/collect.rs | 4 ++-- src/librustc_typeck/impl_wf_check.rs | 2 +- src/librustc_typeck/namespace.rs | 4 ++-- src/librustc_typeck/outlives/implicit_infer.rs | 2 +- src/librustc_typeck/outlives/test.rs | 2 +- src/librustc_typeck/variance/constraints.rs | 2 +- src/librustc_typeck/variance/terms.rs | 2 +- src/librustc_typeck/variance/test.rs | 2 +- src/librustdoc/clean/mod.rs | 2 +- src/librustdoc/doctree.rs | 2 +- 57 files changed, 91 insertions(+), 95 deletions(-) diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index 6fbb8d783d4..03282fc99a0 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -128,7 +128,7 @@ impl Target { } } - fn from_impl_item<'tcx>(tcx: TyCtxt<'tcx>, impl_item: &hir::ImplItem) -> Target { + fn from_impl_item<'tcx>(tcx: TyCtxt<'tcx>, impl_item: &hir::ImplItem<'_>) -> Target { match impl_item.kind { hir::ImplItemKind::Const(..) => Target::AssocConst, hir::ImplItemKind::Method(..) => { @@ -510,7 +510,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> { intravisit::walk_foreign_item(self, f_item) } - fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) { + fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) { let target = Target::from_impl_item(self.tcx, impl_item); self.check_attributes(impl_item.hir_id, &impl_item.attrs, &impl_item.span, target, None); intravisit::walk_impl_item(self, impl_item) diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 6143e2281e4..fcd2d758420 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -301,7 +301,7 @@ pub trait Visitor<'v>: Sized { fn visit_trait_item_ref(&mut self, ii: &'v TraitItemRef) { walk_trait_item_ref(self, ii) } - fn visit_impl_item(&mut self, ii: &'v ImplItem) { + fn visit_impl_item(&mut self, ii: &'v ImplItem<'v>) { walk_impl_item(self, ii) } fn visit_impl_item_ref(&mut self, ii: &'v ImplItemRef) { @@ -893,14 +893,14 @@ pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref: visitor.visit_defaultness(defaultness); } -pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem) { +pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem<'v>) { // N.B., deliberately force a compilation error if/when new fields are added. let ImplItem { hir_id: _, ident, ref vis, ref defaultness, - ref attrs, + attrs, ref generics, ref kind, span: _, diff --git a/src/librustc/hir/itemlikevisit.rs b/src/librustc/hir/itemlikevisit.rs index 723cede0be6..30b41ea4acb 100644 --- a/src/librustc/hir/itemlikevisit.rs +++ b/src/librustc/hir/itemlikevisit.rs @@ -47,7 +47,7 @@ use super::intravisit::Visitor; pub trait ItemLikeVisitor<'hir> { fn visit_item(&mut self, item: &'hir Item<'hir>); fn visit_trait_item(&mut self, trait_item: &'hir TraitItem<'hir>); - fn visit_impl_item(&mut self, impl_item: &'hir ImplItem); + fn visit_impl_item(&mut self, impl_item: &'hir ImplItem<'hir>); } pub struct DeepVisitor<'v, V> { @@ -73,7 +73,7 @@ impl<'v, 'hir, V> ItemLikeVisitor<'hir> for DeepVisitor<'v, V> self.visitor.visit_trait_item(trait_item); } - fn visit_impl_item(&mut self, impl_item: &'hir ImplItem) { + fn visit_impl_item(&mut self, impl_item: &'hir ImplItem<'hir>) { self.visitor.visit_impl_item(impl_item); } } @@ -82,7 +82,7 @@ impl<'v, 'hir, V> ItemLikeVisitor<'hir> for DeepVisitor<'v, V> pub trait ParItemLikeVisitor<'hir> { fn visit_item(&self, item: &'hir Item<'hir>); fn visit_trait_item(&self, trait_item: &'hir TraitItem<'hir>); - fn visit_impl_item(&self, impl_item: &'hir ImplItem); + fn visit_impl_item(&self, impl_item: &'hir ImplItem<'hir>); } pub trait IntoVisitor<'hir> { @@ -103,7 +103,7 @@ impl<'hir, V> ParItemLikeVisitor<'hir> for ParDeepVisitor self.0.into_visitor().visit_trait_item(trait_item); } - fn visit_impl_item(&self, impl_item: &'hir ImplItem) { + fn visit_impl_item(&self, impl_item: &'hir ImplItem<'hir>) { self.0.into_visitor().visit_impl_item(impl_item); } } diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index d380b87916c..74615cbe945 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -98,7 +98,7 @@ pub struct LoweringContext<'a, 'hir: 'a> { items: BTreeMap>, trait_items: BTreeMap>, - impl_items: BTreeMap, + impl_items: BTreeMap>, bodies: BTreeMap, exported_macros: Vec>, non_exported_macro_attrs: Vec, diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index 35a4f7cde6f..1953d6f88f8 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -906,14 +906,14 @@ impl LoweringContext<'_, 'hir> { self.expr(span, hir::ExprKind::Err, AttrVec::new()) } - fn lower_impl_item(&mut self, i: &AssocItem) -> hir::ImplItem { + fn lower_impl_item(&mut self, i: &AssocItem) -> hir::ImplItem<'hir> { let impl_item_def_id = self.resolver.definitions().local_def_id(i.id); let (generics, kind) = match i.kind { AssocItemKind::Const(ref ty, ref expr) => ( self.lower_generics(&i.generics, ImplTraitContext::disallowed()), hir::ImplItemKind::Const( - self.lower_ty(ty, ImplTraitContext::disallowed()), + self.arena.alloc(self.lower_ty(ty, ImplTraitContext::disallowed()).into_inner()), self.lower_const_body(i.span, expr.as_deref()), ), ), @@ -940,11 +940,13 @@ impl LoweringContext<'_, 'hir> { let generics = self.lower_generics(&i.generics, ImplTraitContext::disallowed()); let kind = match ty { None => { - hir::ImplItemKind::TyAlias(P(self.ty(i.span, hir::TyKind::Err))) + let ty = self.arena.alloc(self.ty(i.span, hir::TyKind::Err)); + hir::ImplItemKind::TyAlias(ty) } Some(ty) => match ty.kind.opaque_top_hack() { None => { let ty = self.lower_ty(ty, ImplTraitContext::disallowed()); + let ty = self.arena.alloc(ty.into_inner()); hir::ImplItemKind::TyAlias(ty) } Some(bs) => { @@ -961,7 +963,7 @@ impl LoweringContext<'_, 'hir> { hir::ImplItem { hir_id: self.lower_node_id(i.id), ident: i.ident, - attrs: self.lower_attrs(&i.attrs), + attrs: self.lower_attrs_arena(&i.attrs), generics, vis: self.lower_visibility(&i.vis, None), defaultness: self.lower_defaultness(i.defaultness, true /* [1] */), diff --git a/src/librustc/hir/map/blocks.rs b/src/librustc/hir/map/blocks.rs index a9388825f16..ab04a8a10aa 100644 --- a/src/librustc/hir/map/blocks.rs +++ b/src/librustc/hir/map/blocks.rs @@ -44,7 +44,7 @@ impl MaybeFnLike for ast::Item<'_> { } } -impl MaybeFnLike for ast::ImplItem { +impl MaybeFnLike for ast::ImplItem<'_> { fn is_fn_like(&self) -> bool { match self.kind { ast::ImplItemKind::Method(..) => true, diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index 95b44ba403a..8e60581fbce 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -410,7 +410,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> { }); } - fn visit_impl_item(&mut self, ii: &'hir ImplItem) { + fn visit_impl_item(&mut self, ii: &'hir ImplItem<'hir>) { debug_assert_eq!(ii.hir_id.owner, self.definitions.opt_def_index(self.hir_to_node_id[&ii.hir_id]).unwrap()); self.with_dep_node_owner(ii.hir_id.owner, ii, |this| { diff --git a/src/librustc/hir/map/hir_id_validator.rs b/src/librustc/hir/map/hir_id_validator.rs index 4657f8b03b0..0a06473ed30 100644 --- a/src/librustc/hir/map/hir_id_validator.rs +++ b/src/librustc/hir/map/hir_id_validator.rs @@ -63,7 +63,7 @@ impl<'a, 'hir> ItemLikeVisitor<'hir> for OuterVisitor<'a, 'hir> { inner_visitor.check(i.hir_id, |this| intravisit::walk_trait_item(this, i)); } - fn visit_impl_item(&mut self, i: &'hir hir::ImplItem) { + fn visit_impl_item(&mut self, i: &'hir hir::ImplItem<'hir>) { let mut inner_visitor = self.new_inner_visitor(self.hir_map); inner_visitor.check(i.hir_id, |this| intravisit::walk_impl_item(this, i)); } diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index d15d59b2210..6803a605437 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -451,7 +451,7 @@ impl<'hir> Map<'hir> { self.forest.krate.trait_item(id) } - pub fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem { + pub fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir> { self.read(id.hir_id); // N.B., intentionally bypass `self.forest.krate()` so that we @@ -966,7 +966,7 @@ impl<'hir> Map<'hir> { } } - pub fn expect_impl_item(&self, id: HirId) -> &'hir ImplItem { + pub fn expect_impl_item(&self, id: HirId) -> &'hir ImplItem<'hir> { match self.find(id) { Some(Node::ImplItem(item)) => item, _ => bug!("expected impl item, found {}", self.node_to_string(id)) @@ -1253,7 +1253,7 @@ impl Named for ForeignItem<'_> { fn name(&self) -> Name { self.ident.name } } impl Named for Variant { fn name(&self) -> Name { self.ident.name } } impl Named for StructField { fn name(&self) -> Name { self.ident.name } } impl Named for TraitItem<'_> { fn name(&self) -> Name { self.ident.name } } -impl Named for ImplItem { fn name(&self) -> Name { self.ident.name } } +impl Named for ImplItem<'_> { fn name(&self) -> Name { self.ident.name } } pub fn map_crate<'hir>(sess: &crate::session::Session, cstore: &CrateStoreDyn, diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 991e51e6dc3..51368d2acc3 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -759,7 +759,7 @@ pub struct Crate<'hir> { pub items: BTreeMap>, pub trait_items: BTreeMap>, - pub impl_items: BTreeMap, + pub impl_items: BTreeMap>, pub bodies: BTreeMap, pub trait_impls: BTreeMap>, @@ -783,7 +783,7 @@ impl Crate<'hir> { &self.trait_items[&id] } - pub fn impl_item(&self, id: ImplItemId) -> &ImplItem { + pub fn impl_item(&self, id: ImplItemId) -> &ImplItem<'hir> { &self.impl_items[&id] } @@ -1938,27 +1938,27 @@ pub struct ImplItemId { /// Represents anything within an `impl` block. #[derive(RustcEncodable, RustcDecodable, Debug)] -pub struct ImplItem { +pub struct ImplItem<'hir> { pub ident: Ident, pub hir_id: HirId, pub vis: Visibility, pub defaultness: Defaultness, - pub attrs: HirVec, + pub attrs: &'hir [Attribute], pub generics: Generics, - pub kind: ImplItemKind, + pub kind: ImplItemKind<'hir>, pub span: Span, } /// Represents various kinds of content within an `impl`. #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] -pub enum ImplItemKind { +pub enum ImplItemKind<'hir> { /// An associated constant of the given type, set to the constant result /// of the expression. - Const(P, BodyId), + Const(&'hir Ty, BodyId), /// A method implementation with the given signature and body. Method(FnSig, BodyId), /// An associated type. - TyAlias(P), + TyAlias(&'hir Ty), /// An associated `type = impl Trait`. OpaqueTy(GenericBounds), } @@ -2790,7 +2790,7 @@ pub enum Node<'hir> { Item(&'hir Item<'hir>), ForeignItem(&'hir ForeignItem<'hir>), TraitItem(&'hir TraitItem<'hir>), - ImplItem(&'hir ImplItem), + ImplItem(&'hir ImplItem<'hir>), Variant(&'hir Variant), Field(&'hir StructField), AnonConst(&'hir AnonConst), diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index d24d08575e7..dc270fc40c9 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -882,7 +882,7 @@ impl<'a> State<'a> { self.ann.post(self, AnnNode::SubItem(ti.hir_id)) } - pub fn print_impl_item(&mut self, ii: &hir::ImplItem) { + pub fn print_impl_item(&mut self, ii: &hir::ImplItem<'_>) { self.ann.pre(self, AnnNode::SubItem(ii.hir_id)); self.hardbreak_if_not_bol(); self.maybe_print_comment(ii.span.lo()); diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 149e647ca74..a91535b5516 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -172,7 +172,7 @@ impl<'a> HashStable> for hir::TraitItem<'_> { } -impl<'a> HashStable> for hir::ImplItem { +impl<'a> HashStable> for hir::ImplItem<'_> { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let hir::ImplItem { hir_id: _, diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index f5e52c4d4b2..347960ac222 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -271,7 +271,7 @@ impl<'tcx> TyCtxt<'tcx> { } } - fn impl_item_scope_tag(item: &hir::ImplItem) -> &'static str { + fn impl_item_scope_tag(item: &hir::ImplItem<'_>) -> &'static str { match item.kind { hir::ImplItemKind::Method(..) => "method body", hir::ImplItemKind::Const(..) diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 8327977d9b0..490599e582f 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -1085,7 +1085,7 @@ for LateContextAndPass<'a, 'tcx, T> { self.context.generics = generics; } - fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) { + fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) { let generics = self.context.generics.take(); self.context.generics = Some(&impl_item.generics); self.with_lint_attrs(impl_item.hir_id, &impl_item.attrs, |cx| { diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 3dad72543f5..12417d6089a 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -126,8 +126,8 @@ macro_rules! late_lint_methods { ); fn check_trait_item(a: &$hir hir::TraitItem<$hir>); fn check_trait_item_post(a: &$hir hir::TraitItem<$hir>); - fn check_impl_item(a: &$hir hir::ImplItem); - fn check_impl_item_post(a: &$hir hir::ImplItem); + fn check_impl_item(a: &$hir hir::ImplItem<$hir>); + fn check_impl_item_post(a: &$hir hir::ImplItem<$hir>); fn check_struct_def(a: &$hir hir::VariantData); fn check_struct_def_post(a: &$hir hir::VariantData); fn check_struct_field(a: &$hir hir::StructField); @@ -655,7 +655,7 @@ impl intravisit::Visitor<'tcx> for LintLevelMapBuilder<'_, 'tcx> { }); } - fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) { + fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) { self.with_lint_attrs(impl_item.hir_id, &impl_item.attrs, |builder| { intravisit::walk_impl_item(builder, impl_item); }); diff --git a/src/librustc/middle/diagnostic_items.rs b/src/librustc/middle/diagnostic_items.rs index 466c7a37d0f..96faf567463 100644 --- a/src/librustc/middle/diagnostic_items.rs +++ b/src/librustc/middle/diagnostic_items.rs @@ -33,7 +33,7 @@ impl<'v, 'tcx> ItemLikeVisitor<'v> for DiagnosticItemCollector<'tcx> { self.observe_item(&trait_item.attrs, trait_item.hir_id); } - fn visit_impl_item(&mut self, impl_item: &hir::ImplItem) { + fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) { self.observe_item(&impl_item.attrs, impl_item.hir_id); } } diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index dadc9261a3e..d87eec05866 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -155,7 +155,7 @@ impl ItemLikeVisitor<'v> for LanguageItemCollector<'tcx> { // At present, lang items are always items, not trait items. } - fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) { + fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) { // At present, lang items are always items, not impl items. } } diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 643c92185c8..6746df6c7de 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -47,7 +47,7 @@ fn item_might_be_inlined(tcx: TyCtxt<'tcx>, item: &hir::Item<'_>, attrs: Codegen fn method_might_be_inlined( tcx: TyCtxt<'_>, - impl_item: &hir::ImplItem, + impl_item: &hir::ImplItem<'_>, impl_src: DefId, ) -> bool { let codegen_fn_attrs = tcx.codegen_fn_attrs(impl_item.hir_id.owner_def_id()); @@ -389,7 +389,7 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) {} - fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) { + fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) { // processed in visit_item above } } diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index c6a4a926ae4..38a7c67b907 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -823,7 +823,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { } } - fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) { + fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) { use self::hir::ImplItemKind::*; match impl_item.kind { Method(ref sig, _) => { diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 03c6abfbb84..0aef5b24fc7 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -289,7 +289,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { }); } - fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem) { + fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) { let kind = if self.in_trait_impl { AnnotationKind::Prohibited } else { @@ -373,7 +373,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> { intravisit::walk_trait_item(self, ti); } - fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem) { + fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) { let impl_def_id = self.tcx.hir().local_def_id( self.tcx.hir().get_parent_item(ii.hir_id)); if self.tcx.impl_trait_ref(impl_def_id).is_none() { diff --git a/src/librustc_codegen_utils/symbol_names_test.rs b/src/librustc_codegen_utils/symbol_names_test.rs index 1a21be66c43..893aea16fd2 100644 --- a/src/librustc_codegen_utils/symbol_names_test.rs +++ b/src/librustc_codegen_utils/symbol_names_test.rs @@ -65,7 +65,7 @@ impl hir::itemlikevisit::ItemLikeVisitor<'tcx> for SymbolNamesTest<'tcx> { self.process_attrs(trait_item.hir_id); } - fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) { + fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) { self.process_attrs(impl_item.hir_id); } } diff --git a/src/librustc_incremental/assert_dep_graph.rs b/src/librustc_incremental/assert_dep_graph.rs index db64e736a5c..feab4ca0a31 100644 --- a/src/librustc_incremental/assert_dep_graph.rs +++ b/src/librustc_incremental/assert_dep_graph.rs @@ -172,7 +172,7 @@ impl Visitor<'tcx> for IfThisChanged<'tcx> { intravisit::walk_trait_item(self, trait_item); } - fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) { + fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) { self.process_attrs(impl_item.hir_id, &impl_item.attrs); intravisit::walk_impl_item(self, impl_item); } diff --git a/src/librustc_incremental/persist/dirty_clean.rs b/src/librustc_incremental/persist/dirty_clean.rs index b8f58ca2e91..7c9ed24f53b 100644 --- a/src/librustc_incremental/persist/dirty_clean.rs +++ b/src/librustc_incremental/persist/dirty_clean.rs @@ -540,7 +540,7 @@ impl ItemLikeVisitor<'tcx> for DirtyCleanVisitor<'tcx> { self.check_item(item.hir_id, item.span); } - fn visit_impl_item(&mut self, item: &hir::ImplItem) { + fn visit_impl_item(&mut self, item: &hir::ImplItem<'_>) { self.check_item(item.hir_id, item.span); } } diff --git a/src/librustc_interface/proc_macro_decls.rs b/src/librustc_interface/proc_macro_decls.rs index c13dd595834..e3def175626 100644 --- a/src/librustc_interface/proc_macro_decls.rs +++ b/src/librustc_interface/proc_macro_decls.rs @@ -33,7 +33,7 @@ impl<'v> ItemLikeVisitor<'v> for Finder { fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) { } - fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) { + fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) { } } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 0a38ca55a24..2037daded6d 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -454,7 +454,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { desc); } - fn check_impl_item(&mut self, cx: &LateContext<'_, '_>, impl_item: &hir::ImplItem) { + fn check_impl_item(&mut self, cx: &LateContext<'_, '_>, impl_item: &hir::ImplItem<'_>) { // If the method is an impl for a trait, don't doc. if method_context(cx, impl_item.hir_id) == MethodLateContext::TraitImpl { return; @@ -1005,7 +1005,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnreachablePub { self.perform_lint(cx, "field", field.hir_id, &field.vis, field.span, false); } - fn check_impl_item(&mut self, cx: &LateContext<'_, '_>, impl_item: &hir::ImplItem) { + fn check_impl_item(&mut self, cx: &LateContext<'_, '_>, impl_item: &hir::ImplItem<'_>) { self.perform_lint(cx, "item", impl_item.hir_id, &impl_item.vis, impl_item.span, false); } } diff --git a/src/librustc_lint/nonstandard_style.rs b/src/librustc_lint/nonstandard_style.rs index e4805f1217b..2f06d5f3f7b 100644 --- a/src/librustc_lint/nonstandard_style.rs +++ b/src/librustc_lint/nonstandard_style.rs @@ -404,7 +404,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals { } } - fn check_impl_item(&mut self, cx: &LateContext<'_, '_>, ii: &hir::ImplItem) { + fn check_impl_item(&mut self, cx: &LateContext<'_, '_>, ii: &hir::ImplItem<'_>) { if let hir::ImplItemKind::Const(..) = ii.kind { NonUpperCaseGlobals::check_upper_case(cx, "associated constant", &ii.ident); } diff --git a/src/librustc_metadata/foreign_modules.rs b/src/librustc_metadata/foreign_modules.rs index 14f83642f9c..2311e0422f6 100644 --- a/src/librustc_metadata/foreign_modules.rs +++ b/src/librustc_metadata/foreign_modules.rs @@ -34,5 +34,5 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> { } fn visit_trait_item(&mut self, _it: &'tcx hir::TraitItem<'tcx>) {} - fn visit_impl_item(&mut self, _it: &'tcx hir::ImplItem) {} + fn visit_impl_item(&mut self, _it: &'tcx hir::ImplItem<'tcx>) {} } diff --git a/src/librustc_metadata/link_args.rs b/src/librustc_metadata/link_args.rs index 2fb0790cb46..10dfc3c72e5 100644 --- a/src/librustc_metadata/link_args.rs +++ b/src/librustc_metadata/link_args.rs @@ -46,7 +46,7 @@ impl<'tcx> ItemLikeVisitor<'tcx> for Collector { } fn visit_trait_item(&mut self, _it: &'tcx hir::TraitItem<'tcx>) {} - fn visit_impl_item(&mut self, _it: &'tcx hir::ImplItem) {} + fn visit_impl_item(&mut self, _it: &'tcx hir::ImplItem<'tcx>) {} } impl Collector { diff --git a/src/librustc_metadata/native_libs.rs b/src/librustc_metadata/native_libs.rs index d8230b67037..6ab20271774 100644 --- a/src/librustc_metadata/native_libs.rs +++ b/src/librustc_metadata/native_libs.rs @@ -130,7 +130,7 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> { } fn visit_trait_item(&mut self, _it: &'tcx hir::TraitItem<'tcx>) {} - fn visit_impl_item(&mut self, _it: &'tcx hir::ImplItem) {} + fn visit_impl_item(&mut self, _it: &'tcx hir::ImplItem<'tcx>) {} } impl Collector<'tcx> { diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index 0f168ff906f..6a803997468 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -945,7 +945,7 @@ impl EncodeContext<'tcx> { }); record!(self.per_def.visibility[def_id] <- impl_item.vis); record!(self.per_def.span[def_id] <- ast_item.span); - record!(self.per_def.attributes[def_id] <- &ast_item.attrs); + record!(self.per_def.attributes[def_id] <- ast_item.attrs); self.encode_stability(def_id); self.encode_const_stability(def_id); self.encode_deprecation(def_id); @@ -1727,7 +1727,7 @@ impl<'tcx, 'v> ItemLikeVisitor<'v> for ImplVisitor<'tcx> { fn visit_trait_item(&mut self, _trait_item: &'v hir::TraitItem<'v>) {} - fn visit_impl_item(&mut self, _impl_item: &'v hir::ImplItem) { + fn visit_impl_item(&mut self, _impl_item: &'v hir::ImplItem<'v>) { // handled in `visit_item` above } } diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 9645607e5ac..3479ad6749a 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -55,14 +55,8 @@ pub fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> BodyAndCache<'_> { } Node::Item(hir::Item { kind: hir::ItemKind::Static(ty, _, body_id), .. }) | Node::Item(hir::Item { kind: hir::ItemKind::Const(ty, body_id), .. }) - => { - (*body_id, ty.span) - } | Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Const(ty, body_id), .. }) - => { - (*body_id, ty.span) - } - Node::TraitItem( + | Node::TraitItem( hir::TraitItem { kind: hir::TraitItemKind::Const(ty, Some(body_id)), .. } ) => { (*body_id, ty.span) diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index 18b811be465..83a4f224aa2 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -1064,7 +1064,7 @@ impl ItemLikeVisitor<'v> for RootCollector<'_, 'v> { // it's still generic over some `Self: Trait`, so not a root. } - fn visit_impl_item(&mut self, ii: &'v hir::ImplItem) { + fn visit_impl_item(&mut self, ii: &'v hir::ImplItem<'v>) { match ii.kind { hir::ImplItemKind::Method(hir::FnSig { .. }, _) => { let def_id = self.tcx.hir().local_def_id(ii.hir_id); diff --git a/src/librustc_passes/dead.rs b/src/librustc_passes/dead.rs index b36db76c7df..dba5a3dbd2b 100644 --- a/src/librustc_passes/dead.rs +++ b/src/librustc_passes/dead.rs @@ -421,7 +421,7 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> { // ignore: we are handling this in `visit_item` above } - fn visit_impl_item(&mut self, _item: &hir::ImplItem) { + fn visit_impl_item(&mut self, _item: &hir::ImplItem<'_>) { // ignore: we are handling this in `visit_item` above } } @@ -636,7 +636,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> { intravisit::walk_struct_field(self, field); } - fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) { + fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) { match impl_item.kind { hir::ImplItemKind::Const(_, body_id) => { if !self.symbol_is_live(impl_item.hir_id) { diff --git a/src/librustc_passes/entry.rs b/src/librustc_passes/entry.rs index ad9a924d5d3..77ee6ce8513 100644 --- a/src/librustc_passes/entry.rs +++ b/src/librustc_passes/entry.rs @@ -44,7 +44,7 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for EntryContext<'a, 'tcx> { // Entry fn is never a trait item. } - fn visit_impl_item(&mut self, _impl_item: &'tcx ImplItem) { + fn visit_impl_item(&mut self, _impl_item: &'tcx ImplItem<'tcx>) { // Entry fn is never a trait item. } } diff --git a/src/librustc_passes/hir_stats.rs b/src/librustc_passes/hir_stats.rs index 5598613e5c9..297b527d846 100644 --- a/src/librustc_passes/hir_stats.rs +++ b/src/librustc_passes/hir_stats.rs @@ -193,7 +193,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { hir_visit::walk_trait_item(self, ti) } - fn visit_impl_item(&mut self, ii: &'v hir::ImplItem) { + fn visit_impl_item(&mut self, ii: &'v hir::ImplItem<'v>) { self.record("ImplItem", Id::Node(ii.hir_id), ii); hir_visit::walk_impl_item(self, ii) } diff --git a/src/librustc_passes/layout_test.rs b/src/librustc_passes/layout_test.rs index 24b6753c0c7..d7872f80d26 100644 --- a/src/librustc_passes/layout_test.rs +++ b/src/librustc_passes/layout_test.rs @@ -41,7 +41,7 @@ impl ItemLikeVisitor<'tcx> for VarianceTest<'tcx> { } fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem<'tcx>) {} - fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem) {} + fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem<'tcx>) {} } impl VarianceTest<'tcx> { diff --git a/src/librustc_plugin_impl/build.rs b/src/librustc_plugin_impl/build.rs index 6da3e872628..8ceef5a4b76 100644 --- a/src/librustc_plugin_impl/build.rs +++ b/src/librustc_plugin_impl/build.rs @@ -25,7 +25,7 @@ impl<'v> ItemLikeVisitor<'v> for RegistrarFinder { fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) { } - fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) { + fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) { } } diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index b7c06609fa3..95f8cc9af35 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -1020,7 +1020,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> { self.tables = orig_tables; } - fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem) { + fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) { let orig_tables = mem::replace(&mut self.tables, item_tables(self.tcx, ii.hir_id, self.empty_tables)); intravisit::walk_impl_item(self, ii); @@ -1302,7 +1302,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> { self.tables = orig_tables; } - fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem) { + fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) { let orig_tables = mem::replace(&mut self.tables, item_tables(self.tcx, ii.hir_id, self.empty_tables)); intravisit::walk_impl_item(self, ii); diff --git a/src/librustc_traits/lowering/mod.rs b/src/librustc_traits/lowering/mod.rs index 1f5958ef8fb..e6de2b279fc 100644 --- a/src/librustc_traits/lowering/mod.rs +++ b/src/librustc_traits/lowering/mod.rs @@ -679,7 +679,7 @@ impl Visitor<'tcx> for ClauseDumper<'tcx> { intravisit::walk_trait_item(self, trait_item); } - fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) { + fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) { self.process_attrs(impl_item.hir_id, &impl_item.attrs); intravisit::walk_impl_item(self, impl_item); } diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 3c6e6d974d9..aecc46d3128 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -1015,7 +1015,7 @@ fn compute_all_traits(tcx: TyCtxt<'_>) -> Vec { fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) {} - fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) {} + fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) {} } tcx.hir().krate().visit_all_item_likes(&mut Visitor { diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index ce5a385b587..5ba03ab753b 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -755,7 +755,7 @@ impl ItemLikeVisitor<'tcx> for CheckItemTypesVisitor<'tcx> { check_item_type(self.tcx, i); } fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem<'tcx>) { } - fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem) { } + fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem<'tcx>) { } } pub fn check_wf_new(tcx: TyCtxt<'_>) { @@ -1865,7 +1865,7 @@ fn check_on_unimplemented(tcx: TyCtxt<'_>, trait_def_id: DefId, item: &hir::Item fn report_forbidden_specialization( tcx: TyCtxt<'_>, - impl_item: &hir::ImplItem, + impl_item: &hir::ImplItem<'_>, parent_impl: DefId, ) { let mut err = struct_span_err!( @@ -1895,7 +1895,7 @@ fn check_specialization_validity<'tcx>( trait_def: &ty::TraitDef, trait_item: &ty::AssocItem, impl_id: DefId, - impl_item: &hir::ImplItem, + impl_item: &hir::ImplItem<'_>, ) { let kind = match impl_item.kind { hir::ImplItemKind::Const(..) => ty::AssocKind::Const, diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 207db48860f..5b7513b5263 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -1093,7 +1093,7 @@ impl ParItemLikeVisitor<'tcx> for CheckTypeWellFormedVisitor<'tcx> { self.tcx.ensure().check_trait_item_well_formed(def_id); } - fn visit_impl_item(&self, impl_item: &'tcx hir::ImplItem) { + fn visit_impl_item(&self, impl_item: &'tcx hir::ImplItem<'tcx>) { debug!("visit_impl_item: {:?}", impl_item); let def_id = self.tcx.hir().local_def_id(impl_item.hir_id); self.tcx.ensure().check_impl_item_well_formed(def_id); diff --git a/src/librustc_typeck/check_unused.rs b/src/librustc_typeck/check_unused.rs index 950954a66ef..7377c4df979 100644 --- a/src/librustc_typeck/check_unused.rs +++ b/src/librustc_typeck/check_unused.rs @@ -41,7 +41,7 @@ impl ItemLikeVisitor<'v> for CheckVisitor<'tcx> { fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) { } - fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) { + fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) { } } @@ -234,6 +234,6 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for CollectExternCrateVisitor<'a, 'tcx> { fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) { } - fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) { + fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) { } } diff --git a/src/librustc_typeck/coherence/inherent_impls.rs b/src/librustc_typeck/coherence/inherent_impls.rs index 2e4c25cf0df..16fe6d529a4 100644 --- a/src/librustc_typeck/coherence/inherent_impls.rs +++ b/src/librustc_typeck/coherence/inherent_impls.rs @@ -257,7 +257,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> { fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) { } - fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) { + fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) { } } diff --git a/src/librustc_typeck/coherence/inherent_impls_overlap.rs b/src/librustc_typeck/coherence/inherent_impls_overlap.rs index 11bd0209c0d..1acbf0795a6 100644 --- a/src/librustc_typeck/coherence/inherent_impls_overlap.rs +++ b/src/librustc_typeck/coherence/inherent_impls_overlap.rs @@ -101,6 +101,6 @@ impl ItemLikeVisitor<'v> for InherentOverlapChecker<'tcx> { fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'v>) { } - fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) { + fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'v>) { } } diff --git a/src/librustc_typeck/coherence/orphan.rs b/src/librustc_typeck/coherence/orphan.rs index 85e5dad0ccd..109609f5d49 100644 --- a/src/librustc_typeck/coherence/orphan.rs +++ b/src/librustc_typeck/coherence/orphan.rs @@ -221,6 +221,6 @@ impl ItemLikeVisitor<'v> for OrphanChecker<'tcx> { fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) { } - fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) { + fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) { } } diff --git a/src/librustc_typeck/coherence/unsafety.rs b/src/librustc_typeck/coherence/unsafety.rs index 0a7c907fe5d..324ac0a0f35 100644 --- a/src/librustc_typeck/coherence/unsafety.rs +++ b/src/librustc_typeck/coherence/unsafety.rs @@ -81,6 +81,6 @@ impl ItemLikeVisitor<'v> for UnsafetyChecker<'tcx> { fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) { } - fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) { + fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) { } } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index c09d56b3984..9d260bde751 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -150,7 +150,7 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> { intravisit::walk_trait_item(self, trait_item); } - fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) { + fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) { convert_impl_item(self.tcx, impl_item.hir_id); intravisit::walk_impl_item(self, impl_item); } @@ -1702,7 +1702,7 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { intravisit::walk_item(self, it); } } - fn visit_impl_item(&mut self, it: &'tcx ImplItem) { + fn visit_impl_item(&mut self, it: &'tcx ImplItem<'tcx>) { debug!("find_existential_constraints: visiting {:?}", it); let def_id = self.tcx.hir().local_def_id(it.hir_id); // The opaque type itself or its children are not within its reveal scope. diff --git a/src/librustc_typeck/impl_wf_check.rs b/src/librustc_typeck/impl_wf_check.rs index b7691189865..7bcc5386445 100644 --- a/src/librustc_typeck/impl_wf_check.rs +++ b/src/librustc_typeck/impl_wf_check.rs @@ -91,7 +91,7 @@ impl ItemLikeVisitor<'tcx> for ImplWfCheck<'tcx> { fn visit_trait_item(&mut self, _trait_item: &'tcx hir::TraitItem<'tcx>) { } - fn visit_impl_item(&mut self, _impl_item: &'tcx hir::ImplItem) { } + fn visit_impl_item(&mut self, _impl_item: &'tcx hir::ImplItem<'tcx>) { } } fn enforce_impl_params_are_constrained( diff --git a/src/librustc_typeck/namespace.rs b/src/librustc_typeck/namespace.rs index 1e1d3e7865c..553c93e0958 100644 --- a/src/librustc_typeck/namespace.rs +++ b/src/librustc_typeck/namespace.rs @@ -19,8 +19,8 @@ impl From for Namespace { } } -impl<'a> From <&'a hir::ImplItemKind> for Namespace { - fn from(impl_kind: &'a hir::ImplItemKind) -> Self { +impl<'a> From <&'a hir::ImplItemKind<'_>> for Namespace { + fn from(impl_kind: &'a hir::ImplItemKind<'_>) -> Self { match *impl_kind { hir::ImplItemKind::OpaqueTy(..) | hir::ImplItemKind::TyAlias(..) => Namespace::Type, diff --git a/src/librustc_typeck/outlives/implicit_infer.rs b/src/librustc_typeck/outlives/implicit_infer.rs index edf83b1de1d..e3947a84989 100644 --- a/src/librustc_typeck/outlives/implicit_infer.rs +++ b/src/librustc_typeck/outlives/implicit_infer.rs @@ -115,7 +115,7 @@ impl<'cx, 'tcx> ItemLikeVisitor<'tcx> for InferVisitor<'cx, 'tcx> { fn visit_trait_item(&mut self, _trait_item: &'tcx hir::TraitItem<'tcx>) {} - fn visit_impl_item(&mut self, _impl_item: &'tcx hir::ImplItem) {} + fn visit_impl_item(&mut self, _impl_item: &'tcx hir::ImplItem<'tcx>) {} } fn insert_required_predicates_to_be_wf<'tcx>( diff --git a/src/librustc_typeck/outlives/test.rs b/src/librustc_typeck/outlives/test.rs index a8c4f9c0ebb..081d0ff1e16 100644 --- a/src/librustc_typeck/outlives/test.rs +++ b/src/librustc_typeck/outlives/test.rs @@ -34,5 +34,5 @@ impl ItemLikeVisitor<'tcx> for OutlivesTest<'tcx> { } fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem<'tcx>) {} - fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem) {} + fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem<'tcx>) {} } diff --git a/src/librustc_typeck/variance/constraints.rs b/src/librustc_typeck/variance/constraints.rs index ff29c3ca4bd..1d16562e0e6 100644 --- a/src/librustc_typeck/variance/constraints.rs +++ b/src/librustc_typeck/variance/constraints.rs @@ -110,7 +110,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> { } } - fn visit_impl_item(&mut self, impl_item: &hir::ImplItem) { + fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) { if let hir::ImplItemKind::Method(..) = impl_item.kind { self.visit_node_helper(impl_item.hir_id); } diff --git a/src/librustc_typeck/variance/terms.rs b/src/librustc_typeck/variance/terms.rs index 4de16e71553..c97ac24ce50 100644 --- a/src/librustc_typeck/variance/terms.rs +++ b/src/librustc_typeck/variance/terms.rs @@ -173,7 +173,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for TermsContext<'a, 'tcx> { } } - fn visit_impl_item(&mut self, impl_item: &hir::ImplItem) { + fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) { if let hir::ImplItemKind::Method(..) = impl_item.kind { self.add_inferreds_for_item(impl_item.hir_id); } diff --git a/src/librustc_typeck/variance/test.rs b/src/librustc_typeck/variance/test.rs index 416cb91c232..1233be43e09 100644 --- a/src/librustc_typeck/variance/test.rs +++ b/src/librustc_typeck/variance/test.rs @@ -30,5 +30,5 @@ impl ItemLikeVisitor<'tcx> for VarianceTest<'tcx> { } fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem<'tcx>) { } - fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem) { } + fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem<'tcx>) { } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 5dd82689369..55c3e9e4a24 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1127,7 +1127,7 @@ impl Clean for hir::TraitItem<'_> { } } -impl Clean for hir::ImplItem { +impl Clean for hir::ImplItem<'_> { fn clean(&self, cx: &DocContext<'_>) -> Item { let inner = match self.kind { hir::ImplItemKind::Const(ref ty, expr) => { diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index f5de869cf13..6aa23248719 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -206,7 +206,7 @@ pub struct Impl<'hir> { pub generics: &'hir hir::Generics, pub trait_: &'hir Option, pub for_: &'hir hir::Ty, - pub items: Vec<&'hir hir::ImplItem>, + pub items: Vec<&'hir hir::ImplItem<'hir>>, pub attrs: &'hir [ast::Attribute], pub whence: Span, pub vis: &'hir hir::Visibility, From 4f1c88be46a1d541ab09214a3b894192e19b554a Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 29 Nov 2019 09:26:18 +0100 Subject: [PATCH 07/12] Use Arena inside hir::EnumDef. --- src/librustc/arena.rs | 2 ++ src/librustc/hir/check_attr.rs | 2 +- src/librustc/hir/def.rs | 2 +- src/librustc/hir/intravisit.rs | 16 +++++------ src/librustc/hir/lowering/item.rs | 18 +++++++------ src/librustc/hir/map/collector.rs | 2 +- src/librustc/hir/map/mod.rs | 6 ++--- src/librustc/hir/mod.rs | 30 ++++++++++----------- src/librustc/hir/print.rs | 8 +++--- src/librustc/lint/context.rs | 4 +-- src/librustc/lint/mod.rs | 10 +++---- src/librustc/middle/stability.rs | 4 +-- src/librustc_lint/builtin.rs | 2 +- src/librustc_lint/nonstandard_style.rs | 2 +- src/librustc_mir/transform/mod.rs | 2 +- src/librustc_passes/dead.rs | 8 +++--- src/librustc_passes/hir_stats.rs | 2 +- src/librustc_privacy/lib.rs | 8 +++--- src/librustc_typeck/check/mod.rs | 6 ++--- src/librustc_typeck/check/wfcheck.rs | 4 +-- src/librustc_typeck/collect.rs | 4 +-- src/librustc_typeck/variance/constraints.rs | 2 +- src/librustc_typeck/variance/terms.rs | 2 +- src/librustdoc/clean/mod.rs | 4 +-- src/librustdoc/doctree.rs | 2 +- 25 files changed, 78 insertions(+), 74 deletions(-) diff --git a/src/librustc/arena.rs b/src/librustc/arena.rs index 3f0c0277f8a..a892a7a25ba 100644 --- a/src/librustc/arena.rs +++ b/src/librustc/arena.rs @@ -131,8 +131,10 @@ macro_rules! arena_types { [] impl_item_ref: rustc::hir::ImplItemRef, [] macro_def: rustc::hir::MacroDef<$tcx>, [] path: rustc::hir::Path, + [] struct_field: rustc::hir::StructField, [] trait_item_ref: rustc::hir::TraitItemRef, [] ty: rustc::hir::Ty, + [] variant: rustc::hir::Variant<$tcx>, ], $tcx); ) } diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index 03282fc99a0..9e95cba7fcb 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -529,7 +529,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> { fn is_c_like_enum(item: &Item<'_>) -> bool { if let ItemKind::Enum(ref def, _) = item.kind { - for variant in &def.variants { + for variant in def.variants { match variant.data { hir::VariantData::Unit(..) => { /* continue */ } _ => return false, diff --git a/src/librustc/hir/def.rs b/src/librustc/hir/def.rs index 231b054f974..d4e89c5f047 100644 --- a/src/librustc/hir/def.rs +++ b/src/librustc/hir/def.rs @@ -340,7 +340,7 @@ impl CtorKind { } } - pub fn from_hir(vdata: &hir::VariantData) -> CtorKind { + pub fn from_hir(vdata: &hir::VariantData<'_>) -> CtorKind { match *vdata { hir::VariantData::Tuple(..) => CtorKind::Fn, hir::VariantData::Unit(..) => CtorKind::Const, diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index fcd2d758420..094d390f826 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -317,7 +317,7 @@ pub trait Visitor<'v>: Sized { walk_poly_trait_ref(self, t, m) } fn visit_variant_data(&mut self, - s: &'v VariantData, + s: &'v VariantData<'v>, _: Name, _: &'v Generics, _parent_id: HirId, @@ -328,13 +328,13 @@ pub trait Visitor<'v>: Sized { walk_struct_field(self, s) } fn visit_enum_def(&mut self, - enum_definition: &'v EnumDef, + enum_definition: &'v EnumDef<'v>, generics: &'v Generics, item_id: HirId, _: Span) { walk_enum_def(self, enum_definition, generics, item_id) } - fn visit_variant(&mut self, v: &'v Variant, g: &'v Generics, item_id: HirId) { + fn visit_variant(&mut self, v: &'v Variant<'v>, g: &'v Generics, item_id: HirId) { walk_variant(self, v, g, item_id) } fn visit_label(&mut self, label: &'v Label) { @@ -565,19 +565,19 @@ pub fn walk_use<'v, V: Visitor<'v>>(visitor: &mut V, } pub fn walk_enum_def<'v, V: Visitor<'v>>(visitor: &mut V, - enum_definition: &'v EnumDef, + enum_definition: &'v EnumDef<'v>, generics: &'v Generics, item_id: HirId) { visitor.visit_id(item_id); walk_list!(visitor, visit_variant, - &enum_definition.variants, + enum_definition.variants, generics, item_id); } pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V, - variant: &'v Variant, + variant: &'v Variant<'v>, generics: &'v Generics, parent_item_id: HirId) { visitor.visit_ident(variant.ident); @@ -588,7 +588,7 @@ pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V, parent_item_id, variant.span); walk_list!(visitor, visit_anon_const, &variant.disr_expr); - walk_list!(visitor, visit_attribute, &variant.attrs); + walk_list!(visitor, visit_attribute, variant.attrs); } pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) { @@ -948,7 +948,7 @@ pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, impl_item_ref: &' visitor.visit_defaultness(defaultness); } -pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V, struct_definition: &'v VariantData) { +pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V, struct_definition: &'v VariantData<'v>) { if let Some(ctor_hir_id) = struct_definition.ctor_hir_id() { visitor.visit_id(ctor_hir_id); } diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index 1953d6f88f8..158957b4ada 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -363,11 +363,12 @@ impl LoweringContext<'_, 'hir> { ItemKind::Enum(ref enum_definition, ref generics) => { hir::ItemKind::Enum( hir::EnumDef { - variants: enum_definition + variants: self.arena.alloc_from_iter( + enum_definition .variants .iter() .map(|x| self.lower_variant(x)) - .collect(), + ), }, self.lower_generics(generics, ImplTraitContext::disallowed()), ) @@ -756,9 +757,9 @@ impl LoweringContext<'_, 'hir> { self.arena.alloc(hir::GlobalAsm { asm: ga.asm }) } - fn lower_variant(&mut self, v: &Variant) -> hir::Variant { + fn lower_variant(&mut self, v: &Variant) -> hir::Variant<'hir> { hir::Variant { - attrs: self.lower_attrs(&v.attrs), + attrs: self.lower_attrs_arena(&v.attrs), data: self.lower_variant_data(&v.data), disr_expr: v.disr_expr.as_ref().map(|e| self.lower_anon_const(e)), id: self.lower_node_id(v.id), @@ -767,19 +768,20 @@ impl LoweringContext<'_, 'hir> { } } - fn lower_variant_data(&mut self, vdata: &VariantData) -> hir::VariantData { + fn lower_variant_data(&mut self, vdata: &VariantData) -> hir::VariantData<'hir> { match *vdata { VariantData::Struct(ref fields, recovered) => hir::VariantData::Struct( - fields.iter().enumerate().map(|f| self.lower_struct_field(f)).collect(), + self.arena.alloc_from_iter(fields.iter().enumerate().map(|f| self.lower_struct_field(f))), recovered, ), VariantData::Tuple(ref fields, id) => { hir::VariantData::Tuple( - fields + self.arena.alloc_from_iter( + fields .iter() .enumerate() .map(|f| self.lower_struct_field(f)) - .collect(), + ), self.lower_node_id(id), ) }, diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index 8e60581fbce..00d61fb2fb0 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -539,7 +539,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> { }); } - fn visit_variant(&mut self, v: &'hir Variant, g: &'hir Generics, item_id: HirId) { + fn visit_variant(&mut self, v: &'hir Variant<'hir>, g: &'hir Generics, item_id: HirId) { self.insert(v.span, v.id, Node::Variant(v)); self.with_parent(v.id, |this| { // Register the constructor of this variant. diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 6803a605437..8865157a319 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -980,7 +980,7 @@ impl<'hir> Map<'hir> { } } - pub fn expect_variant_data(&self, id: HirId) -> &'hir VariantData { + pub fn expect_variant_data(&self, id: HirId) -> &'hir VariantData<'hir> { match self.find(id) { Some(Node::Item(i)) => { match i.kind { @@ -995,7 +995,7 @@ impl<'hir> Map<'hir> { } } - pub fn expect_variant(&self, id: HirId) -> &'hir Variant { + pub fn expect_variant(&self, id: HirId) -> &'hir Variant<'hir> { match self.find(id) { Some(Node::Variant(variant)) => variant, _ => bug!("expected variant, found {}", self.node_to_string(id)), @@ -1250,7 +1250,7 @@ impl Named for Spanned { fn name(&self) -> Name { self.node.name() } impl Named for Item<'_> { fn name(&self) -> Name { self.ident.name } } impl Named for ForeignItem<'_> { fn name(&self) -> Name { self.ident.name } } -impl Named for Variant { fn name(&self) -> Name { self.ident.name } } +impl Named for Variant<'_> { fn name(&self) -> Name { self.ident.name } } impl Named for StructField { fn name(&self) -> Name { self.ident.name } } impl Named for TraitItem<'_> { fn name(&self) -> Name { self.ident.name } } impl Named for ImplItem<'_> { fn name(&self) -> Name { self.ident.name } } diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 51368d2acc3..813cbe503e2 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -2263,21 +2263,21 @@ pub struct GlobalAsm { } #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] -pub struct EnumDef { - pub variants: HirVec, +pub struct EnumDef<'hir> { + pub variants: &'hir [Variant<'hir>], } #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] -pub struct Variant { +pub struct Variant<'hir> { /// Name of the variant. #[stable_hasher(project(name))] pub ident: Ident, /// Attributes of the variant. - pub attrs: HirVec, + pub attrs: &'hir [Attribute], /// Id of the variant (not the constructor, see `VariantData::ctor_hir_id()`). pub id: HirId, /// Fields and constructor id of the variant. - pub data: VariantData, + pub data: VariantData<'hir>, /// Explicit discriminant (e.g., `Foo = 1`). pub disr_expr: Option, /// Span @@ -2397,24 +2397,24 @@ impl StructField { /// Fields and constructor IDs of enum variants and structs. #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] -pub enum VariantData { +pub enum VariantData<'hir> { /// A struct variant. /// /// E.g., `Bar { .. }` as in `enum Foo { Bar { .. } }`. - Struct(HirVec, /* recovered */ bool), + Struct(&'hir [StructField], /* recovered */ bool), /// A tuple variant. /// /// E.g., `Bar(..)` as in `enum Foo { Bar(..) }`. - Tuple(HirVec, HirId), + Tuple(&'hir [StructField], HirId), /// A unit variant. /// /// E.g., `Bar = ..` as in `enum Foo { Bar = .. }`. Unit(HirId), } -impl VariantData { +impl VariantData<'hir> { /// Return the fields of this variant. - pub fn fields(&self) -> &[StructField] { + pub fn fields(&self) -> &'hir [StructField] { match *self { VariantData::Struct(ref fields, ..) | VariantData::Tuple(ref fields, ..) => fields, _ => &[], @@ -2499,11 +2499,11 @@ pub enum ItemKind<'hir> { /// An opaque `impl Trait` type alias, e.g., `type Foo = impl Bar;`. OpaqueTy(OpaqueTy), /// An enum definition, e.g., `enum Foo {C, D}`. - Enum(EnumDef, Generics), + Enum(EnumDef<'hir>, Generics), /// A struct definition, e.g., `struct Foo {x: A}`. - Struct(VariantData, Generics), + Struct(VariantData<'hir>, Generics), /// A union definition, e.g., `union Foo {x: A, y: B}`. - Union(VariantData, Generics), + Union(VariantData<'hir>, Generics), /// A trait definition. Trait(IsAuto, Unsafety, Generics, GenericBounds, &'hir [TraitItemRef]), /// A trait alias. @@ -2791,7 +2791,7 @@ pub enum Node<'hir> { ForeignItem(&'hir ForeignItem<'hir>), TraitItem(&'hir TraitItem<'hir>), ImplItem(&'hir ImplItem<'hir>), - Variant(&'hir Variant), + Variant(&'hir Variant<'hir>), Field(&'hir StructField), AnonConst(&'hir AnonConst), Expr(&'hir Expr), @@ -2808,7 +2808,7 @@ pub enum Node<'hir> { /// `Ctor` refers to the constructor of an enum variant or struct. Only tuple or unit variants /// with synthesized constructors. - Ctor(&'hir VariantData), + Ctor(&'hir VariantData<'hir>), Lifetime(&'hir Lifetime), GenericParam(&'hir GenericParam), diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index dc270fc40c9..63d8afc7ec9 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -708,7 +708,7 @@ impl<'a> State<'a> { } pub fn print_enum_def(&mut self, - enum_definition: &hir::EnumDef, + enum_definition: &hir::EnumDef<'_>, generics: &hir::Generics, name: ast::Name, span: syntax_pos::Span, @@ -723,7 +723,7 @@ impl<'a> State<'a> { } pub fn print_variants(&mut self, - variants: &[hir::Variant], + variants: &[hir::Variant<'_>], span: syntax_pos::Span) { self.bopen(); @@ -770,7 +770,7 @@ impl<'a> State<'a> { } pub fn print_struct(&mut self, - struct_def: &hir::VariantData, + struct_def: &hir::VariantData<'_>, generics: &hir::Generics, name: ast::Name, span: syntax_pos::Span, @@ -819,7 +819,7 @@ impl<'a> State<'a> { } } - pub fn print_variant(&mut self, v: &hir::Variant) { + pub fn print_variant(&mut self, v: &hir::Variant<'_>) { self.head(""); let generics = hir::Generics::empty(); self.print_struct(&v.data, &generics, v.ident.name, v.span, false); diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 490599e582f..6ca85f8da90 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -990,7 +990,7 @@ for LateContextAndPass<'a, 'tcx, T> { } fn visit_variant_data(&mut self, - s: &'tcx hir::VariantData, + s: &'tcx hir::VariantData<'tcx>, _: ast::Name, _: &'tcx hir::Generics, _: hir::HirId, @@ -1008,7 +1008,7 @@ for LateContextAndPass<'a, 'tcx, T> { } fn visit_variant(&mut self, - v: &'tcx hir::Variant, + v: &'tcx hir::Variant<'tcx>, g: &'tcx hir::Generics, item_id: hir::HirId) { self.with_lint_attrs(v.id, &v.attrs, |cx| { diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 12417d6089a..fc05b0bd5a9 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -128,11 +128,11 @@ macro_rules! late_lint_methods { fn check_trait_item_post(a: &$hir hir::TraitItem<$hir>); fn check_impl_item(a: &$hir hir::ImplItem<$hir>); fn check_impl_item_post(a: &$hir hir::ImplItem<$hir>); - fn check_struct_def(a: &$hir hir::VariantData); - fn check_struct_def_post(a: &$hir hir::VariantData); + fn check_struct_def(a: &$hir hir::VariantData<$hir>); + fn check_struct_def_post(a: &$hir hir::VariantData<$hir>); fn check_struct_field(a: &$hir hir::StructField); - fn check_variant(a: &$hir hir::Variant); - fn check_variant_post(a: &$hir hir::Variant); + fn check_variant(a: &$hir hir::Variant<$hir>); + fn check_variant_post(a: &$hir hir::Variant<$hir>); fn check_lifetime(a: &$hir hir::Lifetime); fn check_path(a: &$hir hir::Path, b: hir::HirId); fn check_attribute(a: &$hir ast::Attribute); @@ -629,7 +629,7 @@ impl intravisit::Visitor<'tcx> for LintLevelMapBuilder<'_, 'tcx> { } fn visit_variant(&mut self, - v: &'tcx hir::Variant, + v: &'tcx hir::Variant<'tcx>, g: &'tcx hir::Generics, item_id: hir::HirId) { self.with_lint_attrs(v.id, &v.attrs, |builder| { diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 0aef5b24fc7..8eb1ce14d1f 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -300,7 +300,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { }); } - fn visit_variant(&mut self, var: &'tcx Variant, g: &'tcx Generics, item_id: HirId) { + fn visit_variant(&mut self, var: &'tcx Variant<'tcx>, g: &'tcx Generics, item_id: HirId) { self.annotate(var.id, &var.attrs, var.span, AnnotationKind::Required, |v| { if let Some(ctor_hir_id) = var.data.ctor_hir_id() { @@ -382,7 +382,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> { intravisit::walk_impl_item(self, ii); } - fn visit_variant(&mut self, var: &'tcx Variant, g: &'tcx Generics, item_id: HirId) { + fn visit_variant(&mut self, var: &'tcx Variant<'tcx>, g: &'tcx Generics, item_id: HirId) { self.check_missing_stability(var.id, var.span, "variant"); intravisit::walk_variant(self, var, g, item_id); } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 2037daded6d..156307e31bc 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -483,7 +483,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { } } - fn check_variant(&mut self, cx: &LateContext<'_, '_>, v: &hir::Variant) { + fn check_variant(&mut self, cx: &LateContext<'_, '_>, v: &hir::Variant<'_>) { self.check_missing_docs_attrs(cx, Some(v.id), &v.attrs, diff --git a/src/librustc_lint/nonstandard_style.rs b/src/librustc_lint/nonstandard_style.rs index 2f06d5f3f7b..63a5f8681d6 100644 --- a/src/librustc_lint/nonstandard_style.rs +++ b/src/librustc_lint/nonstandard_style.rs @@ -349,7 +349,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase { fn check_struct_def( &mut self, cx: &LateContext<'_, '_>, - s: &hir::VariantData, + s: &hir::VariantData<'_>, ) { for sf in s.fields() { self.check_snake_case(cx, "structure field", &sf.ident); diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index 2e1a08a0224..350df575047 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -74,7 +74,7 @@ fn mir_keys(tcx: TyCtxt<'_>, krate: CrateNum) -> &DefIdSet { } impl<'a, 'tcx> Visitor<'tcx> for GatherCtors<'a, 'tcx> { fn visit_variant_data(&mut self, - v: &'tcx hir::VariantData, + v: &'tcx hir::VariantData<'tcx>, _: ast::Name, _: &'tcx hir::Generics, _: hir::HirId, diff --git a/src/librustc_passes/dead.rs b/src/librustc_passes/dead.rs index dba5a3dbd2b..7c3cc80e5d2 100644 --- a/src/librustc_passes/dead.rs +++ b/src/librustc_passes/dead.rs @@ -223,7 +223,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> { self.tables = old_tables; } - fn visit_variant_data(&mut self, def: &'tcx hir::VariantData, _: ast::Name, + fn visit_variant_data(&mut self, def: &'tcx hir::VariantData<'tcx>, _: ast::Name, _: &hir::Generics, _: hir::HirId, _: syntax_pos::Span) { let has_repr_c = self.repr_has_repr_c; let inherited_pub_visibility = self.inherited_pub_visibility; @@ -375,7 +375,7 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> { self.worklist.extend(enum_def.variants.iter().map(|variant| variant.id)); } - for variant in &enum_def.variants { + for variant in enum_def.variants { if let Some(ctor_hir_id) = variant.data.ctor_hir_id() { self.struct_constructors.insert(ctor_hir_id, variant.id); } @@ -503,7 +503,7 @@ impl DeadVisitor<'tcx> { && !has_allow_dead_code_or_lang_attr(self.tcx, field.hir_id, &field.attrs) } - fn should_warn_about_variant(&mut self, variant: &hir::Variant) -> bool { + fn should_warn_about_variant(&mut self, variant: &hir::Variant<'_>) -> bool { !self.symbol_is_live(variant.id) && !has_allow_dead_code_or_lang_attr(self.tcx, variant.id, @@ -610,7 +610,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> { } fn visit_variant(&mut self, - variant: &'tcx hir::Variant, + variant: &'tcx hir::Variant<'tcx>, g: &'tcx hir::Generics, id: hir::HirId) { if self.should_warn_about_variant(&variant) { diff --git a/src/librustc_passes/hir_stats.rs b/src/librustc_passes/hir_stats.rs index 297b527d846..0e80f93234c 100644 --- a/src/librustc_passes/hir_stats.rs +++ b/src/librustc_passes/hir_stats.rs @@ -209,7 +209,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_variant(&mut self, - v: &'v hir::Variant, + v: &'v hir::Variant<'v>, g: &'v hir::Generics, item_id: hir::HirId) { self.record("Variant", Id::None, v); diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 95f8cc9af35..239c75b1f1b 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -675,7 +675,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { // Update levels of nested things. match item.kind { hir::ItemKind::Enum(ref def, _) => { - for variant in &def.variants { + for variant in def.variants { let variant_level = self.update(variant.id, item_level); if let Some(ctor_hir_id) = variant.data.ctor_hir_id() { self.update(ctor_hir_id, item_level); @@ -798,7 +798,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { if item_level.is_some() { self.reach(item.hir_id, item_level).generics().predicates(); } - for variant in &def.variants { + for variant in def.variants { let variant_level = self.get(variant.id); if variant_level.is_some() { for field in variant.data.fields() { @@ -1637,7 +1637,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { } fn visit_variant(&mut self, - v: &'tcx hir::Variant, + v: &'tcx hir::Variant<'tcx>, g: &'tcx hir::Generics, item_id: hir::HirId) { if self.access_levels.is_reachable(v.id) { @@ -1890,7 +1890,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> hir::ItemKind::Enum(ref def, _) => { self.check(item.hir_id, item_visibility).generics().predicates(); - for variant in &def.variants { + for variant in def.variants { for field in variant.data.fields() { self.check(field.hir_id, item_visibility).ty(); } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 5ba03ab753b..1cc3f3690f9 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2435,7 +2435,7 @@ fn check_transparent(tcx: TyCtxt<'_>, sp: Span, def_id: DefId) { } #[allow(trivial_numeric_casts)] -pub fn check_enum<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, vs: &'tcx [hir::Variant], id: hir::HirId) { +pub fn check_enum<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, vs: &'tcx [hir::Variant<'tcx>], id: hir::HirId) { let def_id = tcx.hir().local_def_id(id); let def = tcx.adt_def(def_id); def.destructor(tcx); // force the destructor to be evaluated @@ -2472,12 +2472,12 @@ pub fn check_enum<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, vs: &'tcx [hir::Variant], i if tcx.adt_def(def_id).repr.int.is_none() && tcx.features().arbitrary_enum_discriminant { let is_unit = - |var: &hir::Variant| match var.data { + |var: &hir::Variant<'_>| match var.data { hir::VariantData::Unit(..) => true, _ => false }; - let has_disr = |var: &hir::Variant| var.disr_expr.is_some(); + let has_disr = |var: &hir::Variant<'_>| var.disr_expr.is_some(); let has_non_units = vs.iter().any(|var| !is_unit(var)); let disr_units = vs.iter().any(|var| is_unit(&var) && has_disr(&var)); let disr_non_unit = vs.iter().any(|var| !is_unit(&var) && has_disr(&var)); diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 5b7513b5263..e974b070dbd 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -1113,7 +1113,7 @@ struct AdtField<'tcx> { } impl<'a, 'tcx> FnCtxt<'a, 'tcx> { - fn non_enum_variant(&self, struct_def: &hir::VariantData) -> AdtVariant<'tcx> { + fn non_enum_variant(&self, struct_def: &hir::VariantData<'_>) -> AdtVariant<'tcx> { let fields = struct_def.fields().iter().map(|field| { let field_ty = self.tcx.type_of(self.tcx.hir().local_def_id(field.hir_id)); let field_ty = self.normalize_associated_types_in(field.span, @@ -1126,7 +1126,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { AdtVariant { fields } } - fn enum_variants(&self, enum_def: &hir::EnumDef) -> Vec> { + fn enum_variants(&self, enum_def: &hir::EnumDef<'_>) -> Vec> { enum_def.variants.iter() .map(|variant| self.non_enum_variant(&variant.data)) .collect() diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 9d260bde751..224ec145520 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -529,7 +529,7 @@ fn convert_variant_ctor(tcx: TyCtxt<'_>, ctor_id: hir::HirId) { fn convert_enum_variant_types( tcx: TyCtxt<'_>, def_id: DefId, - variants: &[hir::Variant] + variants: &[hir::Variant<'_>] ) { let def = tcx.adt_def(def_id); let repr_type = def.repr.discr_type(); @@ -584,7 +584,7 @@ fn convert_variant( ctor_did: Option, ident: Ident, discr: ty::VariantDiscr, - def: &hir::VariantData, + def: &hir::VariantData<'_>, adt_kind: ty::AdtKind, parent_did: DefId, ) -> ty::VariantDef { diff --git a/src/librustc_typeck/variance/constraints.rs b/src/librustc_typeck/variance/constraints.rs index 1d16562e0e6..64357cb4a3d 100644 --- a/src/librustc_typeck/variance/constraints.rs +++ b/src/librustc_typeck/variance/constraints.rs @@ -81,7 +81,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> { hir::ItemKind::Enum(ref enum_def, _) => { self.visit_node_helper(item.hir_id); - for variant in &enum_def.variants { + for variant in enum_def.variants { if let hir::VariantData::Tuple(..) = variant.data { self.visit_node_helper(variant.data.ctor_hir_id().unwrap()); } diff --git a/src/librustc_typeck/variance/terms.rs b/src/librustc_typeck/variance/terms.rs index c97ac24ce50..95f361763e8 100644 --- a/src/librustc_typeck/variance/terms.rs +++ b/src/librustc_typeck/variance/terms.rs @@ -144,7 +144,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for TermsContext<'a, 'tcx> { hir::ItemKind::Enum(ref enum_def, _) => { self.add_inferreds_for_item(item.hir_id); - for variant in &enum_def.variants { + for variant in enum_def.variants { if let hir::VariantData::Tuple(..) = variant.data { self.add_inferreds_for_item(variant.data.ctor_hir_id().unwrap()); } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 55c3e9e4a24..d882a362266 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1836,7 +1836,7 @@ impl Clean for doctree::Union<'_> { } } -impl Clean for ::rustc::hir::VariantData { +impl Clean for ::rustc::hir::VariantData<'_> { fn clean(&self, cx: &DocContext<'_>) -> VariantStruct { VariantStruct { struct_type: doctree::struct_type_from_def(self), @@ -1923,7 +1923,7 @@ impl Clean for ty::VariantDef { } } -impl Clean for hir::VariantData { +impl Clean for hir::VariantData<'_> { fn clean(&self, cx: &DocContext<'_>) -> VariantKind { match self { hir::VariantData::Struct(..) => VariantKind::Struct(self.clean(cx)), diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index 6aa23248719..852cc0fb326 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -118,7 +118,7 @@ pub struct Variant<'hir> { pub name: Name, pub id: hir::HirId, pub attrs: &'hir [ast::Attribute], - pub def: &'hir hir::VariantData, + pub def: &'hir hir::VariantData<'hir>, pub whence: Span, } From e2526120f23db1a4314634eafa0b27a203aae9a4 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 29 Nov 2019 09:40:33 +0100 Subject: [PATCH 08/12] Use Arena inside hir::StructField. --- src/librustc/arena.rs | 2 +- src/librustc/hir/intravisit.rs | 6 +++--- src/librustc/hir/lowering/item.rs | 9 +++++---- src/librustc/hir/map/collector.rs | 2 +- src/librustc/hir/map/mod.rs | 2 +- src/librustc/hir/mod.rs | 16 ++++++++-------- src/librustc/lint/context.rs | 2 +- src/librustc/lint/mod.rs | 4 ++-- src/librustc/middle/stability.rs | 4 ++-- src/librustc_incremental/assert_dep_graph.rs | 2 +- src/librustc_lint/builtin.rs | 4 ++-- src/librustc_metadata/rmeta/encoder.rs | 2 +- src/librustc_passes/dead.rs | 4 ++-- src/librustc_passes/hir_stats.rs | 2 +- src/librustc_privacy/lib.rs | 2 +- src/librustc_traits/lowering/mod.rs | 2 +- src/librustdoc/clean/mod.rs | 2 +- src/librustdoc/doctree.rs | 4 ++-- 18 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/librustc/arena.rs b/src/librustc/arena.rs index a892a7a25ba..494b8ca8f4f 100644 --- a/src/librustc/arena.rs +++ b/src/librustc/arena.rs @@ -131,7 +131,7 @@ macro_rules! arena_types { [] impl_item_ref: rustc::hir::ImplItemRef, [] macro_def: rustc::hir::MacroDef<$tcx>, [] path: rustc::hir::Path, - [] struct_field: rustc::hir::StructField, + [] struct_field: rustc::hir::StructField<$tcx>, [] trait_item_ref: rustc::hir::TraitItemRef, [] ty: rustc::hir::Ty, [] variant: rustc::hir::Variant<$tcx>, diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 094d390f826..37ee672291e 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -324,7 +324,7 @@ pub trait Visitor<'v>: Sized { _: Span) { walk_struct_def(self, s) } - fn visit_struct_field(&mut self, s: &'v StructField) { + fn visit_struct_field(&mut self, s: &'v StructField<'v>) { walk_struct_field(self, s) } fn visit_enum_def(&mut self, @@ -955,12 +955,12 @@ pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V, struct_definition: & walk_list!(visitor, visit_struct_field, struct_definition.fields()); } -pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V, struct_field: &'v StructField) { +pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V, struct_field: &'v StructField<'v>) { visitor.visit_id(struct_field.hir_id); visitor.visit_vis(&struct_field.vis); visitor.visit_ident(struct_field.ident); visitor.visit_ty(&struct_field.ty); - walk_list!(visitor, visit_attribute, &struct_field.attrs); + walk_list!(visitor, visit_attribute, struct_field.attrs); } pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block) { diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index 158957b4ada..d79f1bfa680 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -791,7 +791,7 @@ impl LoweringContext<'_, 'hir> { } } - fn lower_struct_field(&mut self, (index, f): (usize, &StructField)) -> hir::StructField { + fn lower_struct_field(&mut self, (index, f): (usize, &StructField)) -> hir::StructField<'hir> { let ty = if let TyKind::Path(ref qself, ref path) = f.ty.kind { let t = self.lower_path_ty( &f.ty, @@ -800,9 +800,10 @@ impl LoweringContext<'_, 'hir> { ParamMode::ExplicitNamed, // no `'_` in declarations (Issue #61124) ImplTraitContext::disallowed() ); - P(t) + self.arena.alloc(t) } else { - self.lower_ty(&f.ty, ImplTraitContext::disallowed()) + let t = self.lower_ty(&f.ty, ImplTraitContext::disallowed()); + self.arena.alloc(t.into_inner()) }; hir::StructField { span: f.span, @@ -814,7 +815,7 @@ impl LoweringContext<'_, 'hir> { }, vis: self.lower_visibility(&f.vis, None), ty, - attrs: self.lower_attrs(&f.attrs), + attrs: self.lower_attrs_arena(&f.attrs), } } diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index 00d61fb2fb0..faf2a0c7010 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -550,7 +550,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> { }); } - fn visit_struct_field(&mut self, field: &'hir StructField) { + fn visit_struct_field(&mut self, field: &'hir StructField<'hir>) { self.insert(field.span, field.hir_id, Node::Field(field)); self.with_parent(field.hir_id, |this| { intravisit::walk_struct_field(this, field); diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 8865157a319..c6409f8d465 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -1251,7 +1251,7 @@ impl Named for Spanned { fn name(&self) -> Name { self.node.name() } impl Named for Item<'_> { fn name(&self) -> Name { self.ident.name } } impl Named for ForeignItem<'_> { fn name(&self) -> Name { self.ident.name } } impl Named for Variant<'_> { fn name(&self) -> Name { self.ident.name } } -impl Named for StructField { fn name(&self) -> Name { self.ident.name } } +impl Named for StructField<'_> { fn name(&self) -> Name { self.ident.name } } impl Named for TraitItem<'_> { fn name(&self) -> Name { self.ident.name } } impl Named for ImplItem<'_> { fn name(&self) -> Name { self.ident.name } } diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 813cbe503e2..25fc365b4ec 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -2377,17 +2377,17 @@ impl VisibilityKind { } #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] -pub struct StructField { +pub struct StructField<'hir> { pub span: Span, #[stable_hasher(project(name))] pub ident: Ident, pub vis: Visibility, pub hir_id: HirId, - pub ty: P, - pub attrs: HirVec, + pub ty: &'hir Ty, + pub attrs: &'hir [Attribute], } -impl StructField { +impl StructField<'_> { // Still necessary in couple of places pub fn is_positional(&self) -> bool { let first = self.ident.as_str().as_bytes()[0]; @@ -2401,11 +2401,11 @@ pub enum VariantData<'hir> { /// A struct variant. /// /// E.g., `Bar { .. }` as in `enum Foo { Bar { .. } }`. - Struct(&'hir [StructField], /* recovered */ bool), + Struct(&'hir [StructField<'hir>], /* recovered */ bool), /// A tuple variant. /// /// E.g., `Bar(..)` as in `enum Foo { Bar(..) }`. - Tuple(&'hir [StructField], HirId), + Tuple(&'hir [StructField<'hir>], HirId), /// A unit variant. /// /// E.g., `Bar = ..` as in `enum Foo { Bar = .. }`. @@ -2414,7 +2414,7 @@ pub enum VariantData<'hir> { impl VariantData<'hir> { /// Return the fields of this variant. - pub fn fields(&self) -> &'hir [StructField] { + pub fn fields(&self) -> &'hir [StructField<'hir>] { match *self { VariantData::Struct(ref fields, ..) | VariantData::Tuple(ref fields, ..) => fields, _ => &[], @@ -2792,7 +2792,7 @@ pub enum Node<'hir> { TraitItem(&'hir TraitItem<'hir>), ImplItem(&'hir ImplItem<'hir>), Variant(&'hir Variant<'hir>), - Field(&'hir StructField), + Field(&'hir StructField<'hir>), AnonConst(&'hir AnonConst), Expr(&'hir Expr), Stmt(&'hir Stmt), diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 6ca85f8da90..7f19ec60f53 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -1000,7 +1000,7 @@ for LateContextAndPass<'a, 'tcx, T> { lint_callback!(self, check_struct_def_post, s); } - fn visit_struct_field(&mut self, s: &'tcx hir::StructField) { + fn visit_struct_field(&mut self, s: &'tcx hir::StructField<'tcx>) { self.with_lint_attrs(s.hir_id, &s.attrs, |cx| { lint_callback!(cx, check_struct_field, s); hir_visit::walk_struct_field(cx, s); diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index fc05b0bd5a9..86c7d551560 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -130,7 +130,7 @@ macro_rules! late_lint_methods { fn check_impl_item_post(a: &$hir hir::ImplItem<$hir>); fn check_struct_def(a: &$hir hir::VariantData<$hir>); fn check_struct_def_post(a: &$hir hir::VariantData<$hir>); - fn check_struct_field(a: &$hir hir::StructField); + fn check_struct_field(a: &$hir hir::StructField<$hir>); fn check_variant(a: &$hir hir::Variant<$hir>); fn check_variant_post(a: &$hir hir::Variant<$hir>); fn check_lifetime(a: &$hir hir::Lifetime); @@ -622,7 +622,7 @@ impl intravisit::Visitor<'tcx> for LintLevelMapBuilder<'_, 'tcx> { }) } - fn visit_struct_field(&mut self, s: &'tcx hir::StructField) { + fn visit_struct_field(&mut self, s: &'tcx hir::StructField<'tcx>) { self.with_lint_attrs(s.hir_id, &s.attrs, |builder| { intravisit::walk_struct_field(builder, s); }) diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 8eb1ce14d1f..e1838b13fef 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -312,7 +312,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { }) } - fn visit_struct_field(&mut self, s: &'tcx StructField) { + fn visit_struct_field(&mut self, s: &'tcx StructField<'tcx>) { self.annotate(s.hir_id, &s.attrs, s.span, AnnotationKind::Required, |v| { intravisit::walk_struct_field(v, s); }); @@ -387,7 +387,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> { intravisit::walk_variant(self, var, g, item_id); } - fn visit_struct_field(&mut self, s: &'tcx StructField) { + fn visit_struct_field(&mut self, s: &'tcx StructField<'tcx>) { self.check_missing_stability(s.hir_id, s.span, "field"); intravisit::walk_struct_field(self, s); } diff --git a/src/librustc_incremental/assert_dep_graph.rs b/src/librustc_incremental/assert_dep_graph.rs index feab4ca0a31..44b610e487b 100644 --- a/src/librustc_incremental/assert_dep_graph.rs +++ b/src/librustc_incremental/assert_dep_graph.rs @@ -177,7 +177,7 @@ impl Visitor<'tcx> for IfThisChanged<'tcx> { intravisit::walk_impl_item(self, impl_item); } - fn visit_struct_field(&mut self, s: &'tcx hir::StructField) { + fn visit_struct_field(&mut self, s: &'tcx hir::StructField<'tcx>) { self.process_attrs(s.hir_id, &s.attrs); intravisit::walk_struct_field(self, s); } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 156307e31bc..b83bfedc824 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -473,7 +473,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { desc); } - fn check_struct_field(&mut self, cx: &LateContext<'_, '_>, sf: &hir::StructField) { + fn check_struct_field(&mut self, cx: &LateContext<'_, '_>, sf: &hir::StructField<'_>) { if !sf.is_positional() { self.check_missing_docs_attrs(cx, Some(sf.hir_id), @@ -1001,7 +1001,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnreachablePub { foreign_item.span, true); } - fn check_struct_field(&mut self, cx: &LateContext<'_, '_>, field: &hir::StructField) { + fn check_struct_field(&mut self, cx: &LateContext<'_, '_>, field: &hir::StructField<'_>) { self.perform_lint(cx, "field", field.hir_id, &field.vis, field.span, false); } diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index 6a803997468..e9c5f90d9dc 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -727,7 +727,7 @@ impl EncodeContext<'tcx> { record!(self.per_def.kind[def_id] <- EntryKind::Field); record!(self.per_def.visibility[def_id] <- field.vis); record!(self.per_def.span[def_id] <- self.tcx.def_span(def_id)); - record!(self.per_def.attributes[def_id] <- &variant_data.fields()[field_index].attrs); + record!(self.per_def.attributes[def_id] <- variant_data.fields()[field_index].attrs); self.encode_stability(def_id); self.encode_deprecation(def_id); self.encode_item_type(def_id); diff --git a/src/librustc_passes/dead.rs b/src/librustc_passes/dead.rs index 7c3cc80e5d2..3edd010f311 100644 --- a/src/librustc_passes/dead.rs +++ b/src/librustc_passes/dead.rs @@ -495,7 +495,7 @@ impl DeadVisitor<'tcx> { should_warn && !self.symbol_is_live(item.hir_id) } - fn should_warn_about_field(&mut self, field: &hir::StructField) -> bool { + fn should_warn_about_field(&mut self, field: &hir::StructField<'_>) -> bool { let field_type = self.tcx.type_of(self.tcx.hir().local_def_id(field.hir_id)); !field.is_positional() && !self.symbol_is_live(field.hir_id) @@ -629,7 +629,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> { intravisit::walk_foreign_item(self, fi); } - fn visit_struct_field(&mut self, field: &'tcx hir::StructField) { + fn visit_struct_field(&mut self, field: &'tcx hir::StructField<'tcx>) { if self.should_warn_about_field(&field) { self.warn_dead_code(field.hir_id, field.span, field.ident.name, "field", "read"); } diff --git a/src/librustc_passes/hir_stats.rs b/src/librustc_passes/hir_stats.rs index 0e80f93234c..9ea74235401 100644 --- a/src/librustc_passes/hir_stats.rs +++ b/src/librustc_passes/hir_stats.rs @@ -203,7 +203,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { hir_visit::walk_param_bound(self, bounds) } - fn visit_struct_field(&mut self, s: &'v hir::StructField) { + fn visit_struct_field(&mut self, s: &'v hir::StructField<'v>) { self.record("StructField", Id::Node(s.hir_id), s); hir_visit::walk_struct_field(self, s) } diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 239c75b1f1b..d8d554bad2c 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -1647,7 +1647,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { } } - fn visit_struct_field(&mut self, s: &'tcx hir::StructField) { + fn visit_struct_field(&mut self, s: &'tcx hir::StructField<'tcx>) { if s.vis.node.is_pub() || self.in_variant { intravisit::walk_struct_field(self, s); } diff --git a/src/librustc_traits/lowering/mod.rs b/src/librustc_traits/lowering/mod.rs index e6de2b279fc..9e286094642 100644 --- a/src/librustc_traits/lowering/mod.rs +++ b/src/librustc_traits/lowering/mod.rs @@ -684,7 +684,7 @@ impl Visitor<'tcx> for ClauseDumper<'tcx> { intravisit::walk_impl_item(self, impl_item); } - fn visit_struct_field(&mut self, s: &'tcx hir::StructField) { + fn visit_struct_field(&mut self, s: &'tcx hir::StructField<'tcx>) { self.process_attrs(s.hir_id, &s.attrs); intravisit::walk_struct_field(self, s); } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index d882a362266..4825eb1ebd5 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1743,7 +1743,7 @@ impl<'tcx> Clean for ty::Const<'tcx> { } } -impl Clean for hir::StructField { +impl Clean for hir::StructField<'_> { fn clean(&self, cx: &DocContext<'_>) -> Item { let local_did = cx.tcx.hir().local_def_id(self.hir_id); diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index 852cc0fb326..ae62b743f9d 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -89,7 +89,7 @@ pub struct Struct<'hir> { pub name: Name, pub generics: &'hir hir::Generics, pub attrs: &'hir [ast::Attribute], - pub fields: &'hir [hir::StructField], + pub fields: &'hir [hir::StructField<'hir>], pub whence: Span, } @@ -100,7 +100,7 @@ pub struct Union<'hir> { pub name: Name, pub generics: &'hir hir::Generics, pub attrs: &'hir [ast::Attribute], - pub fields: &'hir [hir::StructField], + pub fields: &'hir [hir::StructField<'hir>], pub whence: Span, } From 42c03e4bb47b4758aa4f65c02ef9eba901a801b7 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 29 Nov 2019 10:24:47 +0100 Subject: [PATCH 09/12] Use Arena inside hir::Mod. --- src/librustc/hir/intravisit.rs | 6 +++--- src/librustc/hir/lowering/item.rs | 4 ++-- src/librustc/hir/map/mod.rs | 2 +- src/librustc/hir/mod.rs | 8 ++++---- src/librustc/hir/print.rs | 4 ++-- src/librustc/ich/impls_hir.rs | 2 +- src/librustc/lint/context.rs | 4 ++-- src/librustc/lint/mod.rs | 4 ++-- src/librustc_lint/nonstandard_style.rs | 2 +- src/librustc_metadata/rmeta/encoder.rs | 2 +- src/librustc_passes/hir_stats.rs | 2 +- src/librustc_privacy/lib.rs | 8 ++++---- src/librustc_typeck/check/method/suggest.rs | 4 ++-- src/librustdoc/visit_ast.rs | 6 +++--- 14 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 37ee672291e..cae813582cd 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 d79f1bfa680..c49242485e1 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 c6409f8d465..cd96bedf4bd 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 25fc365b4ec..c89d93337eb 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 63d8afc7ec9..f0499e5853f 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 a91535b5516..45274b0526f 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 7f19ec60f53..5ac20f46238 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 86c7d551560..a5d6cf9dbb7 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 63a5f8681d6..9b9203083ee 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 e9c5f90d9dc..cfe5ea65fca 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 9ea74235401..776c1aff111 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 d8d554bad2c..83f2fe7e023 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 aecc46d3128..e2b77c01e24 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 2c2a51928d9..897c00f276e 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); } From 9694ab9e18f0b6b306dafaaccb8cc33a293302bd Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 29 Nov 2019 11:09:23 +0100 Subject: [PATCH 10/12] Use Arena inside hir::Body. --- src/librustc/arena.rs | 1 + src/librustc/hir/intravisit.rs | 6 +++--- src/librustc/hir/lowering.rs | 4 ++-- src/librustc/hir/lowering/item.rs | 17 ++++++++++------- src/librustc/hir/map/mod.rs | 2 +- src/librustc/hir/mod.rs | 10 +++++----- src/librustc/ich/hcx.rs | 2 +- src/librustc/ich/impls_hir.rs | 2 +- .../infer/error_reporting/need_type_info.rs | 6 +++--- src/librustc/lint/context.rs | 2 +- src/librustc/lint/mod.rs | 8 ++++---- src/librustc/middle/region.rs | 6 +++--- src/librustc/middle/resolve_lifetime.rs | 2 +- src/librustc_lint/nonstandard_style.rs | 2 +- src/librustc_mir/build/mod.rs | 2 +- src/librustc_mir/hair/pattern/check_match.rs | 4 ++-- src/librustc_passes/check_const.rs | 4 ++-- src/librustc_passes/liveness.rs | 6 +++--- src/librustc_typeck/check/closure.rs | 16 ++++++++-------- src/librustc_typeck/check/mod.rs | 4 ++-- src/librustc_typeck/check/regionck.rs | 6 +++--- src/librustc_typeck/check/upvar.rs | 4 ++-- src/librustc_typeck/check/writeback.rs | 14 +++++++------- src/librustc_typeck/expr_use_visitor.rs | 4 ++-- 24 files changed, 69 insertions(+), 65 deletions(-) diff --git a/src/librustc/arena.rs b/src/librustc/arena.rs index 494b8ca8f4f..164e0e85c5a 100644 --- a/src/librustc/arena.rs +++ b/src/librustc/arena.rs @@ -130,6 +130,7 @@ macro_rules! arena_types { [] foreign_item: rustc::hir::ForeignItem<$tcx>, [] impl_item_ref: rustc::hir::ImplItemRef, [] macro_def: rustc::hir::MacroDef<$tcx>, + [] param: rustc::hir::Param, [] path: rustc::hir::Path, [] struct_field: rustc::hir::StructField<$tcx>, [] trait_item_ref: rustc::hir::TraitItemRef, diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index cae813582cd..bd975c6c95d 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -222,7 +222,7 @@ pub trait Visitor<'v>: Sized { walk_item(self, i) } - fn visit_body(&mut self, b: &'v Body) { + fn visit_body(&mut self, b: &'v Body<'v>) { walk_body(self, b); } @@ -401,8 +401,8 @@ pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod<'v>, mod_hi } } -pub fn walk_body<'v, V: Visitor<'v>>(visitor: &mut V, body: &'v Body) { - walk_list!(visitor, visit_param, &body.params); +pub fn walk_body<'v, V: Visitor<'v>>(visitor: &mut V, body: &'v Body<'v>) { + walk_list!(visitor, visit_param, body.params); visitor.visit_expr(&body.value); } diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 74615cbe945..cac4c694316 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -99,7 +99,7 @@ pub struct LoweringContext<'a, 'hir: 'a> { trait_items: BTreeMap>, impl_items: BTreeMap>, - bodies: BTreeMap, + bodies: BTreeMap>, exported_macros: Vec>, non_exported_macro_attrs: Vec, @@ -3428,7 +3428,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } } -fn body_ids(bodies: &BTreeMap) -> Vec { +fn body_ids(bodies: &BTreeMap>) -> Vec { // Sorting by span ensures that we get things in order within a // file, and also puts the files in a sensible order. let mut body_ids: Vec<_> = bodies.keys().cloned().collect(); diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index c49242485e1..d5440663c49 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -5,7 +5,7 @@ use super::ImplTraitTypeIdVisitor; use super::AnonymousLifetimeMode; use super::ParamMode; -use crate::hir::{self, HirVec}; +use crate::hir; use crate::hir::ptr::P; use crate::hir::def_id::DefId; use crate::hir::def::{Res, DefKind}; @@ -107,7 +107,7 @@ impl<'a, 'lowering, 'hir> Visitor<'a> for ItemLowerer<'a, 'lowering, 'hir> { } } -impl LoweringContext<'_, 'hir> { +impl<'hir> LoweringContext<'_, 'hir> { // Same as the method above, but accepts `hir::GenericParam`s // instead of `ast::GenericParam`s. // This should only be used with generics that have already had their @@ -1052,7 +1052,7 @@ impl LoweringContext<'_, 'hir> { } } - fn record_body(&mut self, params: HirVec, value: hir::Expr) -> hir::BodyId { + fn record_body(&mut self, params: &'hir [hir::Param], value: hir::Expr) -> hir::BodyId { let body = hir::Body { generator_kind: self.generator_kind, params, @@ -1065,7 +1065,7 @@ impl LoweringContext<'_, 'hir> { fn lower_body( &mut self, - f: impl FnOnce(&mut LoweringContext<'_, '_>) -> (HirVec, hir::Expr), + f: impl FnOnce(&mut Self) -> (&'hir [hir::Param], hir::Expr), ) -> hir::BodyId { let prev_gen_kind = self.generator_kind.take(); let (parameters, result) = f(self); @@ -1089,7 +1089,9 @@ impl LoweringContext<'_, 'hir> { body: impl FnOnce(&mut LoweringContext<'_, '_>) -> hir::Expr, ) -> hir::BodyId { self.lower_body(|this| ( - decl.inputs.iter().map(|x| this.lower_param(x)).collect(), + this.arena.alloc_from_iter( + decl.inputs.iter().map(|x| this.lower_param(x)) + ), body(this), )) } @@ -1111,7 +1113,7 @@ impl LoweringContext<'_, 'hir> { } pub(super) fn lower_const_body(&mut self, span: Span, expr: Option<&Expr>) -> hir::BodyId { - self.lower_body(|this| (hir_vec![], match expr { + self.lower_body(|this| (&[], match expr { Some(expr) => this.lower_expr(expr), None => this.expr_err(span), })) @@ -1299,7 +1301,8 @@ impl LoweringContext<'_, 'hir> { ); this.expr_block(P(body), AttrVec::new()) }); - (HirVec::from(parameters), this.expr(body_span, async_expr, AttrVec::new())) + + (this.arena.alloc_from_iter(parameters), this.expr(body_span, async_expr, AttrVec::new())) }) } diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index cd96bedf4bd..71addc123b8 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -459,7 +459,7 @@ impl<'hir> Map<'hir> { self.forest.krate.impl_item(id) } - pub fn body(&self, id: BodyId) -> &'hir Body { + pub fn body(&self, id: BodyId) -> &'hir Body<'hir> { self.read(id.hir_id); // N.B., intentionally bypass `self.forest.krate()` so that we diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index c89d93337eb..ff6801a85c7 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -760,7 +760,7 @@ pub struct Crate<'hir> { pub trait_items: BTreeMap>, pub impl_items: BTreeMap>, - pub bodies: BTreeMap, + pub bodies: BTreeMap>, pub trait_impls: BTreeMap>, /// A list of the body ids written out in the order in which they @@ -787,7 +787,7 @@ impl Crate<'hir> { &self.impl_items[&id] } - pub fn body(&self, id: BodyId) -> &Body { + pub fn body(&self, id: BodyId) -> &Body<'hir> { &self.bodies[&id] } } @@ -1353,13 +1353,13 @@ pub struct BodyId { /// All bodies have an **owner**, which can be accessed via the HIR /// map using `body_owner_def_id()`. #[derive(RustcEncodable, RustcDecodable, Debug)] -pub struct Body { - pub params: HirVec, +pub struct Body<'hir> { + pub params: &'hir [Param], pub value: Expr, pub generator_kind: Option, } -impl Body { +impl Body<'hir> { pub fn id(&self) -> BodyId { BodyId { hir_id: self.value.hir_id, diff --git a/src/librustc/ich/hcx.rs b/src/librustc/ich/hcx.rs index 77a9bcd67a5..af5e167faa8 100644 --- a/src/librustc/ich/hcx.rs +++ b/src/librustc/ich/hcx.rs @@ -61,7 +61,7 @@ struct BodyResolver<'tcx>(&'tcx hir::Crate<'tcx>); impl<'tcx> BodyResolver<'tcx> { /// Returns a reference to the `hir::Body` with the given `BodyId`. /// **Does not do any tracking**; use carefully. - fn body(self, id: hir::BodyId) -> &'tcx hir::Body { + fn body(self, id: hir::BodyId) -> &'tcx hir::Body<'tcx> { self.0.body(id) } } diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 45274b0526f..1f96f4c65ef 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -266,7 +266,7 @@ impl<'a> HashStable> for hir::Item<'_> { } } -impl<'a> HashStable> for hir::Body { +impl<'a> HashStable> for hir::Body<'_> { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let hir::Body { params, diff --git a/src/librustc/infer/error_reporting/need_type_info.rs b/src/librustc/infer/error_reporting/need_type_info.rs index ebb94cc72ff..378d6d78d32 100644 --- a/src/librustc/infer/error_reporting/need_type_info.rs +++ b/src/librustc/infer/error_reporting/need_type_info.rs @@ -83,8 +83,8 @@ impl<'a, 'tcx> Visitor<'tcx> for FindLocalByTypeVisitor<'a, 'tcx> { intravisit::walk_local(self, local); } - fn visit_body(&mut self, body: &'tcx Body) { - for param in &body.params { + fn visit_body(&mut self, body: &'tcx Body<'tcx>) { + for param in body.params { if let (None, Some(ty)) = ( self.found_arg_pattern, self.node_matches_type(param.hir_id), @@ -113,7 +113,7 @@ fn closure_return_type_suggestion( span: Span, err: &mut DiagnosticBuilder<'_>, output: &FunctionRetTy, - body: &Body, + body: &Body<'_>, descr: &str, name: &str, ret: &str, diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 5ac20f46238..b7d01306343 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -924,7 +924,7 @@ for LateContextAndPass<'a, 'tcx, T> { }); } - fn visit_body(&mut self, body: &'tcx hir::Body) { + fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) { lint_callback!(self, check_body, body); hir_visit::walk_body(self, body); lint_callback!(self, check_body_post, body); diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index a5d6cf9dbb7..3d6015ecfbf 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -87,8 +87,8 @@ macro_rules! late_lint_methods { ($macro:path, $args:tt, [$hir:tt]) => ( $macro!($args, [$hir], [ fn check_param(a: &$hir hir::Param); - fn check_body(a: &$hir hir::Body); - fn check_body_post(a: &$hir hir::Body); + fn check_body(a: &$hir hir::Body<$hir>); + fn check_body_post(a: &$hir hir::Body<$hir>); 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>); @@ -114,13 +114,13 @@ macro_rules! late_lint_methods { fn check_fn( a: hir::intravisit::FnKind<$hir>, b: &$hir hir::FnDecl, - c: &$hir hir::Body, + c: &$hir hir::Body<$hir>, d: Span, e: hir::HirId); fn check_fn_post( a: hir::intravisit::FnKind<$hir>, b: &$hir hir::FnDecl, - c: &$hir hir::Body, + c: &$hir hir::Body<$hir>, d: Span, e: hir::HirId ); diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index e050e5f8942..c5d5bc58112 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -715,7 +715,7 @@ impl<'tcx> ScopeTree { pub fn yield_in_scope_for_expr(&self, scope: Scope, expr_hir_id: hir::HirId, - body: &'tcx hir::Body) -> Option { + body: &'tcx hir::Body<'tcx>) -> Option { self.yield_in_scope(scope).and_then(|YieldData { span, expr_and_pat_count, .. }| { let mut visitor = ExprLocatorVisitor { hir_id: expr_hir_id, @@ -1362,7 +1362,7 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> { resolve_block(self, b); } - fn visit_body(&mut self, body: &'tcx hir::Body) { + fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) { let body_id = body.id(); let owner_id = self.tcx.hir().body_owner(body_id); @@ -1387,7 +1387,7 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> { // The arguments and `self` are parented to the fn. self.cx.var_parent = self.cx.parent.take(); - for param in &body.params { + for param in body.params { self.visit_pat(¶m.pat); } diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 38a7c67b907..4b838d04059 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -1167,7 +1167,7 @@ fn signal_shadowing_problem(tcx: TyCtxt<'_>, name: ast::Name, orig: Original, sh // Adds all labels in `b` to `ctxt.labels_in_fn`, signalling a warning // if one of the label shadows a lifetime or another label. -fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body) { +fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body<'_>) { struct GatherLabels<'a, 'tcx> { tcx: TyCtxt<'tcx>, scope: ScopeRef<'a>, diff --git a/src/librustc_lint/nonstandard_style.rs b/src/librustc_lint/nonstandard_style.rs index 9b9203083ee..08d7a90c7b0 100644 --- a/src/librustc_lint/nonstandard_style.rs +++ b/src/librustc_lint/nonstandard_style.rs @@ -298,7 +298,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase { cx: &LateContext<'_, '_>, fk: FnKind<'_>, _: &hir::FnDecl, - _: &hir::Body, + _: &hir::Body<'_>, _: Span, id: hir::HirId, ) { diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 3479ad6749a..6b6a58102fa 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -552,7 +552,7 @@ fn construct_fn<'a, 'tcx, A>( abi: Abi, return_ty: Ty<'tcx>, return_ty_span: Span, - body: &'tcx hir::Body, + body: &'tcx hir::Body<'tcx>, ) -> Body<'tcx> where A: Iterator> diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index 28f0edadc89..4ebf41fb9d2 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -76,10 +76,10 @@ impl<'tcx> Visitor<'tcx> for MatchVisitor<'_, 'tcx> { self.check_patterns(false, &loc.pat); } - fn visit_body(&mut self, body: &'tcx hir::Body) { + fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) { intravisit::walk_body(self, body); - for param in &body.params { + for param in body.params { self.check_irrefutable(¶m.pat, "function argument", None); self.check_patterns(false, ¶m.pat); } diff --git a/src/librustc_passes/check_const.rs b/src/librustc_passes/check_const.rs index f7bdefcb069..6b5b5c823e8 100644 --- a/src/librustc_passes/check_const.rs +++ b/src/librustc_passes/check_const.rs @@ -75,7 +75,7 @@ enum ConstKind { } impl ConstKind { - fn for_body(body: &hir::Body, hir_map: &Map<'_>) -> Option { + fn for_body(body: &hir::Body<'_>, hir_map: &Map<'_>) -> Option { let is_const_fn = |id| hir_map.fn_sig_by_hir_id(id).unwrap().header.is_const(); let owner = hir_map.body_owner(body.id()); @@ -215,7 +215,7 @@ impl<'tcx> Visitor<'tcx> for CheckConstVisitor<'tcx> { self.recurse_into(kind, |this| hir::intravisit::walk_anon_const(this, anon)); } - fn visit_body(&mut self, body: &'tcx hir::Body) { + fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) { let kind = ConstKind::for_body(body, self.tcx.hir()); self.recurse_into(kind, |this| hir::intravisit::walk_body(this, body)); } diff --git a/src/librustc_passes/liveness.rs b/src/librustc_passes/liveness.rs index 81a39edf215..f18ecb90fc1 100644 --- a/src/librustc_passes/liveness.rs +++ b/src/librustc_passes/liveness.rs @@ -371,7 +371,7 @@ fn visit_fn<'tcx>( let body = ir.tcx.hir().body(body_id); - for param in &body.params { + for param in body.params { let is_shorthand = match param.pat.kind { rustc::hir::PatKind::Struct(..) => true, _ => false, @@ -1463,8 +1463,8 @@ impl<'tcx> Liveness<'_, 'tcx> { } } - fn warn_about_unused_args(&self, body: &hir::Body, entry_ln: LiveNode) { - for p in &body.params { + fn warn_about_unused_args(&self, body: &hir::Body<'_>, entry_ln: LiveNode) { + for p in body.params { self.check_unused_vars_in_pat(&p.pat, Some(entry_ln), |spans, hir_id, ln, var| { if self.live_on_entry(ln, var).is_none() { self.report_dead_assign(hir_id, spans, var, true); diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs index 30cb0d4f967..46b9a8d7f91 100644 --- a/src/librustc_typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -63,7 +63,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expr: &hir::Expr, opt_kind: Option, decl: &'tcx hir::FnDecl, - body: &'tcx hir::Body, + body: &'tcx hir::Body<'tcx>, gen: Option, expected_sig: Option>, ) -> Ty<'tcx> { @@ -316,7 +316,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, expr_def_id: DefId, decl: &hir::FnDecl, - body: &hir::Body, + body: &hir::Body<'_>, expected_sig: Option>, ) -> ClosureSignatures<'tcx> { if let Some(e) = expected_sig { @@ -332,7 +332,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, expr_def_id: DefId, decl: &hir::FnDecl, - body: &hir::Body, + body: &hir::Body<'_>, ) -> ClosureSignatures<'tcx> { debug!("sig_of_closure_no_expectation()"); @@ -392,7 +392,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, expr_def_id: DefId, decl: &hir::FnDecl, - body: &hir::Body, + body: &hir::Body<'_>, expected_sig: ExpectedSig<'tcx>, ) -> ClosureSignatures<'tcx> { debug!( @@ -450,7 +450,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, expr_def_id: DefId, decl: &hir::FnDecl, - body: &hir::Body, + body: &hir::Body<'_>, expected_sig: ExpectedSig<'tcx>, ) -> ClosureSignatures<'tcx> { let expr_map_node = self.tcx.hir().get_if_local(expr_def_id).unwrap(); @@ -482,7 +482,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, expr_def_id: DefId, decl: &hir::FnDecl, - body: &hir::Body, + body: &hir::Body<'_>, expected_sigs: &ClosureSignatures<'tcx>, ) -> InferResult<'tcx, ()> { // Get the signature S that the user gave. @@ -590,7 +590,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, expr_def_id: DefId, decl: &hir::FnDecl, - body: &hir::Body, + body: &hir::Body<'_>, ) -> ty::PolyFnSig<'tcx> { let astconv: &dyn AstConv<'_> = self; @@ -788,7 +788,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn closure_sigs( &self, expr_def_id: DefId, - body: &hir::Body, + body: &hir::Body<'_>, bound_sig: ty::PolyFnSig<'tcx>, ) -> ClosureSignatures<'tcx> { let liberated_sig = self.tcx() diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 1cc3f3690f9..1cd1d4fcd3f 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1260,7 +1260,7 @@ fn check_fn<'a, 'tcx>( fn_sig: ty::FnSig<'tcx>, decl: &'tcx hir::FnDecl, fn_id: hir::HirId, - body: &'tcx hir::Body, + body: &'tcx hir::Body<'tcx>, can_be_generator: Option, ) -> (FnCtxt<'a, 'tcx>, Option>) { let mut fn_sig = fn_sig.clone(); @@ -1327,7 +1327,7 @@ fn check_fn<'a, 'tcx>( for (param_ty, param) in fn_sig.inputs().iter().copied() .chain(maybe_va_list) - .zip(&body.params) + .zip(body.params) { // Check the pattern. fcx.check_pat_top(¶m.pat, param_ty, None); diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index 179c462f5e3..396ff5ce518 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -106,7 +106,7 @@ macro_rules! ignore_err { // PUBLIC ENTRY POINTS impl<'a, 'tcx> FnCtxt<'a, 'tcx> { - pub fn regionck_expr(&self, body: &'tcx hir::Body) { + pub fn regionck_expr(&self, body: &'tcx hir::Body<'tcx>) { let subject = self.tcx.hir().body_owner_def_id(body.id()); let id = body.value.hir_id; let mut rcx = RegionCtxt::new( @@ -159,7 +159,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// rest of type check and because sometimes we need type /// inference to have completed before we can determine which /// constraints to add. - pub fn regionck_fn(&self, fn_id: hir::HirId, body: &'tcx hir::Body) { + pub fn regionck_fn(&self, fn_id: hir::HirId, body: &'tcx hir::Body<'tcx>) { debug!("regionck_fn(id={})", fn_id); let subject = self.tcx.hir().body_owner_def_id(body.id()); let hir_id = body.value.hir_id; @@ -300,7 +300,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> { fn visit_fn_body( &mut self, id: hir::HirId, // the id of the fn itself - body: &'tcx hir::Body, + body: &'tcx hir::Body<'tcx>, span: Span, ) { // When we enter a function, we can derive diff --git a/src/librustc_typeck/check/upvar.rs b/src/librustc_typeck/check/upvar.rs index 68cb0080b7d..2788aa6b83e 100644 --- a/src/librustc_typeck/check/upvar.rs +++ b/src/librustc_typeck/check/upvar.rs @@ -46,7 +46,7 @@ use syntax::ast; use syntax_pos::Span; impl<'a, 'tcx> FnCtxt<'a, 'tcx> { - pub fn closure_analyze(&self, body: &'tcx hir::Body) { + pub fn closure_analyze(&self, body: &'tcx hir::Body<'tcx>) { InferBorrowKindVisitor { fcx: self }.visit_body(body); // it's our job to process these. @@ -81,7 +81,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, closure_hir_id: hir::HirId, span: Span, - body: &hir::Body, + body: &hir::Body<'_>, capture_clause: hir::CaptureBy, ) { diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 35f25b322e0..27ce7d7c3e0 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -32,7 +32,7 @@ use std::mem; // resolve_type_vars_in_body, which creates a new TypeTables which // doesn't contain any inference types. impl<'a, 'tcx> FnCtxt<'a, 'tcx> { - pub fn resolve_type_vars_in_body(&self, body: &'tcx hir::Body) -> &'tcx ty::TypeckTables<'tcx> { + pub fn resolve_type_vars_in_body(&self, body: &'tcx hir::Body<'tcx>) -> &'tcx ty::TypeckTables<'tcx> { let item_id = self.tcx.hir().body_owner(body.id()); let item_def_id = self.tcx.hir().local_def_id(item_id); @@ -41,7 +41,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let rustc_dump_user_substs = self.tcx.has_attr(item_def_id, sym::rustc_dump_user_substs); let mut wbcx = WritebackCx::new(self, body, rustc_dump_user_substs); - for param in &body.params { + for param in body.params { wbcx.visit_node_id(param.pat.span, param.hir_id); } // Type only exists for constants and statics, not functions. @@ -102,7 +102,7 @@ struct WritebackCx<'cx, 'tcx> { tables: ty::TypeckTables<'tcx>, - body: &'tcx hir::Body, + body: &'tcx hir::Body<'tcx>, rustc_dump_user_substs: bool, } @@ -110,7 +110,7 @@ struct WritebackCx<'cx, 'tcx> { impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { fn new( fcx: &'cx FnCtxt<'cx, 'tcx>, - body: &'tcx hir::Body, + body: &'tcx hir::Body<'tcx>, rustc_dump_user_substs: bool, ) -> WritebackCx<'cx, 'tcx> { let owner = body.id().hir_id; @@ -265,7 +265,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> { match e.kind { hir::ExprKind::Closure(_, _, body, _, _) => { let body = self.fcx.tcx.hir().body(body); - for param in &body.params { + for param in body.params { self.visit_node_id(e.span, param.hir_id); } @@ -698,14 +698,14 @@ struct Resolver<'cx, 'tcx> { tcx: TyCtxt<'tcx>, infcx: &'cx InferCtxt<'cx, 'tcx>, span: &'cx dyn Locatable, - body: &'tcx hir::Body, + body: &'tcx hir::Body<'tcx>, } impl<'cx, 'tcx> Resolver<'cx, 'tcx> { fn new( fcx: &'cx FnCtxt<'cx, 'tcx>, span: &'cx dyn Locatable, - body: &'tcx hir::Body, + body: &'tcx hir::Body<'tcx>, ) -> Resolver<'cx, 'tcx> { Resolver { tcx: fcx.tcx, diff --git a/src/librustc_typeck/expr_use_visitor.rs b/src/librustc_typeck/expr_use_visitor.rs index 03d7ab2d633..7e67d30db18 100644 --- a/src/librustc_typeck/expr_use_visitor.rs +++ b/src/librustc_typeck/expr_use_visitor.rs @@ -131,10 +131,10 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { } } - pub fn consume_body(&mut self, body: &hir::Body) { + pub fn consume_body(&mut self, body: &hir::Body<'_>) { debug!("consume_body(body={:?})", body); - for param in &body.params { + for param in body.params { let param_ty = return_if_err!(self.mc.pat_ty_adjusted(¶m.pat)); debug!("consume_body: param_ty = {:?}", param_ty); From 5f5b6e7c67a58912e33a524706d76179ff729e77 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 1 Dec 2019 12:49:54 +0100 Subject: [PATCH 11/12] Tidy. --- src/librustc/hir/intravisit.rs | 5 ++- src/librustc/hir/lowering.rs | 4 +- src/librustc/hir/lowering/item.rs | 51 ++++++++++++++++---------- src/librustc_lint/builtin.rs | 6 ++- src/librustc_lint/nonstandard_style.rs | 8 +++- src/librustc_typeck/check/mod.rs | 7 +++- src/librustc_typeck/check/writeback.rs | 4 +- 7 files changed, 60 insertions(+), 25 deletions(-) diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index bd975c6c95d..26e287037f7 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -948,7 +948,10 @@ pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, impl_item_ref: &' visitor.visit_defaultness(defaultness); } -pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V, struct_definition: &'v VariantData<'v>) { +pub fn walk_struct_def<'v, V: Visitor<'v>>( + visitor: &mut V, + struct_definition: &'v VariantData<'v>, +) { if let Some(ctor_hir_id) = struct_definition.ctor_hir_id() { visitor.visit_id(ctor_hir_id); } diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index cac4c694316..83869951ea2 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1579,7 +1579,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { output_lifetime_params: Vec, } - impl<'r, 'a, 'v, 'hir> hir::intravisit::Visitor<'v> for ImplTraitLifetimeCollector<'r, 'a, 'hir> { + impl<'r, 'a, 'v, 'hir> hir::intravisit::Visitor<'v> + for ImplTraitLifetimeCollector<'r, 'a, 'hir> + { fn nested_visit_map<'this>( &'this mut self, ) -> hir::intravisit::NestedVisitorMap<'this, 'v> { diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index d5440663c49..4492845acb8 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -164,7 +164,9 @@ impl<'hir> LoweringContext<'_, 'hir> { pub(super) fn lower_mod(&mut self, m: &Mod) -> hir::Mod<'hir> { hir::Mod { inner: m.inner, - item_ids: self.arena.alloc_from_iter(m.items.iter().flat_map(|x| self.lower_item_id(x))), + item_ids: self.arena.alloc_from_iter( + m.items.iter().flat_map(|x| self.lower_item_id(x)) + ), } } @@ -560,7 +562,8 @@ impl<'hir> LoweringContext<'_, 'hir> { }); } - let path = self.arena.alloc(self.lower_path_extra(ret_res, &path, ParamMode::Explicit, None)); + let path = self.lower_path_extra(ret_res, &path, ParamMode::Explicit, None); + let path = self.arena.alloc(path); hir::ItemKind::Use(path, hir::UseKind::Single) } UseTreeKind::Glob => { @@ -667,7 +670,8 @@ impl<'hir> LoweringContext<'_, 'hir> { let res = self.expect_full_res_from_use(id).next().unwrap_or(Res::Err); let res = self.lower_res(res); - let path = self.arena.alloc(self.lower_path_extra(res, &prefix, ParamMode::Explicit, None)); + let path = self.lower_path_extra(res, &prefix, ParamMode::Explicit, None); + let path = self.arena.alloc(path); hir::ItemKind::Use(path, hir::UseKind::ListStem) } } @@ -733,8 +737,8 @@ impl<'hir> LoweringContext<'_, 'hir> { hir::ForeignItemKind::Fn(fn_dec, fn_args, generics) } ForeignItemKind::Static(ref t, m) => { - hir::ForeignItemKind::Static( - self.arena.alloc(self.lower_ty(t, ImplTraitContext::disallowed()).into_inner()), m) + let ty = self.lower_ty(t, ImplTraitContext::disallowed()); + hir::ForeignItemKind::Static(self.arena.alloc(ty.into_inner()), m) } ForeignItemKind::Ty => hir::ForeignItemKind::Type, ForeignItemKind::Macro(_) => panic!("macro shouldn't exist here"), @@ -771,7 +775,9 @@ impl<'hir> LoweringContext<'_, 'hir> { fn lower_variant_data(&mut self, vdata: &VariantData) -> hir::VariantData<'hir> { match *vdata { VariantData::Struct(ref fields, recovered) => hir::VariantData::Struct( - self.arena.alloc_from_iter(fields.iter().enumerate().map(|f| self.lower_struct_field(f))), + self.arena.alloc_from_iter( + fields.iter().enumerate().map(|f| self.lower_struct_field(f)) + ), recovered, ), VariantData::Tuple(ref fields, id) => { @@ -823,15 +829,17 @@ impl<'hir> LoweringContext<'_, 'hir> { let trait_item_def_id = self.resolver.definitions().local_def_id(i.id); let (generics, kind) = match i.kind { - AssocItemKind::Const(ref ty, ref default) => ( - self.lower_generics(&i.generics, ImplTraitContext::disallowed()), - hir::TraitItemKind::Const( - self.arena.alloc(self.lower_ty(ty, ImplTraitContext::disallowed()).into_inner()), + AssocItemKind::Const(ref ty, ref default) => { + let generics = self.lower_generics(&i.generics, ImplTraitContext::disallowed()); + let ty = self.lower_ty(ty, ImplTraitContext::disallowed()); + let ty = self.arena.alloc(ty.into_inner()); + (generics, hir::TraitItemKind::Const( + ty, default .as_ref() .map(|x| self.lower_const_body(i.span, Some(x))), - ), - ), + )) + }, AssocItemKind::Fn(ref sig, None) => { let names = self.lower_fn_params_to_names(&sig.decl); let (generics, sig) = self.lower_method_sig( @@ -913,13 +921,15 @@ impl<'hir> LoweringContext<'_, 'hir> { let impl_item_def_id = self.resolver.definitions().local_def_id(i.id); let (generics, kind) = match i.kind { - AssocItemKind::Const(ref ty, ref expr) => ( - self.lower_generics(&i.generics, ImplTraitContext::disallowed()), - hir::ImplItemKind::Const( - self.arena.alloc(self.lower_ty(ty, ImplTraitContext::disallowed()).into_inner()), + AssocItemKind::Const(ref ty, ref expr) => { + let generics = self.lower_generics(&i.generics, ImplTraitContext::disallowed()); + let ty = self.lower_ty(ty, ImplTraitContext::disallowed()); + let ty = self.arena.alloc(ty.into_inner()); + (generics, hir::ImplItemKind::Const( + ty, self.lower_const_body(i.span, expr.as_deref()), - ), - ), + )) + }, AssocItemKind::Fn(ref sig, ref body) => { self.current_item = Some(i.span); let body_id = self.lower_maybe_async_body( @@ -1302,7 +1312,10 @@ impl<'hir> LoweringContext<'_, 'hir> { this.expr_block(P(body), AttrVec::new()) }); - (this.arena.alloc_from_iter(parameters), this.expr(body_span, async_expr, AttrVec::new())) + ( + this.arena.alloc_from_iter(parameters), + this.expr(body_span, async_expr, AttrVec::new()), + ) }) } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index b83bfedc824..23133454bd9 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -996,7 +996,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnreachablePub { self.perform_lint(cx, "item", item.hir_id, &item.vis, item.span, true); } - fn check_foreign_item(&mut self, cx: &LateContext<'_, '_>, foreign_item: &hir::ForeignItem<'tcx>) { + fn check_foreign_item( + &mut self, + cx: &LateContext<'_, '_>, + foreign_item: &hir::ForeignItem<'tcx>, + ) { self.perform_lint(cx, "item", foreign_item.hir_id, &foreign_item.vis, foreign_item.span, true); } diff --git a/src/librustc_lint/nonstandard_style.rs b/src/librustc_lint/nonstandard_style.rs index 08d7a90c7b0..bd2cbee2c34 100644 --- a/src/librustc_lint/nonstandard_style.rs +++ b/src/librustc_lint/nonstandard_style.rs @@ -246,7 +246,13 @@ impl NonSnakeCase { } impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase { - fn check_mod(&mut self, cx: &LateContext<'_, '_>, _: &'tcx hir::Mod<'tcx>, _: 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_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 1cd1d4fcd3f..b2c5ddd5bd4 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2435,7 +2435,12 @@ fn check_transparent(tcx: TyCtxt<'_>, sp: Span, def_id: DefId) { } #[allow(trivial_numeric_casts)] -pub fn check_enum<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, vs: &'tcx [hir::Variant<'tcx>], id: hir::HirId) { +pub fn check_enum<'tcx>( + tcx: TyCtxt<'tcx>, + sp: Span, + vs: &'tcx [hir::Variant<'tcx>], + id: hir::HirId, +) { let def_id = tcx.hir().local_def_id(id); let def = tcx.adt_def(def_id); def.destructor(tcx); // force the destructor to be evaluated diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 27ce7d7c3e0..a32c98068da 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -32,7 +32,9 @@ use std::mem; // resolve_type_vars_in_body, which creates a new TypeTables which // doesn't contain any inference types. impl<'a, 'tcx> FnCtxt<'a, 'tcx> { - pub fn resolve_type_vars_in_body(&self, body: &'tcx hir::Body<'tcx>) -> &'tcx ty::TypeckTables<'tcx> { + pub fn resolve_type_vars_in_body(&self, body: &'tcx hir::Body<'tcx>) + -> &'tcx ty::TypeckTables<'tcx> + { let item_id = self.tcx.hir().body_owner(body.id()); let item_def_id = self.tcx.hir().local_def_id(item_id); From baa49b2343b852d4bd4151f7c42e36a3351d0981 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 1 Dec 2019 17:33:31 +0100 Subject: [PATCH 12/12] Nits. --- src/librustc/arena.rs | 7 ++++--- src/librustc/hir/print.rs | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/librustc/arena.rs b/src/librustc/arena.rs index 164e0e85c5a..3695607ff3c 100644 --- a/src/librustc/arena.rs +++ b/src/librustc/arena.rs @@ -122,14 +122,15 @@ macro_rules! arena_types { [few] crate_variances: rustc::ty::CrateVariancesMap<'tcx>, [few] inferred_outlives_crate: rustc::ty::CratePredicatesMap<'tcx>, [] upvars: rustc_data_structures::fx::FxIndexMap, - // HIR nodes arenas + + // HIR types [few] hir_forest: rustc::hir::map::Forest<$tcx>, [] attribute: syntax::ast::Attribute, - [] global_asm: rustc::hir::GlobalAsm, + [few] global_asm: rustc::hir::GlobalAsm, [] fn_decl: rustc::hir::FnDecl, [] foreign_item: rustc::hir::ForeignItem<$tcx>, [] impl_item_ref: rustc::hir::ImplItemRef, - [] macro_def: rustc::hir::MacroDef<$tcx>, + [few] macro_def: rustc::hir::MacroDef<$tcx>, [] param: rustc::hir::Param, [] path: rustc::hir::Path, [] struct_field: rustc::hir::StructField<$tcx>, diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index f0499e5853f..85747cadbd7 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -107,7 +107,7 @@ pub const INDENT_UNIT: usize = 4; /// it can scan the input text for comments to copy forward. pub fn print_crate<'a>(cm: &'a SourceMap, sess: &ParseSess, - krate: &hir::Crate<'a>, + krate: &hir::Crate<'_>, filename: FileName, input: String, ann: &'a dyn PpAnn) -> String {