Auto merge of #66931 - cjgillot:hirene-preamble, r=eddyb

Allocate HIR on an arena 1/4

This PR is the first in a series of 4, aiming at allocating the HIR on an arena, as a memory optimisation.

1. This first PR lays the groundwork and migrates some low-hanging fruits.
2. The second PR will migrate `hir::Expr`, `hir::Pat` and related.
3. The third PR will migrate `hir::Ty` and related.
4. The final PR will be dedicated to eventual cleanups.

In order to make the transition as gradual as possible, some lowering routines receive `Box`-allocated data and move it into the arena. This is a bit wasteful, but hopefully temporary.
Nonetheless, special care should be taken to avoid double arena allocations.

Work mentored by @Zoxc.
This commit is contained in:
bors 2019-12-22 10:30:51 +00:00
commit 26286c7ad0
84 changed files with 857 additions and 782 deletions

View File

@ -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,21 @@ 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<rustc::hir::HirId, rustc::hir::Upvar>,
// HIR types
[few] hir_forest: rustc::hir::map::Forest<$tcx>,
[] attribute: syntax::ast::Attribute,
[few] global_asm: rustc::hir::GlobalAsm,
[] fn_decl: rustc::hir::FnDecl,
[] foreign_item: rustc::hir::ForeignItem<$tcx>,
[] impl_item_ref: rustc::hir::ImplItemRef,
[few] 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,
[] ty: rustc::hir::Ty,
[] variant: rustc::hir::Variant<$tcx>,
], $tcx);
)
}

View File

@ -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};
@ -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,
@ -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(_)) => {
@ -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,
@ -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(..) => {
@ -158,10 +158,10 @@ impl CheckAttrVisitor<'tcx> {
fn check_attributes(
&self,
hir_id: HirId,
attrs: &HirVec<Attribute>,
attrs: &'hir [Attribute],
span: &Span,
target: Target,
item: Option<&Item>,
item: Option<&Item<'_>>,
) {
let mut is_valid = true;
for attr in attrs {
@ -241,7 +241,7 @@ impl CheckAttrVisitor<'tcx> {
fn check_track_caller(
&self,
attr_span: &Span,
attrs: &HirVec<Attribute>,
attrs: &'hir [Attribute],
span: &Span,
target: Target,
) -> bool {
@ -332,10 +332,10 @@ impl CheckAttrVisitor<'tcx> {
/// Checks if the `#[repr]` attributes on `item` are valid.
fn check_repr(
&self,
attrs: &HirVec<Attribute>,
attrs: &'hir [Attribute],
span: &Span,
target: Target,
item: Option<&Item>,
item: Option<&Item<'_>>,
) {
// Extract the names of all repr hints, e.g., [foo, bar, align] for:
// ```
@ -477,7 +477,7 @@ impl CheckAttrVisitor<'tcx> {
}
}
fn check_used(&self, attrs: &HirVec<Attribute>, 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
@ -492,25 +492,25 @@ 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));
self.check_attributes(item.hir_id, item.attrs, &item.span, target, Some(item));
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)
}
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)
}
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)
@ -527,9 +527,9 @@ 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 {
for variant in def.variants {
match variant.data {
hir::VariantData::Unit(..) => { /* continue */ }
_ => return false,

View File

@ -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,

View File

@ -218,11 +218,11 @@ 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)
}
fn visit_body(&mut self, b: &'v Body) {
fn visit_body(&mut self, b: &'v Body<'v>) {
walk_body(self, b);
}
@ -247,10 +247,10 @@ 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) {
fn visit_foreign_item(&mut self, i: &'v ForeignItem<'v>) {
walk_foreign_item(self, i)
}
fn visit_local(&mut self, l: &'v Local) {
@ -295,13 +295,13 @@ 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) {
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) {
@ -317,24 +317,24 @@ 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,
_: 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,
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) {
@ -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) {
@ -382,27 +382,27 @@ 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) {
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, &macro_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) {
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);
}
}
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);
}
@ -462,7 +462,7 @@ pub fn walk_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Param) {
walk_list!(visitor, visit_attribute, &param.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 {
@ -498,7 +498,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
}
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);
@ -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);
@ -554,7 +554,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
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,
@ -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) {
@ -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 &param_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) {
@ -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) => {
@ -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: _,
@ -948,19 +948,22 @@ 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);
}
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) {

View File

@ -45,9 +45,9 @@ 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_trait_item(&mut self, trait_item: &'hir TraitItem);
fn visit_impl_item(&mut self, impl_item: &'hir ImplItem);
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<'hir>);
}
pub struct DeepVisitor<'v, V> {
@ -65,24 +65,24 @@ 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);
}
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);
}
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);
}
}
/// A parallel variant of `ItemLikeVisitor`.
pub trait ParItemLikeVisitor<'hir> {
fn visit_item(&self, item: &'hir Item);
fn visit_trait_item(&self, trait_item: &'hir TraitItem);
fn visit_impl_item(&self, impl_item: &'hir ImplItem);
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<'hir>);
}
pub trait IntoVisitor<'hir> {
@ -95,15 +95,15 @@ pub struct ParDeepVisitor<V>(pub V);
impl<'hir, V> ParItemLikeVisitor<'hir> for ParDeepVisitor<V>
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);
}
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);
}
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);
}
}

View File

@ -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<Symbol>,
/// Used to assign IDs to HIR nodes that do not directly correspond to AST nodes.
@ -90,13 +91,16 @@ pub struct LoweringContext<'a> {
/// librustc is independent of the parser, we use dynamic dispatch here.
nt_to_tokenstream: NtToTokenstream,
/// The items being lowered are collected here.
items: BTreeMap<hir::HirId, hir::Item>,
/// Used to allocate HIR nodes
arena: &'hir Arena<'hir>,
trait_items: BTreeMap<hir::TraitItemId, hir::TraitItem>,
impl_items: BTreeMap<hir::ImplItemId, hir::ImplItem>,
bodies: BTreeMap<hir::BodyId, hir::Body>,
exported_macros: Vec<hir::MacroDef>,
/// The items being lowered are collected here.
items: BTreeMap<hir::HirId, hir::Item<'hir>>,
trait_items: BTreeMap<hir::TraitItemId, hir::TraitItem<'hir>>,
impl_items: BTreeMap<hir::ImplItemId, hir::ImplItem<'hir>>,
bodies: BTreeMap<hir::BodyId, hir::Body<'hir>>,
exported_macros: Vec<hir::MacroDef<'hir>>,
non_exported_macro_attrs: Vec<ast::Attribute>,
trait_impls: BTreeMap<DefId, Vec<hir::HirId>>,
@ -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<NodeId>,
}
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,
@ -560,7 +566,7 @@ impl<'a> LoweringContext<'a> {
}
}
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));
@ -750,7 +756,7 @@ impl<'a> LoweringContext<'a> {
f: F,
) -> (Vec<hir::GenericParam>, T)
where
F: FnOnce(&mut LoweringContext<'_>) -> (Vec<hir::GenericParam>, T),
F: FnOnce(&mut LoweringContext<'_, '_>) -> (Vec<hir::GenericParam>, T),
{
assert!(!self.is_collecting_in_band_lifetimes);
assert!(self.lifetimes_to_define.is_empty());
@ -867,7 +873,7 @@ impl<'a> LoweringContext<'a> {
// for them.
fn with_in_scope_lifetime_defs<T, F>(&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 {
@ -896,7 +902,7 @@ impl<'a> LoweringContext<'a> {
f: F,
) -> (hir::Generics, T)
where
F: FnOnce(&mut LoweringContext<'_>, &mut Vec<hir::GenericParam>) -> T,
F: FnOnce(&mut LoweringContext<'_, '_>, &mut Vec<hir::GenericParam>) -> T,
{
let (in_band_defs, (mut lowered_generics, res)) = self.with_in_scope_lifetime_defs(
&generics.params,
@ -945,7 +951,7 @@ impl<'a> LoweringContext<'a> {
fn with_dyn_type_scope<T, F>(&mut self, in_scope: bool, f: F) -> T
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<T, F>(&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;
@ -983,15 +989,14 @@ impl<'a> LoweringContext<'a> {
}
}
fn lower_attrs_extendable(&mut self, attrs: &[Attribute]) -> Vec<Attribute> {
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<Attribute> {
self.lower_attrs_extendable(attrs).into()
attrs.iter().map(|a| self.lower_attr(a)).collect::<Vec<_>>().into()
}
fn lower_attr(&mut self, attr: &Attribute) -> Attribute {
@ -1446,7 +1451,7 @@ impl<'a> LoweringContext<'a> {
span: Span,
fn_def_id: Option<DefId>,
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 +1568,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 +1579,9 @@ impl<'a> LoweringContext<'a> {
output_lifetime_params: Vec<hir::GenericParam>,
}
impl<'r, 'a, 'v> hir::intravisit::Visitor<'v> for ImplTraitLifetimeCollector<'r, 'a> {
impl<'r, 'a, 'v, 'hir> hir::intravisit::Visitor<'v>
for ImplTraitLifetimeCollector<'r, 'a, 'hir>
{
fn nested_visit_map<'this>(
&'this mut self,
) -> hir::intravisit::NestedVisitorMap<'this, 'v> {
@ -2757,8 +2764,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) => {
@ -3422,7 +3430,7 @@ impl<'a> LoweringContext<'a> {
}
}
fn body_ids(bodies: &BTreeMap<hir::BodyId, hir::Body>) -> Vec<hir::BodyId> {
fn body_ids(bodies: &BTreeMap<hir::BodyId, hir::Body<'hir>>) -> Vec<hir::BodyId> {
// 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();

View File

@ -13,7 +13,7 @@ use syntax::symbol::{sym, Symbol};
use rustc_error_codes::*;
impl LoweringContext<'_> {
impl LoweringContext<'_, '_> {
fn lower_exprs(&mut self, exprs: &[AstP<Expr>]) -> HirVec<hir::Expr> {
exprs.iter().map(|x| self.lower_expr(x)).collect()
}
@ -473,7 +473,7 @@ impl LoweringContext<'_> {
ret_ty: Option<AstP<Ty>>,
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<T, F>(&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<T, F>(&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<T, F>(&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;

View File

@ -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};
@ -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<F>(&mut self, trait_impl_ref: &Option<TraitRef>, 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<'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
@ -116,7 +116,7 @@ impl LoweringContext<'_> {
fn with_parent_item_lifetime_defs<T>(
&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<T>(
&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![]);
@ -161,10 +161,12 @@ impl LoweringContext<'_> {
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))
),
}
}
@ -225,10 +227,10 @@ impl LoweringContext<'_> {
}
}
pub fn lower_item(&mut self, i: &Item) -> Option<hir::Item> {
pub fn lower_item(&mut self, i: &Item) -> Option<hir::Item<'hir>> {
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 +246,12 @@ impl LoweringContext<'_> {
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,10 +268,10 @@ impl LoweringContext<'_> {
span: Span,
id: NodeId,
ident: &mut Ident,
attrs: &hir::HirVec<Attribute>,
attrs: &'hir [Attribute],
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 +284,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 +350,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 {
@ -361,11 +365,12 @@ impl LoweringContext<'_> {
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()),
)
@ -434,10 +439,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 +453,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,
@ -484,8 +490,8 @@ impl LoweringContext<'_> {
id: NodeId,
vis: &mut hir::Visibility,
ident: &mut Ident,
attrs: &hir::HirVec<Attribute>,
) -> hir::ItemKind {
attrs: &'hir [Attribute],
) -> hir::ItemKind<'hir> {
debug!("lower_use_tree(tree={:?})", tree);
debug!("lower_use_tree: vis = {:?}", vis);
@ -540,14 +546,14 @@ 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(
hir::Item {
hir_id: new_id,
ident,
attrs: attrs.into_iter().cloned().collect(),
attrs,
kind,
vis,
span,
@ -556,11 +562,12 @@ impl LoweringContext<'_> {
});
}
let path = P(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 => {
let path = P(self.lower_path(
let path = self.arena.alloc(self.lower_path(
id,
&Path {
segments,
@ -631,7 +638,7 @@ impl LoweringContext<'_> {
hir::Item {
hir_id: new_hir_id,
ident,
attrs: attrs.into_iter().cloned().collect(),
attrs,
kind,
vis,
span: use_tree.span,
@ -663,7 +670,8 @@ 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.lower_path_extra(res, &prefix, ParamMode::Explicit, None);
let path = self.arena.alloc(path);
hir::ItemKind::Use(path, hir::UseKind::ListStem)
}
}
@ -703,12 +711,12 @@ impl LoweringContext<'_> {
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(
@ -723,12 +731,14 @@ impl LoweringContext<'_> {
)
},
);
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)
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"),
@ -738,23 +748,22 @@ impl LoweringContext<'_> {
}
}
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))),
}
}
fn lower_global_asm(&mut self, ga: &GlobalAsm) -> P<hir::GlobalAsm> {
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 {
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),
@ -763,19 +772,22 @@ impl LoweringContext<'_> {
}
}
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),
)
},
@ -785,7 +797,7 @@ impl LoweringContext<'_> {
}
}
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,
@ -794,9 +806,10 @@ impl LoweringContext<'_> {
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,
@ -808,23 +821,25 @@ impl LoweringContext<'_> {
},
vis: self.lower_visibility(&f.vis, None),
ty,
attrs: self.lower_attrs(&f.attrs),
attrs: self.lower_attrs_arena(&f.attrs),
}
}
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()),
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(
@ -848,12 +863,13 @@ impl LoweringContext<'_> {
(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)
@ -864,7 +880,7 @@ impl LoweringContext<'_> {
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,
@ -901,17 +917,19 @@ impl LoweringContext<'_> {
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()),
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(
@ -935,11 +953,13 @@ impl LoweringContext<'_> {
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) => {
@ -956,7 +976,7 @@ impl LoweringContext<'_> {
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] */),
@ -1042,7 +1062,7 @@ impl LoweringContext<'_> {
}
}
fn record_body(&mut self, params: HirVec<hir::Param>, 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,
@ -1055,7 +1075,7 @@ impl LoweringContext<'_> {
fn lower_body(
&mut self,
f: impl FnOnce(&mut LoweringContext<'_>) -> (HirVec<hir::Param>, 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);
@ -1076,10 +1096,12 @@ 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(),
this.arena.alloc_from_iter(
decl.inputs.iter().map(|x| this.lower_param(x))
),
body(this),
))
}
@ -1101,7 +1123,7 @@ impl LoweringContext<'_> {
}
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),
}))
@ -1289,7 +1311,11 @@ impl LoweringContext<'_> {
);
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()),
)
})
}

View File

@ -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,
@ -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,
@ -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,

View File

@ -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<HirId, NodeId>,
@ -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());
@ -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| {
@ -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| {
@ -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| {
@ -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[&macro_def.hir_id];
let def_index = self.definitions.opt_def_index(node_id).unwrap();
@ -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.
@ -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);

View File

@ -53,17 +53,17 @@ 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));
}
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));
}
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));
}

View File

@ -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<DefIndex, IndexVec<ItemLocalId, Opt
#[derive(Clone)]
pub struct Map<'hir> {
/// 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,11 +439,11 @@ impl<'hir> Map<'hir> {
self.lookup(id).cloned()
}
pub fn krate(&self) -> &'hir Crate {
pub fn krate(&self) -> &'hir Crate<'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
@ -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
@ -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
@ -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 {
@ -959,28 +959,28 @@ 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))
}
}
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))
}
}
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))
}
}
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,14 +995,14 @@ 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)),
}
}
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))
@ -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,16 +1248,16 @@ trait Named {
impl<T:Named> Named for Spanned<T> { 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 TraitItem { fn name(&self) -> Name { self.ident.name } }
impl Named for ImplItem { 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 } }
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,
cstore: &CrateStoreDyn,
forest: &'hir Forest,
forest: &'hir Forest<'hir>,
definitions: Definitions)
-> Map<'hir> {
let _prof_timer = sess.prof.generic_activity("build_hir_map");

View File

@ -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 module: Mod,
pub attrs: HirVec<Attribute>,
pub struct Crate<'hir> {
pub module: Mod<'hir>,
pub attrs: &'hir [Attribute],
pub span: Span,
pub exported_macros: HirVec<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: HirVec<Attribute>,
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
@ -756,11 +756,11 @@ pub struct Crate {
// 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<HirId, Item>,
pub items: BTreeMap<HirId, Item<'hir>>,
pub trait_items: BTreeMap<TraitItemId, TraitItem>,
pub impl_items: BTreeMap<ImplItemId, ImplItem>,
pub bodies: BTreeMap<BodyId, Body>,
pub trait_items: BTreeMap<TraitItemId, TraitItem<'hir>>,
pub impl_items: BTreeMap<ImplItemId, ImplItem<'hir>>,
pub bodies: BTreeMap<BodyId, Body<'hir>>,
pub trait_impls: BTreeMap<DefId, Vec<HirId>>,
/// A list of the body ids written out in the order in which they
@ -774,19 +774,25 @@ pub struct Crate {
pub modules: BTreeMap<HirId, ModuleItems>,
}
impl Crate {
pub fn item(&self, id: HirId) -> &Item {
impl Crate<'hir> {
pub fn item(&self, id: HirId) -> &Item<'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]
}
pub fn impl_item(&self, id: ImplItemId) -> &ImplItem {
pub fn impl_item(&self, id: ImplItemId) -> &ImplItem<'hir> {
&self.impl_items[&id]
}
pub fn body(&self, id: BodyId) -> &Body<'hir> {
&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,20 +835,16 @@ impl Crate {
});
});
}
pub fn body(&self, id: BodyId) -> &Body {
&self.bodies[&id]
}
}
/// A macro definition, in this crate or imported from another.
///
/// 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<Attribute>,
pub attrs: &'hir [Attribute],
pub hir_id: HirId,
pub span: Span,
pub body: TokenStream,
@ -1351,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<Param>,
pub struct Body<'hir> {
pub params: &'hir [Param],
pub value: Expr,
pub generator_kind: Option<GeneratorKind>,
}
impl Body {
impl Body<'hir> {
pub fn id(&self) -> BodyId {
BodyId {
hir_id: self.value.hir_id,
@ -1895,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<Attribute>,
pub attrs: &'hir [Attribute],
pub generics: Generics,
pub kind: TraitItemKind,
pub kind: TraitItemKind<'hir>,
pub span: Span,
}
@ -1916,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<Ty>, Option<BodyId>),
Const(&'hir Ty, Option<BodyId>),
/// A method with an optional body.
Method(FnSig, TraitMethod),
/// An associated type with (possibly empty) bounds and optional concrete
/// type.
Type(GenericBounds, Option<P<Ty>>),
Type(GenericBounds, Option<&'hir Ty>),
}
// The bodies for items are stored "out of line", in a separate
@ -1936,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<Attribute>,
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<Ty>, BodyId),
Const(&'hir Ty, BodyId),
/// A method implementation with the given signature and body.
Method(FnSig, BodyId),
/// An associated type.
TyAlias(P<Ty>),
TyAlias(&'hir Ty),
/// An associated `type = impl Trait`.
OpaqueTy(GenericBounds),
}
@ -2241,18 +2243,18 @@ impl FunctionRetTy {
}
#[derive(RustcEncodable, RustcDecodable, Debug)]
pub struct Mod {
pub struct Mod<'hir> {
/// A span from the first token past `{` to the last token until `}`.
/// For `mod foo;`, the inner span ranges from the first token
/// to the last token in the external file.
pub inner: Span,
pub item_ids: HirVec<ItemId>,
pub item_ids: &'hir [ItemId],
}
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct ForeignMod {
pub struct ForeignMod<'hir> {
pub abi: Abi,
pub items: HirVec<ForeignItem>,
pub items: &'hir [ForeignItem<'hir>],
}
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
@ -2261,21 +2263,21 @@ pub struct GlobalAsm {
}
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct EnumDef {
pub variants: HirVec<Variant>,
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<Attribute>,
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<AnonConst>,
/// Span
@ -2375,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<Ty>,
pub attrs: HirVec<Attribute>,
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];
@ -2395,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<StructField>, /* recovered */ bool),
Struct(&'hir [StructField<'hir>], /* recovered */ bool),
/// A tuple variant.
///
/// E.g., `Bar(..)` as in `enum Foo { Bar(..) }`.
Tuple(HirVec<StructField>, HirId),
Tuple(&'hir [StructField<'hir>], 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<'hir>] {
match *self {
VariantData::Struct(ref fields, ..) | VariantData::Tuple(ref fields, ..) => fields,
_ => &[],
@ -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<Attribute>,
pub kind: ItemKind,
pub attrs: &'hir [Attribute],
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,32 +2480,32 @@ pub enum ItemKind {
/// or just
///
/// `use foo::bar::baz;` (with `as baz` implicitly on the right).
Use(P<Path>, UseKind),
Use(&'hir Path, UseKind),
/// A `static` item.
Static(P<Ty>, Mutability, BodyId),
Static(&'hir Ty, Mutability, BodyId),
/// A `const` item.
Const(P<Ty>, BodyId),
Const(&'hir Ty, BodyId),
/// A function declaration.
Fn(FnSig, Generics, BodyId),
/// A module.
Mod(Mod),
Mod(Mod<'hir>),
/// An external module, e.g. `extern { .. }`.
ForeignMod(ForeignMod),
ForeignMod(ForeignMod<'hir>),
/// Module-level inline assembly (from `global_asm!`).
GlobalAsm(P<GlobalAsm>),
GlobalAsm(&'hir GlobalAsm),
/// A type alias, e.g., `type Foo = Bar<u8>`.
TyAlias(P<Ty>, 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<A, B> {C<A>, D<B>}`.
Enum(EnumDef, Generics),
Enum(EnumDef<'hir>, Generics),
/// A struct definition, e.g., `struct Foo<A> {x: A}`.
Struct(VariantData, Generics),
Struct(VariantData<'hir>, Generics),
/// A union definition, e.g., `union Foo<A, B> {x: A, y: B}`.
Union(VariantData, Generics),
Union(VariantData<'hir>, Generics),
/// A trait definition.
Trait(IsAuto, Unsafety, Generics, GenericBounds, HirVec<TraitItemRef>),
Trait(IsAuto, Unsafety, Generics, GenericBounds, &'hir [TraitItemRef]),
/// A trait alias.
TraitAlias(Generics, GenericBounds),
@ -2513,11 +2515,11 @@ pub enum ItemKind {
Defaultness,
Generics,
Option<TraitRef>, // (optional) trait this impl implements
P<Ty>, // self
HirVec<ImplItemRef>),
&'hir Ty, // self
&'hir [ImplItemRef]),
}
impl ItemKind {
impl ItemKind<'_> {
pub fn descriptive_variant(&self) -> &str {
match *self {
ItemKind::ExternCrate(..) => "extern crate",
@ -2605,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<Attribute>,
pub kind: ForeignItemKind,
pub attrs: &'hir [Attribute],
pub kind: ForeignItemKind<'hir>,
pub hir_id: HirId,
pub span: Span,
pub vis: Visibility,
@ -2617,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<FnDecl>, HirVec<Ident>, Generics),
Fn(&'hir FnDecl, &'hir [Ident], Generics),
/// A foreign static item (`static ext: u8`).
Static(P<Ty>, 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",
@ -2785,12 +2787,12 @@ impl CodegenFnAttrs {
#[derive(Copy, Clone, Debug)]
pub enum Node<'hir> {
Param(&'hir Param),
Item(&'hir Item),
ForeignItem(&'hir ForeignItem),
TraitItem(&'hir TraitItem),
ImplItem(&'hir ImplItem),
Variant(&'hir Variant),
Field(&'hir StructField),
Item(&'hir Item<'hir>),
ForeignItem(&'hir ForeignItem<'hir>),
TraitItem(&'hir TraitItem<'hir>),
ImplItem(&'hir ImplItem<'hir>),
Variant(&'hir Variant<'hir>),
Field(&'hir StructField<'hir>),
AnonConst(&'hir AnonConst),
Expr(&'hir Expr),
Stmt(&'hir Stmt),
@ -2802,11 +2804,11 @@ 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.
Ctor(&'hir VariantData),
Ctor(&'hir VariantData<'hir>),
Lifetime(&'hir Lifetime),
GenericParam(&'hir GenericParam),

View File

@ -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
}
}
@ -52,8 +52,8 @@ pub struct NoAnn;
impl PpAnn for NoAnn {}
pub const NO_ANN: &dyn PpAnn = &NoAnn;
impl PpAnn for hir::Crate {
fn try_fetch_item(&self, item: hir::HirId) -> Option<&hir::Item> {
impl PpAnn for hir::Crate<'a> {
fn try_fetch_item(&self, item: hir::HirId) -> Option<&hir::Item<'_>> {
Some(self.item(item))
}
fn nested(&self, state: &mut State<'_>, nested: Nested) {
@ -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<'_>,
filename: FileName,
input: String,
ann: &'a dyn PpAnn) -> String {
@ -259,19 +259,19 @@ 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));
}
}
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);
@ -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);
@ -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);
@ -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());
@ -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());

View File

@ -56,12 +56,12 @@ 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`.
/// **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)
}
}
@ -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 {

View File

@ -150,7 +150,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Expr {
}
}
impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitItem {
impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitItem<'_> {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let hir::TraitItem {
hir_id: _,
@ -172,7 +172,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitItem {
}
impl<'a> HashStable<StableHashingContext<'a>> for hir::ImplItem {
impl<'a> HashStable<StableHashingContext<'a>> for hir::ImplItem<'_> {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let hir::ImplItem {
hir_id: _,
@ -218,7 +218,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::VisibilityKind {
}
}
impl<'a> HashStable<StableHashingContext<'a>> for hir::Mod {
impl<'a> HashStable<StableHashingContext<'a>> for hir::Mod<'_> {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let hir::Mod {
inner: ref inner_span,
@ -245,7 +245,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Mod {
}
}
impl<'a> HashStable<StableHashingContext<'a>> for hir::Item {
impl<'a> HashStable<StableHashingContext<'a>> for hir::Item<'_> {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let hir::Item {
ident,
@ -266,7 +266,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Item {
}
}
impl<'a> HashStable<StableHashingContext<'a>> for hir::Body {
impl<'a> HashStable<StableHashingContext<'a>> for hir::Body<'_> {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let hir::Body {
params,

View File

@ -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",
@ -264,14 +264,14 @@ 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",
}
}
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(..)

View File

@ -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,

View File

@ -883,7 +883,7 @@ impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> LateContextAndPass<'a, 'tcx, T> {
self.context.param_env = old_param_env;
}
fn process_mod(&mut self, m: &'tcx hir::Mod, s: Span, n: hir::HirId) {
fn process_mod(&mut self, m: &'tcx hir::Mod<'tcx>, s: Span, n: hir::HirId) {
lint_callback!(self, check_mod, m, s, n);
hir_visit::walk_mod(self, m, n);
lint_callback!(self, check_mod_post, m, s, n);
@ -924,13 +924,13 @@ 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);
}
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| {
@ -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);
@ -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,
@ -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);
@ -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| {
@ -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);
}
@ -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| {
@ -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| {

View File

@ -87,17 +87,17 @@ 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);
fn check_crate_post(a: &$hir hir::Crate);
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_item(a: &$hir hir::Item);
fn check_item_post(a: &$hir hir::Item);
fn check_crate(a: &$hir hir::Crate<$hir>);
fn check_crate_post(a: &$hir hir::Crate<$hir>);
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>);
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);
@ -114,25 +114,25 @@ 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
);
fn check_trait_item(a: &$hir hir::TraitItem);
fn check_trait_item_post(a: &$hir hir::TraitItem);
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);
fn check_struct_def_post(a: &$hir hir::VariantData);
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_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<$hir>);
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<$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);
fn check_path(a: &$hir hir::Path, b: hir::HirId);
fn check_attribute(a: &$hir ast::Attribute);
@ -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);
@ -604,13 +604,13 @@ 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);
});
}
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);
})
@ -622,14 +622,14 @@ 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);
})
}
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| {
@ -649,13 +649,13 @@ 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);
});
}
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);
});

View File

@ -25,15 +25,15 @@ 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);
}
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);
}
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);
}
}

View File

@ -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() {
@ -151,11 +151,11 @@ 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.
}
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.
}
}

View File

@ -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);

View File

@ -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
}
@ -47,7 +47,7 @@ fn item_might_be_inlined(tcx: TyCtxt<'tcx>, item: &hir::Item, attrs: CodegenFnAt
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());
@ -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.
@ -387,9 +387,9 @@ 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) {
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) {
// processed in visit_item above
}
}

View File

@ -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<Span> {
body: &'tcx hir::Body<'tcx>) -> Option<Span> {
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(&param.pat);
}

View File

@ -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| {
@ -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| {
@ -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, _) => {
@ -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, _) => {
@ -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>,

View File

@ -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 {
@ -283,13 +283,13 @@ 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);
});
}
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 {
@ -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() {
@ -312,19 +312,19 @@ 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);
});
}
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);
});
}
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, |_| {});
}
}
@ -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
@ -368,12 +368,12 @@ 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);
}
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() {
@ -382,22 +382,22 @@ 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);
}
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);
}
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);
}
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");
}
}
@ -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);

View File

@ -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);
}

View File

@ -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<traits::PredicateObligation<'tcx>> {
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<traits::PredicateObligation<'tcx>>,
item: Option<&'tcx hir::Item>,
item: Option<&'tcx hir::Item<'tcx>>,
}
/// Controls whether we "elaborate" supertraits and so forth on the WF

View File

@ -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)

View File

@ -57,15 +57,15 @@ 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);
}
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);
}
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);
}
}

View File

@ -73,7 +73,7 @@ where
}
fn call_with_pp_support_hir<A, F>(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 => {

View File

@ -162,22 +162,22 @@ 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);
}
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);
}
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);
}
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);
}

View File

@ -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);
}
})

View File

@ -532,15 +532,15 @@ 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);
}
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);
}
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);
}
}

View File

@ -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<hir::map::Forest> {
resolver: &'res mut Resolver<'_>,
dep_graph: &'res DepGraph,
krate: &'res ast::Crate,
arena: &'tcx Arena<'tcx>,
) -> Result<hir::map::Forest<'tcx>> {
// 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<lint::LintStore>,
hir_forest: &'tcx hir::map::Forest,
hir_forest: &'tcx hir::map::Forest<'tcx>,
mut resolver_outputs: ResolverOutputs,
outputs: OutputFilenames,
crate_name: &str,

View File

@ -24,16 +24,16 @@ 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);
}
}
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) {
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) {
}
}

View File

@ -82,7 +82,7 @@ pub struct Queries<'tcx> {
register_plugins: Query<(ast::Crate, Lrc<LintStore>)>,
expansion: Query<(ast::Crate, Steal<Rc<RefCell<BoxedResolver>>>, Lrc<LintStore>)>,
dep_graph: Query<DepGraph>,
lower_to_hir: Query<(&'tcx hir::map::Forest, Steal<ResolverOutputs>)>,
lower_to_hir: Query<(&'tcx hir::map::Forest<'tcx>, Steal<ResolverOutputs>)>,
prepare_outputs: Query<OutputFilenames>,
global_ctxt: Query<QueryContext<'tcx>>,
ongoing_codegen: Query<Box<dyn Any>>,
@ -216,7 +216,7 @@ impl<'tcx> Queries<'tcx> {
pub fn lower_to_hir(
&'tcx self,
) -> Result<&Query<(&'tcx hir::map::Forest, Steal<ResolverOutputs>)>> {
) -> Result<&Query<(&'tcx hir::map::Forest<'tcx>, Steal<ResolverOutputs>)>> {
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);

View File

@ -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(..) |
@ -387,10 +387,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,
@ -400,14 +400,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);
@ -419,7 +419,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();
@ -445,7 +445,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;
}
@ -463,7 +463,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;
@ -482,7 +482,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),
@ -492,7 +492,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,
@ -510,7 +510,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;
}
@ -568,7 +568,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;
}
@ -824,7 +824,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) {
@ -1001,20 +1001,24 @@ 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);
}
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);
}
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);
}
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);
}
}
@ -1083,7 +1087,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,
@ -1159,7 +1163,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);
@ -1188,7 +1192,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::*;
@ -1347,7 +1351,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 {
@ -1366,7 +1370,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;
}
@ -1625,7 +1629,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;

View File

@ -246,7 +246,13 @@ 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;
}
@ -298,7 +304,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
cx: &LateContext<'_, '_>,
fk: FnKind<'_>,
_: &hir::FnDecl,
_: &hir::Body,
_: &hir::Body<'_>,
_: Span,
id: hir::HirId,
) {
@ -325,13 +331,13 @@ 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);
}
}
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 {
@ -349,7 +355,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);
@ -386,7 +392,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);
@ -398,13 +404,13 @@ 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);
}
}
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);
}

View File

@ -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 {
@ -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);

View File

@ -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,
@ -33,6 +33,6 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
});
}
fn visit_trait_item(&mut self, _it: &'tcx hir::TraitItem) {}
fn visit_impl_item(&mut self, _it: &'tcx hir::ImplItem) {}
fn visit_trait_item(&mut self, _it: &'tcx hir::TraitItem<'tcx>) {}
fn visit_impl_item(&mut self, _it: &'tcx hir::ImplItem<'tcx>) {}
}

View File

@ -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,
@ -45,8 +45,8 @@ impl<'tcx> ItemLikeVisitor<'tcx> for Collector {
}
}
fn visit_trait_item(&mut self, _it: &'tcx hir::TraitItem) {}
fn visit_impl_item(&mut self, _it: &'tcx hir::ImplItem) {}
fn visit_trait_item(&mut self, _it: &'tcx hir::TraitItem<'tcx>) {}
fn visit_impl_item(&mut self, _it: &'tcx hir::ImplItem<'tcx>) {}
}
impl Collector {

View File

@ -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,
@ -129,8 +129,8 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
}
}
fn visit_trait_item(&mut self, _it: &'tcx hir::TraitItem) {}
fn visit_impl_item(&mut self, _it: &'tcx hir::ImplItem) {}
fn visit_trait_item(&mut self, _it: &'tcx hir::TraitItem<'tcx>) {}
fn visit_impl_item(&mut self, _it: &'tcx hir::ImplItem<'tcx>) {}
}
impl Collector<'tcx> {

View File

@ -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);
}
}
@ -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,
) {
@ -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);
@ -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);
@ -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);
@ -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);
@ -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] <- &macro_def.attrs);
record!(self.per_def.attributes[def_id] <- macro_def.attrs);
self.encode_stability(def_id);
self.encode_deprecation(def_id);
}
@ -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);
@ -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 {
@ -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);
@ -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);
}
}
@ -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) {
@ -1725,9 +1725,9 @@ 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) {
fn visit_impl_item(&mut self, _impl_item: &'v hir::ImplItem<'v>) {
// handled in `visit_item` above
}
}

View File

@ -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<Item=ArgInfo<'tcx>>

View File

@ -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(&param.pat, "function argument", None);
self.check_patterns(false, &param.pat);
}

View File

@ -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(..) |
@ -1059,12 +1059,12 @@ 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.
}
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);
@ -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<MonoItem<'tcx>>,
) {
match item.kind {

View File

@ -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,

View File

@ -75,7 +75,7 @@ enum ConstKind {
}
impl ConstKind {
fn for_body(body: &hir::Body, hir_map: &Map<'_>) -> Option<Self> {
fn for_body(body: &hir::Body<'_>, hir_map: &Map<'_>) -> Option<Self> {
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));
}

View File

@ -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;
@ -355,14 +355,14 @@ fn has_allow_dead_code_or_lang_attr(
// * Implementation of a trait method
struct LifeSeeder<'k, 'tcx> {
worklist: Vec<hir::HirId>,
krate: &'k hir::Crate,
krate: &'k hir::Crate<'k>,
tcx: TyCtxt<'tcx>,
// see `MarkSymbolVisitor::struct_constructors`
struct_constructors: FxHashMap<hir::HirId, hir::HirId>,
}
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);
@ -375,13 +375,13 @@ 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);
}
}
}
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() ||
@ -417,11 +417,11 @@ 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
}
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
}
}
@ -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<hir::HirId>, FxHashMap<hir::HirId, hir::HirId>) {
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<hir::HirId> {
let (worklist, struct_constructors) = create_and_seed_worklist(tcx, access_levels, krate);
let mut symbol_visitor = MarkSymbolVisitor {
@ -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(..)
@ -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)
@ -503,14 +503,14 @@ 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,
&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)
}
@ -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 {
@ -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) {
@ -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");
@ -629,14 +629,14 @@ 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");
}
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) {
@ -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)) => {

View File

@ -33,18 +33,18 @@ 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);
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.
}
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.
}
}
@ -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() {

View File

@ -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<Id>,
}
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(),
@ -123,17 +123,17 @@ 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)
}
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)
}
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)
}
@ -188,12 +188,12 @@ 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)
}
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)
}
@ -203,13 +203,13 @@ 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)
}
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);
@ -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)
}

View File

@ -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 {
@ -40,12 +40,12 @@ impl ItemLikeVisitor<'tcx> for VarianceTest<'tcx> {
}
}
fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem) {}
fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem) {}
fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem<'tcx>) {}
fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem<'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);

View File

@ -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);

View File

@ -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));
@ -22,10 +22,10 @@ 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) {
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) {
}
}

View File

@ -510,7 +510,7 @@ impl EmbargoVisitor<'tcx> {
fn update_macro_reachable_mod(&mut self, reachable_mod: hir::HirId, defining_mod: DefId) {
let module_def_id = self.tcx.hir().local_def_id(reachable_mod);
let module = self.tcx.hir().get_module(module_def_id).0;
for item_id in &module.item_ids {
for item_id in module.item_ids {
let hir_id = item_id.id;
let item_def_id = self.tcx.hir().local_def_id(hir_id);
if let Some(def_kind) = self.tcx.def_kind(item_def_id) {
@ -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::<AccessLevel>::of_impl(item.hir_id, self.tcx, &self.access_levels),
@ -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);
@ -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);
}
@ -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);
}
@ -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();
@ -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() {
@ -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)
@ -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() {
@ -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
@ -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`
}
@ -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));
@ -1013,14 +1013,14 @@ 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);
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);
@ -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`
}
@ -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);
@ -1295,14 +1295,14 @@ 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);
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);
@ -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]
@ -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)
}
@ -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) {
@ -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);
}
@ -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 {
@ -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();
}
@ -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();
}
@ -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 {

View File

@ -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,

View File

@ -669,22 +669,22 @@ 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);
}
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);
}
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);
}
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);
}

View File

@ -63,7 +63,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expr: &hir::Expr,
opt_kind: Option<ty::ClosureKind>,
decl: &'tcx hir::FnDecl,
body: &'tcx hir::Body,
body: &'tcx hir::Body<'tcx>,
gen: Option<hir::Movability>,
expected_sig: Option<ExpectedSig<'tcx>>,
) -> 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<ExpectedSig<'tcx>>,
) -> 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()

View File

@ -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)

View File

@ -1002,7 +1002,7 @@ fn compute_all_traits(tcx: TyCtxt<'_>) -> Vec<DefId> {
}
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(..) => {
@ -1013,9 +1013,9 @@ fn compute_all_traits(tcx: TyCtxt<'_>) -> Vec<DefId> {
}
}
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) {}
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) {}
}
tcx.hir().krate().visit_all_item_likes(&mut Visitor {
@ -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<Span>, bool) {
let mut finder = UsePlacementFinder {
@ -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(..) => {
@ -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());
}

View File

@ -751,11 +751,11 @@ 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) { }
fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem) { }
fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem<'tcx>) { }
fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem<'tcx>) { }
}
pub fn check_wf_new(tcx: TyCtxt<'_>) {
@ -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<hir::Movability>,
) -> (FnCtxt<'a, 'tcx>, Option<GeneratorTypes<'tcx>>) {
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(&param.pat, param_ty, None);
@ -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,
@ -1766,15 +1766,15 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item) {
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 {
@ -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);
@ -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,
@ -2444,7 +2444,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], 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
@ -2481,12 +2486,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));
@ -4708,7 +4713,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::<Vec<_>>()
.join(", "),
Some(Node::TraitItem(hir::TraitItem {
kind: hir::TraitItemKind::Method(.., hir::TraitMethod::Required(idents)),
..

View File

@ -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

View File

@ -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,
) {

View File

@ -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<hir::TraitRef>,
) {
@ -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,19 +1081,19 @@ 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);
}
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);
}
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);
@ -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<AdtVariant<'tcx>> {
fn enum_variants(&self, enum_def: &hir::EnumDef<'_>) -> Vec<AdtVariant<'tcx>> {
enum_def.variants.iter()
.map(|variant| self.non_enum_variant(&variant.data))
.collect()

View File

@ -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 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 +43,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 +104,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 +112,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 +267,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 +700,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,

View File

@ -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;
}
@ -38,10 +38,10 @@ 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) {
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) {
}
}
@ -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(
@ -231,9 +231,9 @@ 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) {
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) {
}
}

View File

@ -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
@ -254,15 +254,15 @@ 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) {
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) {
}
}
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

View File

@ -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(..) |
@ -98,9 +98,9 @@ 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) {
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'v>) {
}
}

View File

@ -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 {
@ -218,9 +218,9 @@ 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) {
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) {
}
}

View File

@ -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,15 +72,15 @@ 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);
}
}
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) {
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) {
}
}

View File

@ -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);
}
@ -145,12 +145,12 @@ 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);
}
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);
}
@ -426,7 +426,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);
@ -538,7 +538,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();
@ -593,7 +593,7 @@ fn convert_variant(
ctor_did: Option<DefId>,
ident: Ident,
discr: ty::VariantDiscr,
def: &hir::VariantData,
def: &hir::VariantData<'_>,
adt_kind: ty::AdtKind,
parent_did: DefId,
) -> ty::VariantDef {
@ -1702,7 +1702,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.
@ -1711,7 +1711,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.
@ -1720,7 +1720,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);
@ -2061,8 +2061,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 {
@ -2107,12 +2105,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 {

View File

@ -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(&param.pat));
debug!("consume_body: param_ty = {:?}", param_ty);

View File

@ -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,
@ -89,9 +89,9 @@ 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) { }
fn visit_impl_item(&mut self, _impl_item: &'tcx hir::ImplItem<'tcx>) { }
}
fn enforce_impl_params_are_constrained(

View File

@ -19,8 +19,8 @@ impl From<ty::AssocKind> 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,

View File

@ -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);
@ -113,9 +113,9 @@ 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) {}
fn visit_impl_item(&mut self, _impl_item: &'tcx hir::ImplItem<'tcx>) {}
}
fn insert_required_predicates_to_be_wf<'tcx>(

View File

@ -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"
@ -33,6 +33,6 @@ impl ItemLikeVisitor<'tcx> for OutlivesTest<'tcx> {
}
}
fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem) {}
fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem) {}
fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem<'tcx>) {}
fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem<'tcx>) {}
}

View File

@ -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, _) => {
@ -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());
}
@ -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);
}
@ -104,13 +104,13 @@ 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);
}
}
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);
}

View File

@ -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));
@ -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());
}
@ -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);
}
@ -167,13 +167,13 @@ 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);
}
}
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);
}

View File

@ -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"
@ -29,6 +29,6 @@ impl ItemLikeVisitor<'tcx> for VarianceTest<'tcx> {
}
}
fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem) { }
fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem) { }
fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem<'tcx>) { }
fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem<'tcx>) { }
}

View File

@ -70,6 +70,12 @@ impl<T: Clean<U>, U, V: Idx> Clean<IndexVec<V, U>> for IndexVec<V, T> {
}
}
impl<T: Clean<U>, U> Clean<U> for &T {
fn clean(&self, cx: &DocContext<'_>) -> U {
(**self).clean(cx)
}
}
impl<T: Clean<U>, U> Clean<U> for P<T> {
fn clean(&self, cx: &DocContext<'_>) -> U {
(**self).clean(cx)
@ -1081,7 +1087,7 @@ impl Clean<PolyTrait> for hir::PolyTraitRef {
}
}
impl Clean<Item> for hir::TraitItem {
impl Clean<Item> for hir::TraitItem<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Item {
let inner = match self.kind {
hir::TraitItemKind::Const(ref ty, default) => {
@ -1122,7 +1128,7 @@ impl Clean<Item> for hir::TraitItem {
}
}
impl Clean<Item> for hir::ImplItem {
impl Clean<Item> for hir::ImplItem<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Item {
let inner = match self.kind {
hir::ImplItemKind::Const(ref ty, expr) => {
@ -1738,7 +1744,7 @@ impl<'tcx> Clean<Constant> for ty::Const<'tcx> {
}
}
impl Clean<Item> for hir::StructField {
impl Clean<Item> for hir::StructField<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Item {
let local_did = cx.tcx.hir().local_def_id(self.hir_id);
@ -1831,7 +1837,7 @@ impl Clean<Item> for doctree::Union<'_> {
}
}
impl Clean<VariantStruct> for ::rustc::hir::VariantData {
impl Clean<VariantStruct> for ::rustc::hir::VariantData<'_> {
fn clean(&self, cx: &DocContext<'_>) -> VariantStruct {
VariantStruct {
struct_type: doctree::struct_type_from_def(self),
@ -1918,7 +1924,7 @@ impl Clean<Item> for ty::VariantDef {
}
}
impl Clean<VariantKind> for hir::VariantData {
impl Clean<VariantKind> for hir::VariantData<'_> {
fn clean(&self, cx: &DocContext<'_>) -> VariantKind {
match self {
hir::VariantData::Struct(..) => VariantKind::Struct(self.clean(cx)),
@ -2387,12 +2393,6 @@ impl Clean<Stability> for attr::Stability {
}
}
impl<'a> Clean<Stability> for &'a attr::Stability {
fn clean(&self, dc: &DocContext<'_>) -> Stability {
(**self).clean(dc)
}
}
impl Clean<Deprecation> for attr::Deprecation {
fn clean(&self, _: &DocContext<'_>) -> Deprecation {
Deprecation {

View File

@ -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<Name>,
@ -90,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,
}
@ -101,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,
}
@ -119,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,
}
@ -136,7 +135,7 @@ pub struct Function<'hir> {
}
pub struct Typedef<'hir> {
pub ty: &'hir P<hir::Ty>,
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<hir::Ty>,
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<hir::Ty>,
pub type_: &'hir hir::Ty,
pub expr: hir::BodyId,
pub name: Name,
pub attrs: &'hir [ast::Attribute],
@ -180,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],
@ -206,8 +205,8 @@ pub struct Impl<'hir> {
pub defaultness: hir::Defaultness,
pub generics: &'hir hir::Generics,
pub trait_: &'hir Option<hir::TraitRef>,
pub for_: &'hir P<hir::Ty>,
pub items: Vec<&'hir hir::ImplItem>,
pub for_: &'hir hir::Ty,
pub items: Vec<&'hir hir::ImplItem<'hir>>,
pub attrs: &'hir [ast::Attribute],
pub whence: Span,
pub vis: &'hir hir::Visibility,
@ -218,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,
}

View File

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