Auto merge of #66942 - cjgillot:hirene-ty, r=Zoxc

Allocate HIR on an arena 3/4 -- Ty

This is the third PR in the series started by #66931 and #66936

Once again, commits don't really make sense on their own.
They are mostly split by type of compile error.

The additional diff is here: https://github.com/cjgillot/rust/compare/hirene-expr...hirene-ty
This commit is contained in:
bors 2019-12-29 22:51:02 +00:00
commit 2ba0d2acbd
56 changed files with 965 additions and 916 deletions

View file

@ -128,26 +128,34 @@ macro_rules! arena_types {
[] arm: rustc::hir::Arm<$tcx>,
[] attribute: syntax::ast::Attribute,
[] block: rustc::hir::Block<$tcx>,
[] bare_fn_ty: rustc::hir::BareFnTy<$tcx>,
[few] global_asm: rustc::hir::GlobalAsm,
[] generic_arg: rustc::hir::GenericArg<$tcx>,
[] generic_args: rustc::hir::GenericArgs<$tcx>,
[] generic_bound: rustc::hir::GenericBound<$tcx>,
[] generic_param: rustc::hir::GenericParam<$tcx>,
[] expr: rustc::hir::Expr<$tcx>,
[] field: rustc::hir::Field<$tcx>,
[] field_pat: rustc::hir::FieldPat<$tcx>,
[] fn_decl: rustc::hir::FnDecl,
[] fn_decl: rustc::hir::FnDecl<$tcx>,
[] foreign_item: rustc::hir::ForeignItem<$tcx>,
[] impl_item_ref: rustc::hir::ImplItemRef,
[] impl_item_ref: rustc::hir::ImplItemRef<$tcx>,
[] inline_asm: rustc::hir::InlineAsm<$tcx>,
[] local: rustc::hir::Local<$tcx>,
[few] macro_def: rustc::hir::MacroDef<$tcx>,
[] param: rustc::hir::Param<$tcx>,
[] pat: rustc::hir::Pat<$tcx>,
[] path: rustc::hir::Path,
[] path_segment: rustc::hir::PathSegment,
[] qpath: rustc::hir::QPath,
[] path: rustc::hir::Path<$tcx>,
[] path_segment: rustc::hir::PathSegment<$tcx>,
[] poly_trait_ref: rustc::hir::PolyTraitRef<$tcx>,
[] qpath: rustc::hir::QPath<$tcx>,
[] stmt: rustc::hir::Stmt<$tcx>,
[] struct_field: rustc::hir::StructField<$tcx>,
[] trait_item_ref: rustc::hir::TraitItemRef,
[] ty: rustc::hir::Ty,
[] ty: rustc::hir::Ty<$tcx>,
[] type_binding: rustc::hir::TypeBinding<$tcx>,
[] variant: rustc::hir::Variant<$tcx>,
[] where_predicate: rustc::hir::WherePredicate<$tcx>,
], $tcx);
)
}

View file

@ -42,10 +42,10 @@ use syntax_pos::Span;
#[derive(Copy, Clone)]
pub enum FnKind<'a> {
/// `#[xxx] pub async/const/extern "Abi" fn foo()`
ItemFn(Ident, &'a Generics, FnHeader, &'a Visibility, &'a [Attribute]),
ItemFn(Ident, &'a Generics<'a>, FnHeader, &'a Visibility<'a>, &'a [Attribute]),
/// `fn foo(&self)`
Method(Ident, &'a FnSig, Option<&'a Visibility>, &'a [Attribute]),
Method(Ident, &'a FnSig<'a>, Option<&'a Visibility<'a>>, &'a [Attribute]),
/// `|x, y| {}`
Closure(&'a [Attribute]),
@ -274,25 +274,25 @@ pub trait Visitor<'v>: Sized {
fn visit_expr(&mut self, ex: &'v Expr<'v>) {
walk_expr(self, ex)
}
fn visit_ty(&mut self, t: &'v Ty) {
fn visit_ty(&mut self, t: &'v Ty<'v>) {
walk_ty(self, t)
}
fn visit_generic_param(&mut self, p: &'v GenericParam) {
fn visit_generic_param(&mut self, p: &'v GenericParam<'v>) {
walk_generic_param(self, p)
}
fn visit_generics(&mut self, g: &'v Generics) {
fn visit_generics(&mut self, g: &'v Generics<'v>) {
walk_generics(self, g)
}
fn visit_where_predicate(&mut self, predicate: &'v WherePredicate) {
fn visit_where_predicate(&mut self, predicate: &'v WherePredicate<'v>) {
walk_where_predicate(self, predicate)
}
fn visit_fn_decl(&mut self, fd: &'v FnDecl) {
fn visit_fn_decl(&mut self, fd: &'v FnDecl<'v>) {
walk_fn_decl(self, fd)
}
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl, b: BodyId, s: Span, id: HirId) {
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl<'v>, b: BodyId, s: Span, id: HirId) {
walk_fn(self, fk, fd, b, s, id)
}
fn visit_use(&mut self, path: &'v Path, hir_id: HirId) {
fn visit_use(&mut self, path: &'v Path<'v>, hir_id: HirId) {
walk_use(self, path, hir_id)
}
fn visit_trait_item(&mut self, ti: &'v TraitItem<'v>) {
@ -304,23 +304,23 @@ pub trait Visitor<'v>: Sized {
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) {
fn visit_impl_item_ref(&mut self, ii: &'v ImplItemRef<'v>) {
walk_impl_item_ref(self, ii)
}
fn visit_trait_ref(&mut self, t: &'v TraitRef) {
fn visit_trait_ref(&mut self, t: &'v TraitRef<'v>) {
walk_trait_ref(self, t)
}
fn visit_param_bound(&mut self, bounds: &'v GenericBound) {
fn visit_param_bound(&mut self, bounds: &'v GenericBound<'v>) {
walk_param_bound(self, bounds)
}
fn visit_poly_trait_ref(&mut self, t: &'v PolyTraitRef, m: TraitBoundModifier) {
fn visit_poly_trait_ref(&mut self, t: &'v PolyTraitRef<'v>, m: TraitBoundModifier) {
walk_poly_trait_ref(self, t, m)
}
fn visit_variant_data(
&mut self,
s: &'v VariantData<'v>,
_: Name,
_: &'v Generics,
_: &'v Generics<'v>,
_parent_id: HirId,
_: Span,
) {
@ -332,19 +332,19 @@ pub trait Visitor<'v>: Sized {
fn visit_enum_def(
&mut self,
enum_definition: &'v EnumDef<'v>,
generics: &'v Generics,
generics: &'v Generics<'v>,
item_id: HirId,
_: Span,
) {
walk_enum_def(self, enum_definition, generics, item_id)
}
fn visit_variant(&mut self, v: &'v Variant<'v>, g: &'v Generics, item_id: HirId) {
fn visit_variant(&mut self, v: &'v Variant<'v>, g: &'v Generics<'v>, item_id: HirId) {
walk_variant(self, v, g, item_id)
}
fn visit_label(&mut self, label: &'v Label) {
walk_label(self, label)
}
fn visit_generic_arg(&mut self, generic_arg: &'v GenericArg) {
fn visit_generic_arg(&mut self, generic_arg: &'v GenericArg<'v>) {
match generic_arg {
GenericArg::Lifetime(lt) => self.visit_lifetime(lt),
GenericArg::Type(ty) => self.visit_ty(ty),
@ -354,26 +354,26 @@ pub trait Visitor<'v>: Sized {
fn visit_lifetime(&mut self, lifetime: &'v Lifetime) {
walk_lifetime(self, lifetime)
}
fn visit_qpath(&mut self, qpath: &'v QPath, id: HirId, span: Span) {
fn visit_qpath(&mut self, qpath: &'v QPath<'v>, id: HirId, span: Span) {
walk_qpath(self, qpath, id, span)
}
fn visit_path(&mut self, path: &'v Path, _id: HirId) {
fn visit_path(&mut self, path: &'v Path<'v>, _id: HirId) {
walk_path(self, path)
}
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v PathSegment) {
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v PathSegment<'v>) {
walk_path_segment(self, path_span, path_segment)
}
fn visit_generic_args(&mut self, path_span: Span, generic_args: &'v GenericArgs) {
fn visit_generic_args(&mut self, path_span: Span, generic_args: &'v GenericArgs<'v>) {
walk_generic_args(self, path_span, generic_args)
}
fn visit_assoc_type_binding(&mut self, type_binding: &'v TypeBinding) {
fn visit_assoc_type_binding(&mut self, type_binding: &'v TypeBinding<'v>) {
walk_assoc_type_binding(self, type_binding)
}
fn visit_attribute(&mut self, _attr: &'v Attribute) {}
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) {
fn visit_vis(&mut self, vis: &'v Visibility<'v>) {
walk_vis(self, vis)
}
fn visit_associated_item_kind(&mut self, kind: &'v AssocItemKind) {
@ -445,16 +445,16 @@ pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime
pub fn walk_poly_trait_ref<'v, V>(
visitor: &mut V,
trait_ref: &'v PolyTraitRef,
trait_ref: &'v PolyTraitRef<'v>,
_modifier: TraitBoundModifier,
) where
V: Visitor<'v>,
{
walk_list!(visitor, visit_generic_param, &trait_ref.bound_generic_params);
walk_list!(visitor, visit_generic_param, trait_ref.bound_generic_params);
visitor.visit_trait_ref(&trait_ref.trait_ref);
}
pub fn walk_trait_ref<'v, V>(visitor: &mut V, trait_ref: &'v TraitRef)
pub fn walk_trait_ref<'v, V>(visitor: &mut V, trait_ref: &'v TraitRef<'v>)
where
V: Visitor<'v>,
{
@ -509,7 +509,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
visitor.visit_ty(ty);
visitor.visit_generics(generics)
}
ItemKind::OpaqueTy(OpaqueTy { ref generics, ref bounds, .. }) => {
ItemKind::OpaqueTy(OpaqueTy { ref generics, bounds, .. }) => {
visitor.visit_id(item.hir_id);
walk_generics(visitor, generics);
walk_list!(visitor, visit_param_bound, bounds);
@ -538,13 +538,13 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
item.span,
);
}
ItemKind::Trait(.., ref generics, ref bounds, trait_item_refs) => {
ItemKind::Trait(.., ref generics, bounds, trait_item_refs) => {
visitor.visit_id(item.hir_id);
visitor.visit_generics(generics);
walk_list!(visitor, visit_param_bound, bounds);
walk_list!(visitor, visit_trait_item_ref, trait_item_refs);
}
ItemKind::TraitAlias(ref generics, ref bounds) => {
ItemKind::TraitAlias(ref generics, bounds) => {
visitor.visit_id(item.hir_id);
visitor.visit_generics(generics);
walk_list!(visitor, visit_param_bound, bounds);
@ -553,7 +553,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
walk_list!(visitor, visit_attribute, item.attrs);
}
pub fn walk_use<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path, hir_id: HirId) {
pub fn walk_use<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path<'v>, hir_id: HirId) {
visitor.visit_id(hir_id);
visitor.visit_path(path, hir_id);
}
@ -561,7 +561,7 @@ pub fn walk_use<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path, hir_id: Hir
pub fn walk_enum_def<'v, V: Visitor<'v>>(
visitor: &mut V,
enum_definition: &'v EnumDef<'v>,
generics: &'v Generics,
generics: &'v Generics<'v>,
item_id: HirId,
) {
visitor.visit_id(item_id);
@ -571,7 +571,7 @@ pub fn walk_enum_def<'v, V: Visitor<'v>>(
pub fn walk_variant<'v, V: Visitor<'v>>(
visitor: &mut V,
variant: &'v Variant<'v>,
generics: &'v Generics,
generics: &'v Generics<'v>,
parent_item_id: HirId,
) {
visitor.visit_ident(variant.ident);
@ -587,7 +587,7 @@ pub fn walk_variant<'v, V: Visitor<'v>>(
walk_list!(visitor, visit_attribute, variant.attrs);
}
pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) {
visitor.visit_id(typ.hir_id);
match typ.kind {
@ -598,17 +598,17 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
visitor.visit_ty(&mutable_type.ty)
}
TyKind::Never => {}
TyKind::Tup(ref tuple_element_types) => {
TyKind::Tup(tuple_element_types) => {
walk_list!(visitor, visit_ty, tuple_element_types);
}
TyKind::BareFn(ref function_declaration) => {
walk_list!(visitor, visit_generic_param, &function_declaration.generic_params);
walk_list!(visitor, visit_generic_param, function_declaration.generic_params);
visitor.visit_fn_decl(&function_declaration.decl);
}
TyKind::Path(ref qpath) => {
visitor.visit_qpath(qpath, typ.hir_id, typ.span);
}
TyKind::Def(item_id, ref lifetimes) => {
TyKind::Def(item_id, lifetimes) => {
visitor.visit_nested_item(item_id);
walk_list!(visitor, visit_generic_arg, lifetimes);
}
@ -616,7 +616,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
visitor.visit_ty(ty);
visitor.visit_anon_const(length)
}
TyKind::TraitObject(ref bounds, ref lifetime) => {
TyKind::TraitObject(bounds, ref lifetime) => {
for bound in bounds {
visitor.visit_poly_trait_ref(bound, TraitBoundModifier::None);
}
@ -627,7 +627,12 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
}
}
pub fn walk_qpath<'v, V: Visitor<'v>>(visitor: &mut V, qpath: &'v QPath, id: HirId, span: Span) {
pub fn walk_qpath<'v, V: Visitor<'v>>(
visitor: &mut V,
qpath: &'v QPath<'v>,
id: HirId,
span: Span,
) {
match *qpath {
QPath::Resolved(ref maybe_qself, ref path) => {
if let Some(ref qself) = *maybe_qself {
@ -642,8 +647,8 @@ pub fn walk_qpath<'v, V: Visitor<'v>>(visitor: &mut V, qpath: &'v QPath, id: Hir
}
}
pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) {
for segment in &path.segments {
pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path<'v>) {
for segment in path.segments {
visitor.visit_path_segment(path.span, segment);
}
}
@ -651,7 +656,7 @@ pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) {
pub fn walk_path_segment<'v, V: Visitor<'v>>(
visitor: &mut V,
path_span: Span,
segment: &'v PathSegment,
segment: &'v PathSegment<'v>,
) {
visitor.visit_ident(segment.ident);
if let Some(id) = segment.hir_id {
@ -665,20 +670,23 @@ pub fn walk_path_segment<'v, V: Visitor<'v>>(
pub fn walk_generic_args<'v, V: Visitor<'v>>(
visitor: &mut V,
_path_span: Span,
generic_args: &'v GenericArgs,
generic_args: &'v GenericArgs<'v>,
) {
walk_list!(visitor, visit_generic_arg, &generic_args.args);
walk_list!(visitor, visit_assoc_type_binding, &generic_args.bindings);
walk_list!(visitor, visit_assoc_type_binding, generic_args.bindings);
}
pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(visitor: &mut V, type_binding: &'v TypeBinding) {
pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(
visitor: &mut V,
type_binding: &'v TypeBinding<'v>,
) {
visitor.visit_id(type_binding.hir_id);
visitor.visit_ident(type_binding.ident);
match type_binding.kind {
TypeBindingKind::Equality { ref ty } => {
visitor.visit_ty(ty);
}
TypeBindingKind::Constraint { ref bounds } => {
TypeBindingKind::Constraint { bounds } => {
walk_list!(visitor, visit_param_bound, bounds);
}
}
@ -747,7 +755,7 @@ pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v
walk_list!(visitor, visit_attribute, foreign_item.attrs);
}
pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v GenericBound) {
pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v GenericBound<'v>) {
match *bound {
GenericBound::Trait(ref typ, modifier) => {
visitor.visit_poly_trait_ref(typ, modifier);
@ -756,9 +764,9 @@ pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v GenericB
}
}
pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v GenericParam) {
pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v GenericParam<'v>) {
visitor.visit_id(param.hir_id);
walk_list!(visitor, visit_attribute, &param.attrs);
walk_list!(visitor, visit_attribute, param.attrs);
match param.name {
ParamName::Plain(ident) => visitor.visit_ident(ident),
ParamName::Error | ParamName::Fresh(_) => {}
@ -768,29 +776,30 @@ pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Generi
GenericParamKind::Type { ref default, .. } => walk_list!(visitor, visit_ty, default),
GenericParamKind::Const { ref ty } => visitor.visit_ty(ty),
}
walk_list!(visitor, visit_param_bound, &param.bounds);
walk_list!(visitor, visit_param_bound, param.bounds);
}
pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics) {
pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics<'v>) {
walk_list!(visitor, visit_generic_param, &generics.params);
walk_list!(visitor, visit_where_predicate, &generics.where_clause.predicates);
walk_list!(visitor, visit_where_predicate, generics.where_clause.predicates);
}
pub fn walk_where_predicate<'v, V: Visitor<'v>>(visitor: &mut V, predicate: &'v WherePredicate) {
pub fn walk_where_predicate<'v, V: Visitor<'v>>(
visitor: &mut V,
predicate: &'v WherePredicate<'v>,
) {
match predicate {
&WherePredicate::BoundPredicate(WhereBoundPredicate {
ref bounded_ty,
ref bounds,
ref bound_generic_params,
bounds,
bound_generic_params,
..
}) => {
visitor.visit_ty(bounded_ty);
walk_list!(visitor, visit_param_bound, bounds);
walk_list!(visitor, visit_generic_param, bound_generic_params);
}
&WherePredicate::RegionPredicate(WhereRegionPredicate {
ref lifetime, ref bounds, ..
}) => {
&WherePredicate::RegionPredicate(WhereRegionPredicate { ref lifetime, bounds, .. }) => {
visitor.visit_lifetime(lifetime);
walk_list!(visitor, visit_param_bound, bounds);
}
@ -804,14 +813,14 @@ pub fn walk_where_predicate<'v, V: Visitor<'v>>(visitor: &mut V, predicate: &'v
}
}
pub fn walk_fn_ret_ty<'v, V: Visitor<'v>>(visitor: &mut V, ret_ty: &'v FunctionRetTy) {
pub fn walk_fn_ret_ty<'v, V: Visitor<'v>>(visitor: &mut V, ret_ty: &'v FunctionRetTy<'v>) {
if let Return(ref output_ty) = *ret_ty {
visitor.visit_ty(output_ty)
}
}
pub fn walk_fn_decl<'v, V: Visitor<'v>>(visitor: &mut V, function_declaration: &'v FnDecl) {
for ty in &function_declaration.inputs {
pub fn walk_fn_decl<'v, V: Visitor<'v>>(visitor: &mut V, function_declaration: &'v FnDecl<'v>) {
for ty in function_declaration.inputs {
visitor.visit_ty(ty)
}
walk_fn_ret_ty(visitor, &function_declaration.output)
@ -829,7 +838,7 @@ pub fn walk_fn_kind<'v, V: Visitor<'v>>(visitor: &mut V, function_kind: FnKind<'
pub fn walk_fn<'v, V: Visitor<'v>>(
visitor: &mut V,
function_kind: FnKind<'v>,
function_declaration: &'v FnDecl,
function_declaration: &'v FnDecl<'v>,
body_id: BodyId,
_span: Span,
id: HirId,
@ -850,7 +859,7 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
visitor.visit_ty(ty);
walk_list!(visitor, visit_nested_body, default);
}
TraitItemKind::Method(ref sig, TraitMethod::Required(ref param_names)) => {
TraitItemKind::Method(ref sig, TraitMethod::Required(param_names)) => {
visitor.visit_id(trait_item.hir_id);
visitor.visit_fn_decl(&sig.decl);
for &param_name in param_names {
@ -866,7 +875,7 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
trait_item.hir_id,
);
}
TraitItemKind::Type(ref bounds, ref default) => {
TraitItemKind::Type(bounds, ref default) => {
visitor.visit_id(trait_item.hir_id);
walk_list!(visitor, visit_param_bound, bounds);
walk_list!(visitor, visit_ty, default);
@ -920,14 +929,14 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
visitor.visit_id(impl_item.hir_id);
visitor.visit_ty(ty);
}
ImplItemKind::OpaqueTy(ref bounds) => {
ImplItemKind::OpaqueTy(bounds) => {
visitor.visit_id(impl_item.hir_id);
walk_list!(visitor, visit_param_bound, bounds);
}
}
}
pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, impl_item_ref: &'v ImplItemRef) {
pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, impl_item_ref: &'v ImplItemRef<'v>) {
// N.B., deliberately force a compilation error if/when new fields are added.
let ImplItemRef { id, ident, ref kind, span: _, ref vis, ref defaultness } = *impl_item_ref;
visitor.visit_nested_impl_item(id);
@ -1099,7 +1108,7 @@ pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm<'v>) {
walk_list!(visitor, visit_attribute, arm.attrs);
}
pub fn walk_vis<'v, V: Visitor<'v>>(visitor: &mut V, vis: &'v Visibility) {
pub fn walk_vis<'v, V: Visitor<'v>>(visitor: &mut V, vis: &'v Visibility<'v>) {
if let VisibilityKind::Restricted { ref path, hir_id } = vis.node {
visitor.visit_id(hir_id);
visitor.visit_path(path, hir_id)

View file

@ -46,6 +46,7 @@ use crate::lint::builtin::{self, ELIDED_LIFETIMES_IN_PATHS};
use crate::middle::cstore::CrateStore;
use crate::session::config::nightly_options;
use crate::session::Session;
use crate::util::captures::Captures;
use crate::util::common::FN_OUTPUT_NAME;
use crate::util::nodemap::{DefIdMap, NodeMap};
use errors::Applicability;
@ -207,13 +208,13 @@ type NtToTokenstream = fn(&Nonterminal, &ParseSess, Span) -> TokenStream;
/// Context of `impl Trait` in code, which determines whether it is allowed in an HIR subtree,
/// and if so, what meaning it has.
#[derive(Debug)]
enum ImplTraitContext<'a> {
enum ImplTraitContext<'b, 'a> {
/// Treat `impl Trait` as shorthand for a new universal generic parameter.
/// Example: `fn foo(x: impl Debug)`, where `impl Debug` is conceptually
/// equivalent to a fresh universal parameter like `fn foo<T: Debug>(x: T)`.
///
/// Newly generated parameters should be inserted into the given `Vec`.
Universal(&'a mut Vec<hir::GenericParam>),
Universal(&'b mut Vec<hir::GenericParam<'a>>),
/// Treat `impl Trait` as shorthand for a new opaque type.
/// Example: `fn foo() -> impl Debug`, where `impl Debug` is conceptually
@ -238,13 +239,13 @@ enum ImplTraitPosition {
Other,
}
impl<'a> ImplTraitContext<'a> {
impl<'b, 'a> ImplTraitContext<'b, 'a> {
#[inline]
fn disallowed() -> Self {
ImplTraitContext::Disallowed(ImplTraitPosition::Other)
}
fn reborrow(&'b mut self) -> ImplTraitContext<'b> {
fn reborrow(&'c mut self) -> ImplTraitContext<'c, 'a> {
use self::ImplTraitContext::*;
match self {
Universal(params) => Universal(params),
@ -741,9 +742,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
parent_id: DefId,
anonymous_lifetime_mode: AnonymousLifetimeMode,
f: F,
) -> (Vec<hir::GenericParam>, T)
) -> (Vec<hir::GenericParam<'hir>>, T)
where
F: FnOnce(&mut LoweringContext<'_, '_>) -> (Vec<hir::GenericParam>, T),
F: FnOnce(&mut Self) -> (Vec<hir::GenericParam<'hir>>, T),
{
assert!(!self.is_collecting_in_band_lifetimes);
assert!(self.lifetimes_to_define.is_empty());
@ -774,7 +775,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
span: Span,
hir_name: ParamName,
parent_index: DefIndex,
) -> hir::GenericParam {
) -> hir::GenericParam<'hir> {
let node_id = self.resolver.next_node_id();
// Get the name we'll use to make the def-path. Note
@ -798,8 +799,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::GenericParam {
hir_id: self.lower_node_id(node_id),
name: hir_name,
attrs: hir_vec![],
bounds: hir_vec![],
attrs: &[],
bounds: &[],
span,
pure_wrt_drop: false,
kind: hir::GenericParamKind::Lifetime { kind },
@ -849,7 +850,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// for them.
fn with_in_scope_lifetime_defs<T, F>(&mut self, params: &[GenericParam], f: F) -> T
where
F: FnOnce(&mut LoweringContext<'_, 'hir>) -> T,
F: FnOnce(&mut Self) -> T,
{
let old_len = self.in_scope_lifetimes.len();
let lt_def_names = params.iter().filter_map(|param| match param.kind {
@ -876,9 +877,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
parent_id: DefId,
anonymous_lifetime_mode: AnonymousLifetimeMode,
f: F,
) -> (hir::Generics, T)
) -> (hir::Generics<'hir>, T)
where
F: FnOnce(&mut LoweringContext<'_, '_>, &mut Vec<hir::GenericParam>) -> T,
F: FnOnce(&mut Self, &mut Vec<hir::GenericParam<'hir>>) -> T,
{
let (in_band_defs, (mut lowered_generics, res)) =
self.with_in_scope_lifetime_defs(&generics.params, |this| {
@ -918,7 +919,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn with_dyn_type_scope<T, F>(&mut self, in_scope: bool, f: F) -> T
where
F: FnOnce(&mut LoweringContext<'_, '_>) -> T,
F: FnOnce(&mut Self) -> T,
{
let was_in_dyn_type = self.is_in_dyn_type;
self.is_in_dyn_type = in_scope;
@ -1027,8 +1028,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_assoc_ty_constraint(
&mut self,
constraint: &AssocTyConstraint,
itctx: ImplTraitContext<'_>,
) -> hir::TypeBinding {
itctx: ImplTraitContext<'_, 'hir>,
) -> hir::TypeBinding<'hir> {
debug!("lower_assoc_ty_constraint(constraint={:?}, itctx={:?})", constraint, itctx);
let kind = match constraint.kind {
@ -1124,8 +1125,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_generic_arg(
&mut self,
arg: &ast::GenericArg,
itctx: ImplTraitContext<'_>,
) -> hir::GenericArg {
itctx: ImplTraitContext<'_, 'hir>,
) -> hir::GenericArg<'hir> {
match arg {
ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(&lt)),
ast::GenericArg::Type(ty) => {
@ -1180,8 +1181,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
}
fn lower_ty(&mut self, t: &Ty, itctx: ImplTraitContext<'_>) -> P<hir::Ty> {
P(self.lower_ty_direct(t, itctx))
fn lower_ty(&mut self, t: &Ty, itctx: ImplTraitContext<'_, 'hir>) -> &'hir hir::Ty<'hir> {
self.arena.alloc(self.lower_ty_direct(t, itctx))
}
fn lower_path_ty(
@ -1190,8 +1191,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
qself: &Option<QSelf>,
path: &Path,
param_mode: ParamMode,
itctx: ImplTraitContext<'_>,
) -> hir::Ty {
itctx: ImplTraitContext<'_, 'hir>,
) -> hir::Ty<'hir> {
let id = self.lower_node_id(t.id);
let qpath = self.lower_qpath(t.id, qself, path, param_mode, itctx);
let ty = self.ty_path(id, t.span, qpath);
@ -1201,15 +1202,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
ty
}
fn ty(&mut self, span: Span, kind: hir::TyKind) -> hir::Ty {
fn ty(&mut self, span: Span, kind: hir::TyKind<'hir>) -> hir::Ty<'hir> {
hir::Ty { hir_id: self.next_id(), kind, span }
}
fn ty_tup(&mut self, span: Span, tys: HirVec<hir::Ty>) -> hir::Ty {
fn ty_tup(&mut self, span: Span, tys: &'hir [hir::Ty<'hir>]) -> hir::Ty<'hir> {
self.ty(span, hir::TyKind::Tup(tys))
}
fn lower_ty_direct(&mut self, t: &Ty, mut itctx: ImplTraitContext<'_>) -> hir::Ty {
fn lower_ty_direct(&mut self, t: &Ty, mut itctx: ImplTraitContext<'_, 'hir>) -> hir::Ty<'hir> {
let kind = match t.kind {
TyKind::Infer => hir::TyKind::Infer,
TyKind::Err => hir::TyKind::Err,
@ -1225,23 +1226,32 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
TyKind::BareFn(ref f) => self.with_in_scope_lifetime_defs(&f.generic_params, |this| {
this.with_anonymous_lifetime_mode(AnonymousLifetimeMode::PassThrough, |this| {
hir::TyKind::BareFn(P(hir::BareFnTy {
generic_params: this.lower_generic_params(
&f.generic_params,
&NodeMap::default(),
ImplTraitContext::disallowed(),
),
unsafety: f.unsafety,
abi: this.lower_extern(f.ext),
decl: this.lower_fn_decl(&f.decl, None, false, None),
param_names: this.lower_fn_params_to_names(&f.decl),
}))
hir::TyKind::BareFn(
this.arena.alloc(hir::BareFnTy {
generic_params: this.arena.alloc_from_iter(
this.lower_generic_params(
&f.generic_params,
&NodeMap::default(),
ImplTraitContext::disallowed(),
)
.into_iter(),
),
unsafety: f.unsafety,
abi: this.lower_extern(f.ext),
decl: this.lower_fn_decl(&f.decl, None, false, None),
param_names: this.arena.alloc_from_iter(
this.lower_fn_params_to_names(&f.decl).into_iter(),
),
}),
)
})
}),
TyKind::Never => hir::TyKind::Never,
TyKind::Tup(ref tys) => hir::TyKind::Tup(
tys.iter().map(|ty| self.lower_ty_direct(ty, itctx.reborrow())).collect(),
),
TyKind::Tup(ref tys) => {
hir::TyKind::Tup(self.arena.alloc_from_iter(
tys.iter().map(|ty| self.lower_ty_direct(ty, itctx.reborrow())),
))
}
TyKind::Paren(ref ty) => {
return self.lower_ty_direct(ty, itctx);
}
@ -1253,11 +1263,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let res = self.lower_res(res);
hir::TyKind::Path(hir::QPath::Resolved(
None,
P(hir::Path {
self.arena.alloc(hir::Path {
res,
segments: hir_vec![hir::PathSegment::from_ident(Ident::with_dummy_span(
kw::SelfUpper
))],
segments: arena_vec![self; hir::PathSegment::from_ident(
Ident::with_dummy_span(kw::SelfUpper)
)],
span: t.span,
}),
))
@ -1269,21 +1279,21 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
TyKind::TraitObject(ref bounds, kind) => {
let mut lifetime_bound = None;
let (bounds, lifetime_bound) = self.with_dyn_type_scope(true, |this| {
let bounds = bounds
.iter()
.filter_map(|bound| match *bound {
GenericBound::Trait(ref ty, TraitBoundModifier::None) => {
Some(this.lower_poly_trait_ref(ty, itctx.reborrow()))
}
GenericBound::Trait(_, TraitBoundModifier::Maybe) => None,
GenericBound::Outlives(ref lifetime) => {
if lifetime_bound.is_none() {
lifetime_bound = Some(this.lower_lifetime(lifetime));
let bounds =
this.arena.alloc_from_iter(bounds.iter().filter_map(
|bound| match *bound {
GenericBound::Trait(ref ty, TraitBoundModifier::None) => {
Some(this.lower_poly_trait_ref(ty, itctx.reborrow()))
}
None
}
})
.collect();
GenericBound::Trait(_, TraitBoundModifier::Maybe) => None,
GenericBound::Outlives(ref lifetime) => {
if lifetime_bound.is_none() {
lifetime_bound = Some(this.lower_lifetime(lifetime));
}
None
}
},
));
let lifetime_bound =
lifetime_bound.unwrap_or_else(|| this.elided_dyn_bound(t.span));
(bounds, lifetime_bound)
@ -1316,7 +1326,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir_id: self.lower_node_id(def_node_id),
name: ParamName::Plain(ident),
pure_wrt_drop: false,
attrs: hir_vec![],
attrs: &[],
bounds: hir_bounds,
span,
kind: hir::GenericParamKind::Type {
@ -1327,10 +1337,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::TyKind::Path(hir::QPath::Resolved(
None,
P(hir::Path {
self.arena.alloc(hir::Path {
span,
res: Res::Def(DefKind::TyParam, DefId::local(def_index)),
segments: hir_vec![hir::PathSegment::from_ident(ident)],
segments: arena_vec![self; hir::PathSegment::from_ident(ident)],
}),
))
}
@ -1378,8 +1388,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
span: Span,
fn_def_id: Option<DefId>,
opaque_ty_node_id: NodeId,
lower_bounds: impl FnOnce(&mut LoweringContext<'_, '_>) -> hir::GenericBounds,
) -> hir::TyKind {
lower_bounds: impl FnOnce(&mut Self) -> hir::GenericBounds<'hir>,
) -> hir::TyKind<'hir> {
debug!(
"lower_opaque_impl_trait(fn_def_id={:?}, opaque_ty_node_id={:?}, span={:?})",
fn_def_id, opaque_ty_node_id, span,
@ -1413,7 +1423,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let opaque_ty_item = hir::OpaqueTy {
generics: hir::Generics {
params: lifetime_defs,
where_clause: hir::WhereClause { predicates: hir_vec![], span },
where_clause: hir::WhereClause { predicates: &[], span },
span,
},
bounds: hir_bounds,
@ -1435,7 +1445,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn generate_opaque_type(
&mut self,
opaque_ty_node_id: NodeId,
opaque_ty_item: hir::OpaqueTy,
opaque_ty_item: hir::OpaqueTy<'hir>,
span: Span,
opaque_ty_span: Span,
) -> hir::HirId {
@ -1463,8 +1473,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
&mut self,
opaque_ty_id: NodeId,
parent_index: DefIndex,
bounds: &hir::GenericBounds,
) -> (HirVec<hir::GenericArg>, HirVec<hir::GenericParam>) {
bounds: hir::GenericBounds<'hir>,
) -> (&'hir [hir::GenericArg<'hir>], HirVec<hir::GenericParam<'hir>>) {
debug!(
"lifetimes_from_impl_trait_bounds(opaque_ty_id={:?}, \
parent_index={:?}, \
@ -1482,8 +1492,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
collect_elided_lifetimes: bool,
currently_bound_lifetimes: Vec<hir::LifetimeName>,
already_defined_lifetimes: FxHashSet<hir::LifetimeName>,
output_lifetimes: Vec<hir::GenericArg>,
output_lifetime_params: Vec<hir::GenericParam>,
output_lifetimes: Vec<hir::GenericArg<'hir>>,
output_lifetime_params: Vec<hir::GenericParam<'hir>>,
}
impl<'r, 'a, 'v, 'hir> hir::intravisit::Visitor<'v> for ImplTraitLifetimeCollector<'r, 'a, 'hir> {
@ -1493,7 +1503,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::intravisit::NestedVisitorMap::None
}
fn visit_generic_args(&mut self, span: Span, parameters: &'v hir::GenericArgs) {
fn visit_generic_args(&mut self, span: Span, parameters: &'v hir::GenericArgs<'v>) {
// Don't collect elided lifetimes used inside of `Fn()` syntax.
if parameters.parenthesized {
let old_collect_elided_lifetimes = self.collect_elided_lifetimes;
@ -1505,7 +1515,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
}
fn visit_ty(&mut self, t: &'v hir::Ty) {
fn visit_ty(&mut self, t: &'v hir::Ty<'v>) {
// Don't collect elided lifetimes used inside of `fn()` syntax.
if let hir::TyKind::BareFn(_) = t.kind {
let old_collect_elided_lifetimes = self.collect_elided_lifetimes;
@ -1525,7 +1535,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn visit_poly_trait_ref(
&mut self,
trait_ref: &'v hir::PolyTraitRef,
trait_ref: &'v hir::PolyTraitRef<'v>,
modifier: hir::TraitBoundModifier,
) {
// Record the "stack height" of `for<'a>` lifetime bindings
@ -1535,7 +1545,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.currently_bound_lifetimes.truncate(old_len);
}
fn visit_generic_param(&mut self, param: &'v hir::GenericParam) {
fn visit_generic_param(&mut self, param: &'v hir::GenericParam<'v>) {
// Record the introduction of 'a in `for<'a> ...`.
if let hir::GenericParamKind::Lifetime { .. } = param.kind {
// Introduce lifetimes one at a time so that we can handle
@ -1605,8 +1615,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
name,
span: lifetime.span,
pure_wrt_drop: false,
attrs: hir_vec![],
bounds: hir_vec![],
attrs: &[],
bounds: &[],
kind: hir::GenericParamKind::Lifetime { kind },
});
}
@ -1628,10 +1638,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::intravisit::walk_param_bound(&mut lifetime_collector, &bound);
}
(
lifetime_collector.output_lifetimes.into(),
lifetime_collector.output_lifetime_params.into(),
)
let ImplTraitLifetimeCollector { output_lifetimes, output_lifetime_params, .. } =
lifetime_collector;
(self.arena.alloc_from_iter(output_lifetimes), output_lifetime_params.into())
}
fn lower_qpath(
@ -1640,8 +1650,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
qself: &Option<QSelf>,
p: &Path,
param_mode: ParamMode,
mut itctx: ImplTraitContext<'_>,
) -> hir::QPath {
mut itctx: ImplTraitContext<'_, 'hir>,
) -> hir::QPath<'hir> {
let qself_position = qself.as_ref().map(|q| q.position);
let qself = qself.as_ref().map(|q| self.lower_ty(&q.ty, itctx.reborrow()));
@ -1649,12 +1659,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.resolver.get_partial_res(id).unwrap_or_else(|| PartialRes::new(Res::Err));
let proj_start = p.segments.len() - partial_res.unresolved_segments();
let path = P(hir::Path {
let path = self.arena.alloc(hir::Path {
res: self.lower_res(partial_res.base_res()),
segments: p.segments[..proj_start]
.iter()
.enumerate()
.map(|(i, segment)| {
segments: self.arena.alloc_from_iter(p.segments[..proj_start].iter().enumerate().map(
|(i, segment)| {
let param_mode = match (qself_position, param_mode) {
(Some(j), ParamMode::Optional) if i < j => {
// This segment is part of the trait path in a
@ -1730,8 +1738,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
itctx.reborrow(),
None,
)
})
.collect(),
},
)),
span: p.span,
});
@ -1751,7 +1759,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// e.g., `Vec` in `Vec::new` or `<I as Iterator>::Item` in
// `<I as Iterator>::Item::default`.
let new_id = self.next_id();
P(self.ty_path(new_id, p.span, hir::QPath::Resolved(qself, path)))
self.arena.alloc(self.ty_path(new_id, p.span, hir::QPath::Resolved(qself, path)))
};
// Anything after the base path are associated "extensions",
@ -1765,7 +1773,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// 3. `<<std::vec::Vec<T>>::IntoIter>::Item`
// * final path is `<<<std::vec::Vec<T>>::IntoIter>::Item>::clone`
for (i, segment) in p.segments.iter().enumerate().skip(proj_start) {
let segment = P(self.lower_path_segment(
let segment = self.arena.alloc(self.lower_path_segment(
p.span,
segment,
param_mode,
@ -1783,7 +1791,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// Wrap the associated extension in another type node.
let new_id = self.next_id();
ty = P(self.ty_path(new_id, p.span, qpath));
ty = self.arena.alloc(self.ty_path(new_id, p.span, qpath));
}
// We should've returned in the for loop above.
@ -1801,29 +1809,25 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
p: &Path,
param_mode: ParamMode,
explicit_owner: Option<NodeId>,
) -> hir::Path {
) -> hir::Path<'hir> {
hir::Path {
res,
segments: p
.segments
.iter()
.map(|segment| {
self.lower_path_segment(
p.span,
segment,
param_mode,
0,
ParenthesizedGenericArgs::Err,
ImplTraitContext::disallowed(),
explicit_owner,
)
})
.collect(),
segments: self.arena.alloc_from_iter(p.segments.iter().map(|segment| {
self.lower_path_segment(
p.span,
segment,
param_mode,
0,
ParenthesizedGenericArgs::Err,
ImplTraitContext::disallowed(),
explicit_owner,
)
})),
span: p.span,
}
}
fn lower_path(&mut self, id: NodeId, p: &Path, param_mode: ParamMode) -> hir::Path {
fn lower_path(&mut self, id: NodeId, p: &Path, param_mode: ParamMode) -> hir::Path<'hir> {
let res = self.expect_full_res(id);
let res = self.lower_res(res);
self.lower_path_extra(res, p, param_mode, None)
@ -1836,9 +1840,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
param_mode: ParamMode,
expected_lifetimes: usize,
parenthesized_generic_args: ParenthesizedGenericArgs,
itctx: ImplTraitContext<'_>,
itctx: ImplTraitContext<'_, 'hir>,
explicit_owner: Option<NodeId>,
) -> hir::PathSegment {
) -> hir::PathSegment<'hir> {
let (mut generic_args, infer_args) = if let Some(ref generic_args) = segment.args {
let msg = "parenthesized type parameters may only be used with a `Fn` trait";
match **generic_args {
@ -1969,21 +1973,21 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
segment.ident, segment.id, id,
);
hir::PathSegment::new(
segment.ident,
Some(id),
Some(self.lower_res(res)),
generic_args,
hir::PathSegment {
ident: segment.ident,
hir_id: Some(id),
res: Some(self.lower_res(res)),
infer_args,
)
args: if generic_args.is_empty() { None } else { Some(self.arena.alloc(generic_args)) },
}
}
fn lower_angle_bracketed_parameter_data(
&mut self,
data: &AngleBracketedArgs,
param_mode: ParamMode,
mut itctx: ImplTraitContext<'_>,
) -> (hir::GenericArgs, bool) {
mut itctx: ImplTraitContext<'_, 'hir>,
) -> (hir::GenericArgs<'hir>, bool) {
let &AngleBracketedArgs { ref args, ref constraints, .. } = data;
let has_non_lt_args = args.iter().any(|arg| match arg {
ast::GenericArg::Lifetime(_) => false,
@ -1993,10 +1997,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
(
hir::GenericArgs {
args: args.iter().map(|a| self.lower_generic_arg(a, itctx.reborrow())).collect(),
bindings: constraints
.iter()
.map(|b| self.lower_assoc_ty_constraint(b, itctx.reborrow()))
.collect(),
bindings: self.arena.alloc_from_iter(
constraints.iter().map(|b| self.lower_assoc_ty_constraint(b, itctx.reborrow())),
),
parenthesized: false,
},
!has_non_lt_args && param_mode == ParamMode::Optional,
@ -2006,7 +2009,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_parenthesized_parameter_data(
&mut self,
data: &ParenthesizedArgs,
) -> (hir::GenericArgs, bool) {
) -> (hir::GenericArgs<'hir>, bool) {
// Switch to `PassThrough` mode for anonymous lifetimes; this
// means that we permit things like `&Ref<T>`, where `Ref` has
// a hidden lifetime parameter. This is needed for backwards
@ -2014,13 +2017,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// we generally don't permit such things (see #51008).
self.with_anonymous_lifetime_mode(AnonymousLifetimeMode::PassThrough, |this| {
let &ParenthesizedArgs { ref inputs, ref output, span } = data;
let inputs = inputs
.iter()
.map(|ty| this.lower_ty_direct(ty, ImplTraitContext::disallowed()))
.collect();
let inputs = this.arena.alloc_from_iter(
inputs.iter().map(|ty| this.lower_ty_direct(ty, ImplTraitContext::disallowed())),
);
let output_ty = match output {
FunctionRetTy::Ty(ty) => this.lower_ty(&ty, ImplTraitContext::disallowed()),
FunctionRetTy::Default(_) => P(this.ty_tup(span, hir::HirVec::new())),
FunctionRetTy::Default(_) => this.arena.alloc(this.ty_tup(span, &[])),
};
let args = hir_vec![GenericArg::Type(this.ty_tup(span, inputs))];
let binding = hir::TypeBinding {
@ -2029,7 +2031,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
span: output_ty.span,
kind: hir::TypeBindingKind::Equality { ty: output_ty },
};
(hir::GenericArgs { args, bindings: hir_vec![binding], parenthesized: true }, false)
(
hir::GenericArgs { args, bindings: arena_vec![this; binding], parenthesized: true },
false,
)
})
}
@ -2052,7 +2057,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
},
)
});
let ty = ty.map(|ty| &*self.arena.alloc(ty.into_inner()));
let init = l.init.as_ref().map(|e| self.lower_expr(e));
(
hir::Local {
@ -2100,10 +2104,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_fn_decl(
&mut self,
decl: &FnDecl,
mut in_band_ty_params: Option<(DefId, &mut Vec<hir::GenericParam>)>,
mut in_band_ty_params: Option<(DefId, &mut Vec<hir::GenericParam<'hir>>)>,
impl_trait_return_allow: bool,
make_ret_async: Option<NodeId>,
) -> P<hir::FnDecl> {
) -> &'hir hir::FnDecl<'hir> {
debug!(
"lower_fn_decl(\
fn_decl: {:?}, \
@ -2133,16 +2137,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
if c_variadic {
inputs = &inputs[..inputs.len() - 1];
}
inputs
.iter()
.map(|param| {
if let Some((_, ibty)) = &mut in_band_ty_params {
this.lower_ty_direct(&param.ty, ImplTraitContext::Universal(ibty))
} else {
this.lower_ty_direct(&param.ty, ImplTraitContext::disallowed())
}
})
.collect::<HirVec<_>>()
this.arena.alloc_from_iter(inputs.iter().map(|param| {
if let Some((_, ibty)) = &mut in_band_ty_params {
this.lower_ty_direct(&param.ty, ImplTraitContext::Universal(ibty))
} else {
this.lower_ty_direct(&param.ty, ImplTraitContext::disallowed())
}
}))
});
let output = if let Some(ret_id) = make_ret_async {
@ -2163,7 +2164,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
};
P(hir::FnDecl {
self.arena.alloc(hir::FnDecl {
inputs,
output,
c_variadic,
@ -2209,7 +2210,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
output: &FunctionRetTy,
fn_def_id: DefId,
opaque_ty_node_id: NodeId,
) -> hir::FunctionRetTy {
) -> hir::FunctionRetTy<'hir> {
debug!(
"lower_async_fn_ret_ty(\
output={:?}, \
@ -2311,19 +2312,18 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let generic_params = lifetime_params
.iter()
.cloned()
.map(|(span, hir_name)| {
this.lifetime_to_generic_param(span, hir_name, opaque_ty_def_index)
this.lifetime_to_generic_param(*span, *hir_name, opaque_ty_def_index)
})
.collect();
let opaque_ty_item = hir::OpaqueTy {
generics: hir::Generics {
params: generic_params,
where_clause: hir::WhereClause { predicates: hir_vec![], span },
where_clause: hir::WhereClause { predicates: &[], span },
span,
},
bounds: hir_vec![future_bound],
bounds: arena_vec![this; future_bound],
impl_trait_fn: Some(fn_def_id),
origin: hir::OpaqueTyOrigin::AsyncFn,
};
@ -2362,22 +2362,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
})
})
.collect();
generic_args.extend(lifetime_params[input_lifetimes_count..].iter().map(|&(span, _)| {
generic_args.extend(lifetime_params[input_lifetimes_count..].iter().map(|&(span, _)|
// Output lifetime like `'_`.
GenericArg::Lifetime(hir::Lifetime {
hir_id: self.next_id(),
span,
name: hir::LifetimeName::Implicit,
})
}));
})));
let generic_args = self.arena.alloc_from_iter(generic_args);
// Create the `Foo<...>` reference itself. Note that the `type
// Foo = impl Trait` is, internally, created as a child of the
// async fn, so the *type parameters* are inherited. It's
// only the lifetime parameters that we must supply.
let opaque_ty_ref = hir::TyKind::Def(hir::ItemId { id: opaque_ty_id }, generic_args.into());
let opaque_ty_ref = hir::TyKind::Def(hir::ItemId { id: opaque_ty_id }, generic_args);
let opaque_ty = self.ty(opaque_ty_span, opaque_ty_ref);
hir::FunctionRetTy::Return(P(opaque_ty))
hir::FunctionRetTy::Return(self.arena.alloc(opaque_ty))
}
/// Transforms `-> T` into `Future<Output = T>`
@ -2386,17 +2386,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
output: &FunctionRetTy,
fn_def_id: DefId,
span: Span,
) -> hir::GenericBound {
) -> hir::GenericBound<'hir> {
// Compute the `T` in `Future<Output = T>` from the return type.
let output_ty = match output {
FunctionRetTy::Ty(ty) => self.lower_ty(ty, ImplTraitContext::OpaqueTy(Some(fn_def_id))),
FunctionRetTy::Default(ret_ty_span) => P(self.ty_tup(*ret_ty_span, hir_vec![])),
FunctionRetTy::Default(ret_ty_span) => self.arena.alloc(self.ty_tup(*ret_ty_span, &[])),
};
// "<Output = T>"
let future_params = P(hir::GenericArgs {
args: hir_vec![],
bindings: hir_vec![hir::TypeBinding {
let future_params = self.arena.alloc(hir::GenericArgs {
args: HirVec::new(),
bindings: arena_vec![self; hir::TypeBinding {
ident: Ident::with_dummy_span(FN_OUTPUT_NAME),
kind: hir::TypeBindingKind::Equality { ty: output_ty },
hir_id: self.next_id(),
@ -2406,13 +2406,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
});
// ::std::future::Future<future_params>
let future_path =
P(self.std_path(span, &[sym::future, sym::Future], Some(future_params), false));
let future_path = self.arena.alloc(self.std_path(
span,
&[sym::future, sym::Future],
Some(future_params),
false,
));
hir::GenericBound::Trait(
hir::PolyTraitRef {
trait_ref: hir::TraitRef { path: future_path, hir_ref_id: self.next_id() },
bound_generic_params: hir_vec![],
bound_generic_params: &[],
span,
},
hir::TraitBoundModifier::None,
@ -2422,8 +2426,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_param_bound(
&mut self,
tpb: &GenericBound,
itctx: ImplTraitContext<'_>,
) -> hir::GenericBound {
itctx: ImplTraitContext<'_, 'hir>,
) -> hir::GenericBound<'hir> {
match *tpb {
GenericBound::Trait(ref ty, modifier) => hir::GenericBound::Trait(
self.lower_poly_trait_ref(ty, itctx),
@ -2474,8 +2478,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
&mut self,
params: &[GenericParam],
add_bounds: &NodeMap<Vec<GenericBound>>,
mut itctx: ImplTraitContext<'_>,
) -> hir::HirVec<hir::GenericParam> {
mut itctx: ImplTraitContext<'_, 'hir>,
) -> HirVec<hir::GenericParam<'hir>> {
params
.iter()
.map(|param| self.lower_generic_param(param, add_bounds, itctx.reborrow()))
@ -2486,11 +2490,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
&mut self,
param: &GenericParam,
add_bounds: &NodeMap<Vec<GenericBound>>,
mut itctx: ImplTraitContext<'_>,
) -> hir::GenericParam {
let mut bounds = self
mut itctx: ImplTraitContext<'_, 'hir>,
) -> hir::GenericParam<'hir> {
let mut bounds: Vec<_> = self
.with_anonymous_lifetime_mode(AnonymousLifetimeMode::ReportError, |this| {
this.lower_param_bounds(&param.bounds, itctx.reborrow())
this.lower_param_bounds_mut(&param.bounds, itctx.reborrow()).collect()
});
let (name, kind) = match param.kind {
@ -2526,8 +2530,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
GenericParamKind::Type { ref default, .. } => {
let add_bounds = add_bounds.get(&param.id).map_or(&[][..], |x| &x);
if !add_bounds.is_empty() {
let params = self.lower_param_bounds(add_bounds, itctx.reborrow()).into_iter();
bounds = bounds.into_iter().chain(params).collect();
let params = self.lower_param_bounds_mut(add_bounds, itctx.reborrow());
bounds.extend(params);
}
let kind = hir::GenericParamKind::Type {
@ -2557,13 +2561,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
name,
span: param.ident.span,
pure_wrt_drop: attr::contains_name(&param.attrs, sym::may_dangle),
attrs: self.lower_attrs(&param.attrs),
bounds,
attrs: self.lower_attrs_arena(&param.attrs),
bounds: self.arena.alloc_from_iter(bounds),
kind,
}
}
fn lower_trait_ref(&mut self, p: &TraitRef, itctx: ImplTraitContext<'_>) -> hir::TraitRef {
fn lower_trait_ref(
&mut self,
p: &TraitRef,
itctx: ImplTraitContext<'_, 'hir>,
) -> hir::TraitRef<'hir> {
let path = match self.lower_qpath(p.ref_id, &None, &p.path, ParamMode::Explicit, itctx) {
hir::QPath::Resolved(None, path) => path,
qpath => bug!("lower_trait_ref: unexpected QPath `{:?}`", qpath),
@ -2574,8 +2582,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_poly_trait_ref(
&mut self,
p: &PolyTraitRef,
mut itctx: ImplTraitContext<'_>,
) -> hir::PolyTraitRef {
mut itctx: ImplTraitContext<'_, 'hir>,
) -> hir::PolyTraitRef<'hir> {
let bound_generic_params = self.lower_generic_params(
&p.bound_generic_params,
&NodeMap::default(),
@ -2585,19 +2593,31 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
this.lower_trait_ref(&p.trait_ref, itctx)
});
hir::PolyTraitRef { bound_generic_params, trait_ref, span: p.span }
hir::PolyTraitRef {
bound_generic_params: self.arena.alloc_from_iter(bound_generic_params.into_iter()),
trait_ref,
span: p.span,
}
}
fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext<'_>) -> hir::MutTy {
fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext<'_, 'hir>) -> hir::MutTy<'hir> {
hir::MutTy { ty: self.lower_ty(&mt.ty, itctx), mutbl: mt.mutbl }
}
fn lower_param_bounds(
&mut self,
bounds: &[GenericBound],
mut itctx: ImplTraitContext<'_>,
) -> hir::GenericBounds {
bounds.iter().map(|bound| self.lower_param_bound(bound, itctx.reborrow())).collect()
itctx: ImplTraitContext<'_, 'hir>,
) -> hir::GenericBounds<'hir> {
self.arena.alloc_from_iter(self.lower_param_bounds_mut(bounds, itctx))
}
fn lower_param_bounds_mut<'s>(
&'s mut self,
bounds: &'s [GenericBound],
mut itctx: ImplTraitContext<'s, 'hir>,
) -> impl Iterator<Item = hir::GenericBound<'hir>> + Captures<'s> + Captures<'a> {
bounds.iter().map(move |bound| self.lower_param_bound(bound, itctx.reborrow()))
}
fn lower_block(&mut self, b: &Block, targeted_by_break: bool) -> &'hir hir::Block<'hir> {
@ -2834,10 +2854,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
Some(res) => hir::PatKind::Path(hir::QPath::Resolved(
None,
P(hir::Path {
self.arena.alloc(hir::Path {
span: ident.span,
res: self.lower_res(res),
segments: hir_vec![hir::PathSegment::from_ident(ident)],
segments: arena_vec![self; hir::PathSegment::from_ident(ident)],
}),
)),
}
@ -3033,7 +3053,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
subpats: &'hir [&'hir hir::Pat<'hir>],
) -> &'hir hir::Pat<'hir> {
let path = self.std_path(span, components, None, true);
let qpath = hir::QPath::Resolved(None, P(path));
let qpath = hir::QPath::Resolved(None, self.arena.alloc(path));
let pt = if subpats.is_empty() {
hir::PatKind::Path(qpath)
} else {
@ -3079,9 +3099,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
&mut self,
span: Span,
components: &[Symbol],
params: Option<P<hir::GenericArgs>>,
params: Option<&'hir hir::GenericArgs<'hir>>,
is_value: bool,
) -> hir::Path {
) -> hir::Path<'hir> {
let ns = if is_value { Namespace::ValueNS } else { Namespace::TypeNS };
let (path, res) = self.resolver.resolve_str_path(span, self.crate_root, components, ns);
@ -3104,18 +3124,23 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::Path {
span,
res: res.map_id(|_| panic!("unexpected `NodeId`")),
segments: segments.into(),
segments: self.arena.alloc_from_iter(segments),
}
}
fn ty_path(&mut self, mut hir_id: hir::HirId, span: Span, qpath: hir::QPath) -> hir::Ty {
fn ty_path(
&mut self,
mut hir_id: hir::HirId,
span: Span,
qpath: hir::QPath<'hir>,
) -> hir::Ty<'hir> {
let kind = match qpath {
hir::QPath::Resolved(None, path) => {
// Turn trait object paths into `TyKind::TraitObject` instead.
match path.res {
Res::Def(DefKind::Trait, _) | Res::Def(DefKind::TraitAlias, _) => {
let principal = hir::PolyTraitRef {
bound_generic_params: hir::HirVec::new(),
bound_generic_params: &[],
trait_ref: hir::TraitRef { path, hir_ref_id: hir_id },
span,
};
@ -3123,7 +3148,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// The original ID is taken by the `PolyTraitRef`,
// so the `Ty` itself needs a different one.
hir_id = self.next_id();
hir::TyKind::TraitObject(hir_vec![principal], self.elided_dyn_bound(span))
hir::TyKind::TraitObject(
arena_vec![self; principal],
self.elided_dyn_bound(span),
)
}
_ => hir::TyKind::Path(hir::QPath::Resolved(None, path)),
}

View file

@ -1,7 +1,6 @@
use super::{ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs};
use crate::hir;
use crate::hir::def::Res;
use crate::hir::ptr::P;
use rustc_data_structures::thin_vec::ThinVec;
@ -64,12 +63,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
ExprKind::Cast(ref expr, ref ty) => {
let expr = self.lower_expr(expr);
let ty = self.lower_ty(ty, ImplTraitContext::disallowed());
hir::ExprKind::Cast(expr, self.arena.alloc(ty.into_inner()))
hir::ExprKind::Cast(expr, ty)
}
ExprKind::Type(ref expr, ref ty) => {
let expr = self.lower_expr(expr);
let ty = self.lower_ty(ty, ImplTraitContext::disallowed());
hir::ExprKind::Type(expr, self.arena.alloc(ty.into_inner()))
hir::ExprKind::Type(expr, ty)
}
ExprKind::AddrOf(k, m, ref ohs) => {
let ohs = self.lower_expr(ohs);
@ -490,9 +489,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
None => FunctionRetTy::Default(span),
};
let ast_decl = FnDecl { inputs: vec![], output };
let decl = self.arena.alloc(
self.lower_fn_decl(&ast_decl, None, /* impl trait allowed */ false, None).into_inner(),
);
let decl = self.lower_fn_decl(&ast_decl, None, /* impl trait allowed */ false, None);
let body_id = self.lower_fn_body(&ast_decl, |this| {
this.generator_kind = Some(hir::GeneratorKind::Async(async_gen_kind));
body(this)
@ -686,7 +683,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
) -> hir::ExprKind<'hir> {
// Lower outside new scope to preserve `is_in_loop_condition`.
let fn_decl = self.lower_fn_decl(decl, None, false, None);
let fn_decl = self.arena.alloc(fn_decl.into_inner());
self.with_new_scopes(move |this| {
let prev = this.current_item;
@ -749,7 +745,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
// have to conserve the state of being inside a loop condition for the
// closure argument types.
let fn_decl = self.lower_fn_decl(&outer_decl, None, false, None);
let fn_decl = self.arena.alloc(fn_decl.into_inner());
self.with_new_scopes(move |this| {
// FIXME(cramertj): allow `async` non-`move` closures with arguments.
@ -832,7 +827,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let is_unit = fields.is_empty();
let struct_path = [sym::ops, path];
let struct_path = self.std_path(span, &struct_path, None, is_unit);
let struct_path = hir::QPath::Resolved(None, P(struct_path));
let struct_path = hir::QPath::Resolved(None, self.arena.alloc(struct_path));
if is_unit {
hir::ExprKind::Path(struct_path)
@ -1341,9 +1336,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
assoc_fn_name: &str,
args: &'hir [hir::Expr<'hir>],
) -> hir::ExprKind<'hir> {
let ty_path = P(self.std_path(span, ty_path_components, None, false));
let ty = P(self.ty_path(ty_path_id, span, hir::QPath::Resolved(None, ty_path)));
let fn_seg = P(hir::PathSegment::from_ident(Ident::from_str(assoc_fn_name)));
let ty_path = self.arena.alloc(self.std_path(span, ty_path_components, None, false));
let ty =
self.arena.alloc(self.ty_path(ty_path_id, span, hir::QPath::Resolved(None, ty_path)));
let fn_seg = self.arena.alloc(hir::PathSegment::from_ident(Ident::from_str(assoc_fn_name)));
let fn_path = hir::QPath::TypeRelative(ty, fn_seg);
let fn_expr =
self.arena.alloc(self.expr(span, hir::ExprKind::Path(fn_path), ThinVec::new()));
@ -1354,11 +1350,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
&mut self,
span: Span,
components: &[Symbol],
params: Option<P<hir::GenericArgs>>,
params: Option<&'hir hir::GenericArgs<'hir>>,
attrs: AttrVec,
) -> hir::Expr<'hir> {
let path = self.std_path(span, components, params, true);
self.expr(span, hir::ExprKind::Path(hir::QPath::Resolved(None, P(path))), attrs)
self.expr(
span,
hir::ExprKind::Path(hir::QPath::Resolved(None, self.arena.alloc(path))),
attrs,
)
}
pub(super) fn expr_ident(
@ -1388,10 +1388,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
) -> hir::Expr<'hir> {
let expr_path = hir::ExprKind::Path(hir::QPath::Resolved(
None,
P(hir::Path {
self.arena.alloc(hir::Path {
span,
res: Res::Local(binding),
segments: hir_vec![hir::PathSegment::from_ident(ident)],
segments: arena_vec![self; hir::PathSegment::from_ident(ident)],
}),
));

View file

@ -8,7 +8,6 @@ use super::ParamMode;
use crate::hir;
use crate::hir::def::{DefKind, Res};
use crate::hir::def_id::DefId;
use crate::hir::ptr::P;
use crate::util::nodemap::NodeMap;
use rustc_target::spec::abi;
@ -258,7 +257,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
id: NodeId,
ident: &mut Ident,
attrs: &'hir [Attribute],
vis: &mut hir::Visibility,
vis: &mut hir::Visibility<'hir>,
i: &ItemKind,
) -> hir::ItemKind<'hir> {
match *i {
@ -278,11 +277,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
ImplTraitContext::Disallowed(ImplTraitPosition::Binding)
},
);
hir::ItemKind::Static(
self.arena.alloc(ty.into_inner()),
m,
self.lower_const_body(span, Some(e)),
)
hir::ItemKind::Static(ty, m, self.lower_const_body(span, Some(e)))
}
ItemKind::Const(ref t, ref e) => {
let ty = self.lower_ty(
@ -293,10 +288,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
ImplTraitContext::Disallowed(ImplTraitPosition::Binding)
},
);
hir::ItemKind::Const(
self.arena.alloc(ty.into_inner()),
self.lower_const_body(span, Some(e)),
)
hir::ItemKind::Const(ty, self.lower_const_body(span, Some(e)))
}
ItemKind::Fn(FnSig { ref decl, header }, ref generics, ref body) => {
let fn_def_id = self.resolver.definitions().local_def_id(id);
@ -334,7 +326,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
None => {
let ty = self.lower_ty(ty, ImplTraitContext::disallowed());
let generics = self.lower_generics(generics, ImplTraitContext::disallowed());
hir::ItemKind::TyAlias(self.arena.alloc(ty.into_inner()), generics)
hir::ItemKind::TyAlias(ty, generics)
}
Some(bounds) => {
let ty = hir::OpaqueTy {
@ -430,7 +422,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.lower_defaultness(defaultness, true /* [1] */),
generics,
trait_ref,
self.arena.alloc(lowered_ty.into_inner()),
lowered_ty,
new_impl_items,
)
}
@ -465,7 +457,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
tree: &UseTree,
prefix: &Path,
id: NodeId,
vis: &mut hir::Visibility,
vis: &mut hir::Visibility<'hir>,
ident: &mut Ident,
attrs: &'hir [Attribute],
) -> hir::ItemKind<'hir> {
@ -634,30 +626,27 @@ impl<'hir> LoweringContext<'_, 'hir> {
/// Paths like the visibility path in `pub(super) use foo::{bar, baz}` are repeated
/// many times in the HIR tree; for each occurrence, we need to assign distinct
/// `NodeId`s. (See, e.g., #56128.)
fn rebuild_use_path(&mut self, path: &hir::Path) -> hir::Path {
fn rebuild_use_path(&mut self, path: &hir::Path<'hir>) -> hir::Path<'hir> {
debug!("rebuild_use_path(path = {:?})", path);
let segments = path
.segments
.iter()
.map(|seg| hir::PathSegment {
let segments =
self.arena.alloc_from_iter(path.segments.iter().map(|seg| hir::PathSegment {
ident: seg.ident,
hir_id: seg.hir_id.map(|_| self.next_id()),
res: seg.res,
args: None,
infer_args: seg.infer_args,
})
.collect();
}));
hir::Path { span: path.span, res: path.res, segments }
}
fn rebuild_vis(&mut self, vis: &hir::Visibility) -> hir::Visibility {
fn rebuild_vis(&mut self, vis: &hir::Visibility<'hir>) -> hir::Visibility<'hir> {
let vis_kind = match vis.node {
hir::VisibilityKind::Public => hir::VisibilityKind::Public,
hir::VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar),
hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
hir::VisibilityKind::Restricted { ref path, hir_id: _ } => {
hir::VisibilityKind::Restricted {
path: P(self.rebuild_use_path(path)),
path: self.arena.alloc(self.rebuild_use_path(path)),
hir_id: self.next_id(),
}
}
@ -685,14 +674,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
)
},
);
let fn_dec = self.arena.alloc(fn_dec.into_inner());
let fn_args = self.arena.alloc_from_iter(fn_args.into_iter());
hir::ForeignItemKind::Fn(fn_dec, fn_args, generics)
}
ForeignItemKind::Static(ref t, m) => {
let ty = self.lower_ty(t, ImplTraitContext::disallowed());
hir::ForeignItemKind::Static(self.arena.alloc(ty.into_inner()), m)
hir::ForeignItemKind::Static(ty, m)
}
ForeignItemKind::Ty => hir::ForeignItemKind::Type,
ForeignItemKind::Macro(_) => panic!("macro shouldn't exist here"),
@ -751,8 +739,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
);
self.arena.alloc(t)
} else {
let t = self.lower_ty(&f.ty, ImplTraitContext::disallowed());
self.arena.alloc(t.into_inner())
self.lower_ty(&f.ty, ImplTraitContext::disallowed())
};
hir::StructField {
span: f.span,
@ -775,7 +762,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
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(
@ -786,6 +772,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
AssocItemKind::Fn(ref sig, None) => {
let names = self.lower_fn_params_to_names(&sig.decl);
let names: &[Ident] = self.arena.alloc_from_iter(names.into_iter());
let (generics, sig) =
self.lower_method_sig(&i.generics, sig, trait_item_def_id, false, None);
(generics, hir::TraitItemKind::Method(sig, hir::TraitMethod::Required(names)))
@ -797,11 +784,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
(generics, hir::TraitItemKind::Method(sig, hir::TraitMethod::Provided(body_id)))
}
AssocItemKind::TyAlias(ref bounds, ref default) => {
let ty = default.as_ref().map(|x| {
&*self
.arena
.alloc(self.lower_ty(x, ImplTraitContext::disallowed()).into_inner())
});
let ty = default.as_ref().map(|x| self.lower_ty(x, ImplTraitContext::disallowed()));
let generics = self.lower_generics(&i.generics, ImplTraitContext::disallowed());
let kind = hir::TraitItemKind::Type(
self.lower_param_bounds(bounds, ImplTraitContext::disallowed()),
@ -853,7 +836,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
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())),
@ -888,7 +870,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
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) => {
@ -916,7 +897,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// [1] since `default impl` is not yet implemented, this is always true in impls
}
fn lower_impl_item_ref(&mut self, i: &AssocItem) -> hir::ImplItemRef {
fn lower_impl_item_ref(&mut self, i: &AssocItem) -> hir::ImplItemRef<'hir> {
hir::ImplItemRef {
id: hir::ImplItemId { hir_id: self.lower_node_id(i.id) },
ident: i.ident,
@ -950,7 +931,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
&mut self,
v: &Visibility,
explicit_owner: Option<NodeId>,
) -> hir::Visibility {
) -> hir::Visibility<'hir> {
let node = match v.node {
VisibilityKind::Public => hir::VisibilityKind::Public,
VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar),
@ -964,7 +945,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
let res = self.expect_full_res(id);
let res = self.lower_res(res);
hir::VisibilityKind::Restricted {
path: P(self.lower_path_extra(res, path, ParamMode::Explicit, explicit_owner)),
path: self.arena.alloc(self.lower_path_extra(
res,
path,
ParamMode::Explicit,
explicit_owner,
)),
hir_id: lowered_id,
}
}
@ -1253,7 +1239,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn_def_id: DefId,
impl_trait_return_allow: bool,
is_async: Option<NodeId>,
) -> (hir::Generics, hir::FnSig) {
) -> (hir::Generics<'hir>, hir::FnSig<'hir>) {
let header = self.lower_fn_header(sig.header);
let (generics, decl) = self.add_in_band_defs(
generics,
@ -1312,8 +1298,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
pub(super) fn lower_generics(
&mut self,
generics: &Generics,
itctx: ImplTraitContext<'_>,
) -> hir::Generics {
itctx: ImplTraitContext<'_, 'hir>,
) -> hir::Generics<'hir> {
// Collect `?Trait` bounds in where clause and move them to parameter definitions.
// FIXME: this could probably be done with less rightward drift. It also looks like two
// control paths where `report_error` is called are the only paths that advance to after the
@ -1376,20 +1362,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
}
fn lower_where_clause(&mut self, wc: &WhereClause) -> hir::WhereClause {
fn lower_where_clause(&mut self, wc: &WhereClause) -> hir::WhereClause<'hir> {
self.with_anonymous_lifetime_mode(AnonymousLifetimeMode::ReportError, |this| {
hir::WhereClause {
predicates: wc
.predicates
.iter()
.map(|predicate| this.lower_where_predicate(predicate))
.collect(),
predicates: this.arena.alloc_from_iter(
wc.predicates.iter().map(|predicate| this.lower_where_predicate(predicate)),
),
span: wc.span,
}
})
}
fn lower_where_predicate(&mut self, pred: &WherePredicate) -> hir::WherePredicate {
fn lower_where_predicate(&mut self, pred: &WherePredicate) -> hir::WherePredicate<'hir> {
match *pred {
WherePredicate::BoundPredicate(WhereBoundPredicate {
ref bound_generic_params,
@ -1399,23 +1383,25 @@ impl<'hir> LoweringContext<'_, 'hir> {
}) => {
self.with_in_scope_lifetime_defs(&bound_generic_params, |this| {
hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate {
bound_generic_params: this.lower_generic_params(
bound_generic_params,
&NodeMap::default(),
ImplTraitContext::disallowed(),
bound_generic_params: this.arena.alloc_from_iter(
this.lower_generic_params(
bound_generic_params,
&NodeMap::default(),
ImplTraitContext::disallowed(),
)
.into_iter(),
),
bounded_ty: this.lower_ty(bounded_ty, ImplTraitContext::disallowed()),
bounds: bounds
.iter()
.filter_map(|bound| match *bound {
bounds: this.arena.alloc_from_iter(bounds.iter().filter_map(|bound| {
match *bound {
// Ignore `?Trait` bounds.
// They were copied into type parameters already.
GenericBound::Trait(_, TraitBoundModifier::Maybe) => None,
_ => Some(
this.lower_param_bound(bound, ImplTraitContext::disallowed()),
),
})
.collect(),
}
})),
span,
})
})

View file

@ -109,10 +109,10 @@ impl<'a> Code<'a> {
/// use when implementing FnLikeNode operations.
struct ItemFnParts<'a> {
ident: Ident,
decl: &'a ast::FnDecl,
decl: &'a ast::FnDecl<'a>,
header: ast::FnHeader,
vis: &'a ast::Visibility,
generics: &'a ast::Generics,
vis: &'a ast::Visibility<'a>,
generics: &'a ast::Generics<'a>,
body: ast::BodyId,
id: ast::HirId,
span: Span,
@ -122,7 +122,7 @@ struct ItemFnParts<'a> {
/// These are all the components one can extract from a closure expr
/// for use when implementing FnLikeNode operations.
struct ClosureParts<'a> {
decl: &'a FnDecl,
decl: &'a FnDecl<'a>,
body: ast::BodyId,
id: ast::HirId,
span: Span,
@ -130,7 +130,13 @@ struct ClosureParts<'a> {
}
impl<'a> ClosureParts<'a> {
fn new(d: &'a FnDecl, b: ast::BodyId, id: ast::HirId, s: Span, attrs: &'a [Attribute]) -> Self {
fn new(
d: &'a FnDecl<'a>,
b: ast::BodyId,
id: ast::HirId,
s: Span,
attrs: &'a [Attribute],
) -> Self {
ClosureParts { decl: d, body: b, id, span: s, attrs }
}
}
@ -151,15 +157,15 @@ impl<'a> FnLikeNode<'a> {
pub fn body(self) -> ast::BodyId {
self.handle(
|i: ItemFnParts<'a>| i.body,
|_, _, _: &'a ast::FnSig, _, body: ast::BodyId, _, _| body,
|_, _, _: &'a ast::FnSig<'a>, _, body: ast::BodyId, _, _| body,
|c: ClosureParts<'a>| c.body,
)
}
pub fn decl(self) -> &'a FnDecl {
pub fn decl(self) -> &'a FnDecl<'a> {
self.handle(
|i: ItemFnParts<'a>| &*i.decl,
|_, _, sig: &'a ast::FnSig, _, _, _, _| &sig.decl,
|_, _, sig: &'a ast::FnSig<'a>, _, _, _, _| &sig.decl,
|c: ClosureParts<'a>| c.decl,
)
}
@ -167,7 +173,7 @@ impl<'a> FnLikeNode<'a> {
pub fn span(self) -> Span {
self.handle(
|i: ItemFnParts<'_>| i.span,
|_, _, _: &'a ast::FnSig, _, _, span, _| span,
|_, _, _: &'a ast::FnSig<'a>, _, _, span, _| span,
|c: ClosureParts<'_>| c.span,
)
}
@ -175,7 +181,7 @@ impl<'a> FnLikeNode<'a> {
pub fn id(self) -> ast::HirId {
self.handle(
|i: ItemFnParts<'_>| i.id,
|id, _, _: &'a ast::FnSig, _, _, _, _| id,
|id, _, _: &'a ast::FnSig<'a>, _, _, _, _| id,
|c: ClosureParts<'_>| c.id,
)
}
@ -197,7 +203,7 @@ impl<'a> FnLikeNode<'a> {
FnKind::ItemFn(p.ident, p.generics, p.header, p.vis, p.attrs)
};
let closure = |c: ClosureParts<'a>| FnKind::Closure(c.attrs);
let method = |_, ident: Ident, sig: &'a ast::FnSig, vis, _, _, attrs| {
let method = |_, ident: Ident, sig: &'a ast::FnSig<'a>, vis, _, _, attrs| {
FnKind::Method(ident, sig, vis, attrs)
};
self.handle(item, method, closure)
@ -209,8 +215,8 @@ impl<'a> FnLikeNode<'a> {
M: FnOnce(
ast::HirId,
Ident,
&'a ast::FnSig,
Option<&'a ast::Visibility>,
&'a ast::FnSig<'a>,
Option<&'a ast::Visibility<'a>>,
ast::BodyId,
Span,
&'a [Attribute],

View file

@ -401,7 +401,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
});
}
fn visit_generic_param(&mut self, param: &'hir GenericParam) {
fn visit_generic_param(&mut self, param: &'hir GenericParam<'hir>) {
self.insert(param.span, param.hir_id, Node::GenericParam(param));
intravisit::walk_generic_param(self, param);
}
@ -478,14 +478,14 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
});
}
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'hir PathSegment) {
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'hir PathSegment<'hir>) {
if let Some(hir_id) = path_segment.hir_id {
self.insert(path_span, hir_id, Node::PathSegment(path_segment));
}
intravisit::walk_path_segment(self, path_span, path_segment);
}
fn visit_ty(&mut self, ty: &'hir Ty) {
fn visit_ty(&mut self, ty: &'hir Ty<'hir>) {
self.insert(ty.span, ty.hir_id, Node::Ty(ty));
self.with_parent(ty.hir_id, |this| {
@ -493,7 +493,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
});
}
fn visit_trait_ref(&mut self, tr: &'hir TraitRef) {
fn visit_trait_ref(&mut self, tr: &'hir TraitRef<'hir>) {
self.insert(tr.path.span, tr.hir_ref_id, Node::TraitRef(tr));
self.with_parent(tr.hir_ref_id, |this| {
@ -504,7 +504,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
fn visit_fn(
&mut self,
fk: intravisit::FnKind<'hir>,
fd: &'hir FnDecl,
fd: &'hir FnDecl<'hir>,
b: BodyId,
s: Span,
id: HirId,
@ -529,7 +529,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
self.insert(lifetime.span, lifetime.hir_id, Node::Lifetime(lifetime));
}
fn visit_vis(&mut self, visibility: &'hir Visibility) {
fn visit_vis(&mut self, visibility: &'hir Visibility<'hir>) {
match visibility.node {
VisibilityKind::Public | VisibilityKind::Crate(_) | VisibilityKind::Inherited => {}
VisibilityKind::Restricted { hir_id, .. } => {
@ -550,7 +550,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
});
}
fn visit_variant(&mut self, v: &'hir Variant<'hir>, g: &'hir Generics, item_id: HirId) {
fn visit_variant(&mut self, v: &'hir Variant<'hir>, g: &'hir Generics<'hir>, item_id: HirId) {
self.insert(v.span, v.id, Node::Variant(v));
self.with_parent(v.id, |this| {
// Register the constructor of this variant.
@ -576,7 +576,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
self.visit_nested_trait_item(id);
}
fn visit_impl_item_ref(&mut self, ii: &'hir ImplItemRef) {
fn visit_impl_item_ref(&mut self, ii: &'hir ImplItemRef<'hir>) {
// Do not visit the duplicate information in ImplItemRef. We want to
// map the actual nodes, not the duplicate ones in the *Ref.
let ImplItemRef { id, ident: _, kind: _, span: _, vis: _, defaultness: _ } = *ii;

View file

@ -161,7 +161,7 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> {
self.hir_ids_seen.insert(hir_id.local_id);
}
fn visit_impl_item_ref(&mut self, _: &'hir hir::ImplItemRef) {
fn visit_impl_item_ref(&mut self, _: &'hir hir::ImplItemRef<'hir>) {
// Explicitly do nothing here. ImplItemRefs contain hir::Visibility
// values that actually belong to an ImplItem instead of the ItemKind::Impl
// we are currently in. So for those it's correct that they have a

View file

@ -43,7 +43,7 @@ impl<'hir> Entry<'hir> {
}
}
fn fn_decl(&self) -> Option<&'hir FnDecl> {
fn fn_decl(&self) -> Option<&'hir FnDecl<'hir>> {
match self.node {
Node::Item(ref item) => match item.kind {
ItemKind::Fn(ref sig, _, _) => Some(&sig.decl),
@ -69,7 +69,7 @@ impl<'hir> Entry<'hir> {
}
}
fn fn_sig(&self) -> Option<&'hir FnSig> {
fn fn_sig(&self) -> Option<&'hir FnSig<'hir>> {
match &self.node {
Node::Item(item) => match &item.kind {
ItemKind::Fn(sig, _, _) => Some(sig),
@ -429,7 +429,7 @@ impl<'hir> Map<'hir> {
self.forest.krate.body(id)
}
pub fn fn_decl_by_hir_id(&self, hir_id: HirId) -> Option<&'hir FnDecl> {
pub fn fn_decl_by_hir_id(&self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> {
if let Some(entry) = self.find_entry(hir_id) {
entry.fn_decl()
} else {
@ -437,7 +437,7 @@ impl<'hir> Map<'hir> {
}
}
pub fn fn_sig_by_hir_id(&self, hir_id: HirId) -> Option<&'hir FnSig> {
pub fn fn_sig_by_hir_id(&self, hir_id: HirId) -> Option<&'hir FnSig<'hir>> {
if let Some(entry) = self.find_entry(hir_id) {
entry.fn_sig()
} else {
@ -584,7 +584,7 @@ impl<'hir> Map<'hir> {
self.as_local_hir_id(id).map(|id| self.get(id)) // read recorded by `get`
}
pub fn get_generics(&self, id: DefId) -> Option<&'hir Generics> {
pub fn get_generics(&self, id: DefId) -> Option<&'hir Generics<'hir>> {
self.get_if_local(id).and_then(|node| match node {
Node::ImplItem(ref impl_item) => Some(&impl_item.generics),
Node::TraitItem(ref trait_item) => Some(&trait_item.generics),

View file

@ -303,27 +303,27 @@ impl Lifetime {
/// `std::cmp::PartialEq`. It's represented as a sequence of identifiers,
/// along with a bunch of supporting information.
#[derive(RustcEncodable, RustcDecodable, HashStable)]
pub struct Path {
pub struct Path<'hir> {
pub span: Span,
/// The resolution for the path.
pub res: Res,
/// The segments in the path: the things separated by `::`.
pub segments: HirVec<PathSegment>,
pub segments: &'hir [PathSegment<'hir>],
}
impl Path {
impl Path<'_> {
pub fn is_global(&self) -> bool {
!self.segments.is_empty() && self.segments[0].ident.name == kw::PathRoot
}
}
impl fmt::Debug for Path {
impl fmt::Debug for Path<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "path({})", self)
}
}
impl fmt::Display for Path {
impl fmt::Display for Path<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", print::to_string(print::NO_ANN, |s| s.print_path(self, false)))
}
@ -332,7 +332,7 @@ impl fmt::Display for Path {
/// A segment of a path: an identifier, an optional lifetime, and a set of
/// types.
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct PathSegment {
pub struct PathSegment<'hir> {
/// The identifier portion of this path segment.
#[stable_hasher(project(name))]
pub ident: Ident,
@ -349,7 +349,7 @@ pub struct PathSegment {
/// this is more than just simple syntactic sugar; the use of
/// parens affects the region binding rules, so we preserve the
/// distinction.
pub args: Option<P<GenericArgs>>,
pub args: Option<&'hir GenericArgs<'hir>>,
/// Whether to infer remaining type parameters, if any.
/// This only applies to expression and pattern paths, and
@ -358,33 +358,17 @@ pub struct PathSegment {
pub infer_args: bool,
}
impl PathSegment {
impl<'hir> PathSegment<'hir> {
/// Converts an identifier to the corresponding segment.
pub fn from_ident(ident: Ident) -> PathSegment {
pub fn from_ident(ident: Ident) -> PathSegment<'hir> {
PathSegment { ident, hir_id: None, res: None, infer_args: true, args: None }
}
pub fn new(
ident: Ident,
hir_id: Option<HirId>,
res: Option<Res>,
args: GenericArgs,
infer_args: bool,
) -> Self {
PathSegment {
ident,
hir_id,
res,
infer_args,
args: if args.is_empty() { None } else { Some(P(args)) },
}
}
pub fn generic_args(&self) -> &GenericArgs {
pub fn generic_args(&self) -> &GenericArgs<'hir> {
if let Some(ref args) = self.args {
args
} else {
const DUMMY: &GenericArgs = &GenericArgs::none();
const DUMMY: &GenericArgs<'_> = &GenericArgs::none();
DUMMY
}
}
@ -397,13 +381,13 @@ pub struct ConstArg {
}
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum GenericArg {
pub enum GenericArg<'hir> {
Lifetime(Lifetime),
Type(Ty),
Type(Ty<'hir>),
Const(ConstArg),
}
impl GenericArg {
impl GenericArg<'_> {
pub fn span(&self) -> Span {
match self {
GenericArg::Lifetime(l) => l.span,
@ -429,28 +413,28 @@ impl GenericArg {
}
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct GenericArgs {
pub struct GenericArgs<'hir> {
/// The generic arguments for this path segment.
pub args: HirVec<GenericArg>,
pub args: HirVec<GenericArg<'hir>>,
/// Bindings (equality constraints) on associated types, if present.
/// E.g., `Foo<A = Bar>`.
pub bindings: HirVec<TypeBinding>,
pub bindings: &'hir [TypeBinding<'hir>],
/// Were arguments written in parenthesized form `Fn(T) -> U`?
/// This is required mostly for pretty-printing and diagnostics,
/// but also for changing lifetime elision rules to be "function-like".
pub parenthesized: bool,
}
impl GenericArgs {
impl GenericArgs<'_> {
pub const fn none() -> Self {
Self { args: HirVec::new(), bindings: HirVec::new(), parenthesized: false }
Self { args: HirVec::new(), bindings: &[], parenthesized: false }
}
pub fn is_empty(&self) -> bool {
self.args.is_empty() && self.bindings.is_empty() && !self.parenthesized
}
pub fn inputs(&self) -> &[Ty] {
pub fn inputs(&self) -> &[Ty<'_>] {
if self.parenthesized {
for arg in &self.args {
match arg {
@ -499,12 +483,12 @@ pub enum TraitBoundModifier {
/// the "special" built-in traits (see `middle::lang_items`) and
/// detects `Copy`, `Send` and `Sync`.
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum GenericBound {
Trait(PolyTraitRef, TraitBoundModifier),
pub enum GenericBound<'hir> {
Trait(PolyTraitRef<'hir>, TraitBoundModifier),
Outlives(Lifetime),
}
impl GenericBound {
impl GenericBound<'_> {
pub fn span(&self) -> Span {
match self {
&GenericBound::Trait(ref t, ..) => t.span,
@ -513,7 +497,7 @@ impl GenericBound {
}
}
pub type GenericBounds = HirVec<GenericBound>;
pub type GenericBounds<'hir> = &'hir [GenericBound<'hir>];
#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum LifetimeParamKind {
@ -535,29 +519,29 @@ pub enum LifetimeParamKind {
}
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum GenericParamKind {
pub enum GenericParamKind<'hir> {
/// A lifetime definition (e.g., `'a: 'b + 'c + 'd`).
Lifetime {
kind: LifetimeParamKind,
},
Type {
default: Option<P<Ty>>,
default: Option<&'hir Ty<'hir>>,
synthetic: Option<SyntheticTyParamKind>,
},
Const {
ty: P<Ty>,
ty: &'hir Ty<'hir>,
},
}
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct GenericParam {
pub struct GenericParam<'hir> {
pub hir_id: HirId,
pub name: ParamName,
pub attrs: HirVec<Attribute>,
pub bounds: GenericBounds,
pub attrs: &'hir [Attribute],
pub bounds: GenericBounds<'hir>,
pub span: Span,
pub pure_wrt_drop: bool,
pub kind: GenericParamKind,
pub kind: GenericParamKind<'hir>,
}
#[derive(Default)]
@ -570,17 +554,17 @@ pub struct GenericParamCount {
/// Represents lifetimes and type parameters attached to a declaration
/// of a function, enum, trait, etc.
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct Generics {
pub params: HirVec<GenericParam>,
pub where_clause: WhereClause,
pub struct Generics<'hir> {
pub params: HirVec<GenericParam<'hir>>,
pub where_clause: WhereClause<'hir>,
pub span: Span,
}
impl Generics {
pub const fn empty() -> Generics {
impl Generics<'hir> {
pub const fn empty() -> Generics<'hir> {
Generics {
params: HirVec::new(),
where_clause: WhereClause { predicates: HirVec::new(), span: DUMMY_SP },
where_clause: WhereClause { predicates: &[], span: DUMMY_SP },
span: DUMMY_SP,
}
}
@ -602,7 +586,7 @@ impl Generics {
own_counts
}
pub fn get_named(&self, name: Symbol) -> Option<&GenericParam> {
pub fn get_named(&self, name: Symbol) -> Option<&GenericParam<'_>> {
for param in &self.params {
if name == param.name.ident().name {
return Some(param);
@ -629,13 +613,13 @@ pub enum SyntheticTyParamKind {
/// A where-clause in a definition.
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct WhereClause {
pub predicates: HirVec<WherePredicate>,
pub struct WhereClause<'hir> {
pub predicates: &'hir [WherePredicate<'hir>],
// Only valid if predicates isn't empty.
span: Span,
}
impl WhereClause {
impl WhereClause<'_> {
pub fn span(&self) -> Option<Span> {
if self.predicates.is_empty() { None } else { Some(self.span) }
}
@ -649,16 +633,16 @@ impl WhereClause {
/// A single predicate in a where-clause.
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum WherePredicate {
pub enum WherePredicate<'hir> {
/// A type binding (e.g., `for<'c> Foo: Send + Clone + 'c`).
BoundPredicate(WhereBoundPredicate),
BoundPredicate(WhereBoundPredicate<'hir>),
/// A lifetime predicate (e.g., `'a: 'b + 'c`).
RegionPredicate(WhereRegionPredicate),
RegionPredicate(WhereRegionPredicate<'hir>),
/// An equality predicate (unsupported).
EqPredicate(WhereEqPredicate),
EqPredicate(WhereEqPredicate<'hir>),
}
impl WherePredicate {
impl WherePredicate<'_> {
pub fn span(&self) -> Span {
match self {
&WherePredicate::BoundPredicate(ref p) => p.span,
@ -670,31 +654,31 @@ impl WherePredicate {
/// A type bound (e.g., `for<'c> Foo: Send + Clone + 'c`).
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct WhereBoundPredicate {
pub struct WhereBoundPredicate<'hir> {
pub span: Span,
/// Any generics from a `for` binding.
pub bound_generic_params: HirVec<GenericParam>,
pub bound_generic_params: &'hir [GenericParam<'hir>],
/// The type being bounded.
pub bounded_ty: P<Ty>,
pub bounded_ty: &'hir Ty<'hir>,
/// Trait and lifetime bounds (e.g., `Clone + Send + 'static`).
pub bounds: GenericBounds,
pub bounds: GenericBounds<'hir>,
}
/// A lifetime predicate (e.g., `'a: 'b + 'c`).
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct WhereRegionPredicate {
pub struct WhereRegionPredicate<'hir> {
pub span: Span,
pub lifetime: Lifetime,
pub bounds: GenericBounds,
pub bounds: GenericBounds<'hir>,
}
/// An equality predicate (e.g., `T = int`); currently unsupported.
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct WhereEqPredicate {
pub struct WhereEqPredicate<'hir> {
pub hir_id: HirId,
pub span: Span,
pub lhs_ty: P<Ty>,
pub rhs_ty: P<Ty>,
pub lhs_ty: &'hir Ty<'hir>,
pub rhs_ty: &'hir Ty<'hir>,
}
#[derive(RustcEncodable, RustcDecodable, Debug)]
@ -820,7 +804,7 @@ impl Crate<'_> {
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct MacroDef<'hir> {
pub name: Name,
pub vis: Visibility,
pub vis: Visibility<'hir>,
pub attrs: &'hir [Attribute],
pub hir_id: HirId,
pub span: Span,
@ -1003,19 +987,19 @@ pub enum PatKind<'hir> {
/// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`).
/// The `bool` is `true` in the presence of a `..`.
Struct(QPath, &'hir [FieldPat<'hir>], bool),
Struct(QPath<'hir>, &'hir [FieldPat<'hir>], bool),
/// A tuple struct/variant pattern `Variant(x, y, .., z)`.
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
/// `0 <= position <= subpats.len()`
TupleStruct(QPath, &'hir [&'hir Pat<'hir>], Option<usize>),
TupleStruct(QPath<'hir>, &'hir [&'hir Pat<'hir>], Option<usize>),
/// An or-pattern `A | B | C`.
/// Invariant: `pats.len() >= 2`.
Or(&'hir [&'hir Pat<'hir>]),
/// A path pattern for an unit struct/variant or a (maybe-associated) constant.
Path(QPath),
Path(QPath<'hir>),
/// A tuple pattern (e.g., `(a, b)`).
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
@ -1258,7 +1242,7 @@ impl StmtKind<'hir> {
pub struct Local<'hir> {
pub pat: &'hir Pat<'hir>,
/// Type annotation, if any (otherwise the type will be inferred).
pub ty: Option<&'hir Ty>,
pub ty: Option<&'hir Ty<'hir>>,
/// Initializer expression to set the value, if any.
pub init: Option<&'hir Expr<'hir>>,
pub hir_id: HirId,
@ -1583,7 +1567,7 @@ pub fn is_range_literal(sm: &SourceMap, expr: &Expr<'_>) -> bool {
// Returns whether the given path represents a (desugared) range,
// either in std or core, i.e. has either a `::std::ops::Range` or
// `::core::ops::Range` prefix.
fn is_range_path(path: &Path) -> bool {
fn is_range_path(path: &Path<'_>) -> bool {
let segs: Vec<_> = path.segments.iter().map(|seg| seg.ident.to_string()).collect();
let segs: Vec<_> = segs.iter().map(|seg| &**seg).collect();
@ -1663,7 +1647,7 @@ pub enum ExprKind<'hir> {
/// the `hir_id` of the `MethodCall` node itself.
///
/// [`type_dependent_def_id`]: ../ty/struct.TypeckTables.html#method.type_dependent_def_id
MethodCall(&'hir PathSegment, Span, &'hir [Expr<'hir>]),
MethodCall(&'hir PathSegment<'hir>, Span, &'hir [Expr<'hir>]),
/// A tuple (e.g., `(a, b, c, d)`).
Tup(&'hir [Expr<'hir>]),
/// A binary operation (e.g., `a + b`, `a * b`).
@ -1673,9 +1657,9 @@ pub enum ExprKind<'hir> {
/// A literal (e.g., `1`, `"foo"`).
Lit(Lit),
/// A cast (e.g., `foo as f64`).
Cast(&'hir Expr<'hir>, &'hir Ty),
Cast(&'hir Expr<'hir>, &'hir Ty<'hir>),
/// A type reference (e.g., `Foo`).
Type(&'hir Expr<'hir>, &'hir Ty),
Type(&'hir Expr<'hir>, &'hir Ty<'hir>),
/// Wraps the expression in a terminating scope.
/// This makes it semantically equivalent to `{ let _t = expr; _t }`.
///
@ -1695,7 +1679,7 @@ pub enum ExprKind<'hir> {
///
/// This may also be a generator literal or an `async block` as indicated by the
/// `Option<Movability>`.
Closure(CaptureBy, &'hir FnDecl, BodyId, Span, Option<Movability>),
Closure(CaptureBy, &'hir FnDecl<'hir>, BodyId, Span, Option<Movability>),
/// A block (e.g., `'label: { ... }`).
Block(&'hir Block<'hir>, Option<Label>),
@ -1711,7 +1695,7 @@ pub enum ExprKind<'hir> {
Index(&'hir Expr<'hir>, &'hir Expr<'hir>),
/// Path to a definition, possibly containing lifetime or type parameters.
Path(QPath),
Path(QPath<'hir>),
/// A referencing operation (i.e., `&a` or `&mut a`).
AddrOf(BorrowKind, Mutability, &'hir Expr<'hir>),
@ -1729,7 +1713,7 @@ pub enum ExprKind<'hir> {
///
/// E.g., `Foo {x: 1, y: 2}`, or `Foo {x: 1, .. base}`,
/// where `base` is the `Option<Expr>`.
Struct(&'hir QPath, &'hir [Field<'hir>], Option<&'hir Expr<'hir>>),
Struct(&'hir QPath<'hir>, &'hir [Field<'hir>], Option<&'hir Expr<'hir>>),
/// An array literal constructed from one repeated element.
///
@ -1750,14 +1734,14 @@ pub enum ExprKind<'hir> {
///
/// [`qpath_res`]: ../ty/struct.TypeckTables.html#method.qpath_res
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum QPath {
pub enum QPath<'hir> {
/// Path to a definition, optionally "fully-qualified" with a `Self`
/// type, if the path points to an associated item in a trait.
///
/// E.g., an unqualified path like `Clone::clone` has `None` for `Self`,
/// while `<Vec<T> as Clone>::clone` has `Some(Vec<T>)` for `Self`,
/// even though they both have the same two-segment `Clone::clone` `Path`.
Resolved(Option<P<Ty>>, P<Path>),
Resolved(Option<&'hir Ty<'hir>>, &'hir Path<'hir>),
/// Type-related paths (e.g., `<T>::default` or `<T>::Output`).
/// Will be resolved by type-checking to an associated item.
@ -1765,7 +1749,7 @@ pub enum QPath {
/// UFCS source paths can desugar into this, with `Vec::new` turning into
/// `<Vec>::new`, and `T::X::Y::method` into `<<<T>::X>::Y>::method`,
/// the `X` and `Y` nodes each being a `TyKind::Path(QPath::TypeRelative(..))`.
TypeRelative(P<Ty>, P<PathSegment>),
TypeRelative(&'hir Ty<'hir>, &'hir PathSegment<'hir>),
}
/// Hints at the original code for a let statement.
@ -1909,17 +1893,17 @@ impl From<GeneratorKind> for YieldSource {
// N.B., if you change this, you'll probably want to change the corresponding
// type structure in middle/ty.rs as well.
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct MutTy {
pub ty: P<Ty>,
pub struct MutTy<'hir> {
pub ty: &'hir Ty<'hir>,
pub mutbl: Mutability,
}
/// Represents a function's signature in a trait declaration,
/// trait implementation, or a free function.
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct FnSig {
pub struct FnSig<'hir> {
pub header: FnHeader,
pub decl: P<FnDecl>,
pub decl: &'hir FnDecl<'hir>,
}
// The bodies for items are stored "out of line", in a separate
@ -1939,16 +1923,16 @@ pub struct TraitItem<'hir> {
pub ident: Ident,
pub hir_id: HirId,
pub attrs: &'hir [Attribute],
pub generics: Generics,
pub generics: Generics<'hir>,
pub kind: TraitItemKind<'hir>,
pub span: Span,
}
/// Represents a trait method's body (or just argument names).
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum TraitMethod {
pub enum TraitMethod<'hir> {
/// No default body in the trait, just a signature.
Required(HirVec<Ident>),
Required(&'hir [Ident]),
/// Both signature and body are provided in the trait.
Provided(BodyId),
@ -1958,12 +1942,12 @@ pub enum TraitMethod {
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum TraitItemKind<'hir> {
/// An associated constant with an optional value (otherwise `impl`s must contain a value).
Const(&'hir Ty, Option<BodyId>),
Const(&'hir Ty<'hir>, Option<BodyId>),
/// A method with an optional body.
Method(FnSig, TraitMethod),
Method(FnSig<'hir>, TraitMethod<'hir>),
/// An associated type with (possibly empty) bounds and optional concrete
/// type.
Type(GenericBounds, Option<&'hir Ty>),
Type(GenericBounds<'hir>, Option<&'hir Ty<'hir>>),
}
// The bodies for items are stored "out of line", in a separate
@ -1979,10 +1963,10 @@ pub struct ImplItemId {
pub struct ImplItem<'hir> {
pub ident: Ident,
pub hir_id: HirId,
pub vis: Visibility,
pub vis: Visibility<'hir>,
pub defaultness: Defaultness,
pub attrs: &'hir [Attribute],
pub generics: Generics,
pub generics: Generics<'hir>,
pub kind: ImplItemKind<'hir>,
pub span: Span,
}
@ -1992,13 +1976,13 @@ pub struct ImplItem<'hir> {
pub enum ImplItemKind<'hir> {
/// An associated constant of the given type, set to the constant result
/// of the expression.
Const(&'hir Ty, BodyId),
Const(&'hir Ty<'hir>, BodyId),
/// A method implementation with the given signature and body.
Method(FnSig, BodyId),
Method(FnSig<'hir>, BodyId),
/// An associated type.
TyAlias(&'hir Ty),
TyAlias(&'hir Ty<'hir>),
/// An associated `type = impl Trait`.
OpaqueTy(GenericBounds),
OpaqueTy(GenericBounds<'hir>),
}
/// Bind a type to an associated type (i.e., `A = Foo`).
@ -2017,25 +2001,25 @@ pub enum ImplItemKind<'hir> {
/// }
/// ```
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct TypeBinding {
pub struct TypeBinding<'hir> {
pub hir_id: HirId,
#[stable_hasher(project(name))]
pub ident: Ident,
pub kind: TypeBindingKind,
pub kind: TypeBindingKind<'hir>,
pub span: Span,
}
// Represents the two kinds of type bindings.
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum TypeBindingKind {
pub enum TypeBindingKind<'hir> {
/// E.g., `Foo<Bar: Send>`.
Constraint { bounds: HirVec<GenericBound> },
Constraint { bounds: &'hir [GenericBound<'hir>] },
/// E.g., `Foo<Bar = ()>`.
Equality { ty: P<Ty> },
Equality { ty: &'hir Ty<'hir> },
}
impl TypeBinding {
pub fn ty(&self) -> &Ty {
impl TypeBinding<'_> {
pub fn ty(&self) -> &Ty<'_> {
match self.kind {
TypeBindingKind::Equality { ref ty } => ty,
_ => bug!("expected equality type binding for parenthesized generic args"),
@ -2044,13 +2028,13 @@ impl TypeBinding {
}
#[derive(RustcEncodable, RustcDecodable)]
pub struct Ty {
pub struct Ty<'hir> {
pub hir_id: HirId,
pub kind: TyKind,
pub kind: TyKind<'hir>,
pub span: Span,
}
impl fmt::Debug for Ty {
impl fmt::Debug for Ty<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "type({})", print::to_string(print::NO_ANN, |s| s.print_type(self)))
}
@ -2068,18 +2052,18 @@ pub enum PrimTy {
}
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct BareFnTy {
pub struct BareFnTy<'hir> {
pub unsafety: Unsafety,
pub abi: Abi,
pub generic_params: HirVec<GenericParam>,
pub decl: P<FnDecl>,
pub param_names: HirVec<Ident>,
pub generic_params: &'hir [GenericParam<'hir>],
pub decl: &'hir FnDecl<'hir>,
pub param_names: &'hir [Ident],
}
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct OpaqueTy {
pub generics: Generics,
pub bounds: GenericBounds,
pub struct OpaqueTy<'hir> {
pub generics: Generics<'hir>,
pub bounds: GenericBounds<'hir>,
pub impl_trait_fn: Option<DefId>,
pub origin: OpaqueTyOrigin,
}
@ -2097,35 +2081,35 @@ pub enum OpaqueTyOrigin {
/// The various kinds of types recognized by the compiler.
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum TyKind {
pub enum TyKind<'hir> {
/// A variable length slice (i.e., `[T]`).
Slice(P<Ty>),
Slice(&'hir Ty<'hir>),
/// A fixed length array (i.e., `[T; n]`).
Array(P<Ty>, AnonConst),
Array(&'hir Ty<'hir>, AnonConst),
/// A raw pointer (i.e., `*const T` or `*mut T`).
Ptr(MutTy),
Ptr(MutTy<'hir>),
/// A reference (i.e., `&'a T` or `&'a mut T`).
Rptr(Lifetime, MutTy),
Rptr(Lifetime, MutTy<'hir>),
/// A bare function (e.g., `fn(usize) -> bool`).
BareFn(P<BareFnTy>),
BareFn(&'hir BareFnTy<'hir>),
/// The never type (`!`).
Never,
/// A tuple (`(A, B, C, D, ...)`).
Tup(HirVec<Ty>),
Tup(&'hir [Ty<'hir>]),
/// A path to a type definition (`module::module::...::Type`), or an
/// associated type (e.g., `<Vec<T> as Trait>::Type` or `<T>::Target`).
///
/// Type parameters may be stored in each `PathSegment`.
Path(QPath),
Path(QPath<'hir>),
/// A type definition itself. This is currently only used for the `type Foo = impl Trait`
/// item that `impl Trait` in return position desugars to.
///
/// The generic argument list contains the lifetimes (and in the future possibly parameters)
/// that are actually bound on the `impl Trait`.
Def(ItemId, HirVec<GenericArg>),
Def(ItemId, &'hir [GenericArg<'hir>]),
/// A trait object type `Bound1 + Bound2 + Bound3`
/// where `Bound` is a trait or a lifetime.
TraitObject(HirVec<PolyTraitRef>, Lifetime),
TraitObject(&'hir [PolyTraitRef<'hir>], Lifetime),
/// Unused for now.
Typeof(AnonConst),
/// `TyKind::Infer` means the type should be inferred instead of it having been
@ -2175,12 +2159,12 @@ pub struct Param<'hir> {
/// Represents the header (not the body) of a function declaration.
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct FnDecl {
pub struct FnDecl<'hir> {
/// The types of the function's parameters.
///
/// Additional argument data is stored in the function's [body](Body::parameters).
pub inputs: HirVec<Ty>,
pub output: FunctionRetTy,
pub inputs: &'hir [Ty<'hir>],
pub output: FunctionRetTy<'hir>,
pub c_variadic: bool,
/// Does the function have an implicit self?
pub implicit_self: ImplicitSelfKind,
@ -2256,7 +2240,7 @@ impl Defaultness {
}
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum FunctionRetTy {
pub enum FunctionRetTy<'hir> {
/// Return type is not specified.
///
/// Functions default to `()` and
@ -2264,10 +2248,10 @@ pub enum FunctionRetTy {
/// type would be inserted.
DefaultReturn(Span),
/// Everything else.
Return(P<Ty>),
Return(&'hir Ty<'hir>),
}
impl fmt::Display for FunctionRetTy {
impl fmt::Display for FunctionRetTy<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Return(ref ty) => print::to_string(print::NO_ANN, |s| s.print_type(ty)).fmt(f),
@ -2276,7 +2260,7 @@ impl fmt::Display for FunctionRetTy {
}
}
impl FunctionRetTy {
impl FunctionRetTy<'_> {
pub fn span(&self) -> Span {
match *self {
DefaultReturn(span) => span,
@ -2350,14 +2334,14 @@ pub enum UseKind {
/// trait being referred to but just a unique `HirId` that serves as a key
/// within the resolution map.
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct TraitRef {
pub path: P<Path>,
pub struct TraitRef<'hir> {
pub path: &'hir Path<'hir>,
// Don't hash the `ref_id`. It is tracked via the thing it is used to access.
#[stable_hasher(ignore)]
pub hir_ref_id: HirId,
}
impl TraitRef {
impl TraitRef<'_> {
/// Gets the `DefId` of the referenced trait. It _must_ actually be a trait or trait alias.
pub fn trait_def_id(&self) -> DefId {
match self.path.res {
@ -2372,27 +2356,27 @@ impl TraitRef {
}
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct PolyTraitRef {
pub struct PolyTraitRef<'hir> {
/// The `'a` in `<'a> Foo<&'a T>`.
pub bound_generic_params: HirVec<GenericParam>,
pub bound_generic_params: &'hir [GenericParam<'hir>],
/// The `Foo<&'a T>` in `<'a> Foo<&'a T>`.
pub trait_ref: TraitRef,
pub trait_ref: TraitRef<'hir>,
pub span: Span,
}
pub type Visibility = Spanned<VisibilityKind>;
pub type Visibility<'hir> = Spanned<VisibilityKind<'hir>>;
#[derive(RustcEncodable, RustcDecodable, Debug)]
pub enum VisibilityKind {
pub enum VisibilityKind<'hir> {
Public,
Crate(CrateSugar),
Restricted { path: P<Path>, hir_id: HirId },
Restricted { path: &'hir Path<'hir>, hir_id: HirId },
Inherited,
}
impl VisibilityKind {
impl VisibilityKind<'_> {
pub fn is_pub(&self) -> bool {
match *self {
VisibilityKind::Public => true,
@ -2422,9 +2406,9 @@ pub struct StructField<'hir> {
pub span: Span,
#[stable_hasher(project(name))]
pub ident: Ident,
pub vis: Visibility,
pub vis: Visibility<'hir>,
pub hir_id: HirId,
pub ty: &'hir Ty,
pub ty: &'hir Ty<'hir>,
pub attrs: &'hir [Attribute],
}
@ -2488,7 +2472,7 @@ pub struct Item<'hir> {
pub hir_id: HirId,
pub attrs: &'hir [Attribute],
pub kind: ItemKind<'hir>,
pub vis: Visibility,
pub vis: Visibility<'hir>,
pub span: Span,
}
@ -2521,14 +2505,14 @@ pub enum ItemKind<'hir> {
/// or just
///
/// `use foo::bar::baz;` (with `as baz` implicitly on the right).
Use(&'hir Path, UseKind),
Use(&'hir Path<'hir>, UseKind),
/// A `static` item.
Static(&'hir Ty, Mutability, BodyId),
Static(&'hir Ty<'hir>, Mutability, BodyId),
/// A `const` item.
Const(&'hir Ty, BodyId),
Const(&'hir Ty<'hir>, BodyId),
/// A function declaration.
Fn(FnSig, Generics, BodyId),
Fn(FnSig<'hir>, Generics<'hir>, BodyId),
/// A module.
Mod(Mod<'hir>),
/// An external module, e.g. `extern { .. }`.
@ -2536,29 +2520,29 @@ pub enum ItemKind<'hir> {
/// Module-level inline assembly (from `global_asm!`).
GlobalAsm(&'hir GlobalAsm),
/// A type alias, e.g., `type Foo = Bar<u8>`.
TyAlias(&'hir Ty, Generics),
TyAlias(&'hir Ty<'hir>, Generics<'hir>),
/// An opaque `impl Trait` type alias, e.g., `type Foo = impl Bar;`.
OpaqueTy(OpaqueTy),
OpaqueTy(OpaqueTy<'hir>),
/// An enum definition, e.g., `enum Foo<A, B> {C<A>, D<B>}`.
Enum(EnumDef<'hir>, Generics),
Enum(EnumDef<'hir>, Generics<'hir>),
/// A struct definition, e.g., `struct Foo<A> {x: A}`.
Struct(VariantData<'hir>, Generics),
Struct(VariantData<'hir>, Generics<'hir>),
/// A union definition, e.g., `union Foo<A, B> {x: A, y: B}`.
Union(VariantData<'hir>, Generics),
Union(VariantData<'hir>, Generics<'hir>),
/// A trait definition.
Trait(IsAuto, Unsafety, Generics, GenericBounds, &'hir [TraitItemRef]),
Trait(IsAuto, Unsafety, Generics<'hir>, GenericBounds<'hir>, &'hir [TraitItemRef]),
/// A trait alias.
TraitAlias(Generics, GenericBounds),
TraitAlias(Generics<'hir>, GenericBounds<'hir>),
/// An implementation, e.g., `impl<A> Trait for Foo { .. }`.
Impl(
Unsafety,
ImplPolarity,
Defaultness,
Generics,
Option<TraitRef>, // (optional) trait this impl implements
&'hir Ty, // self
&'hir [ImplItemRef],
Generics<'hir>,
Option<TraitRef<'hir>>, // (optional) trait this impl implements
&'hir Ty<'hir>, // self
&'hir [ImplItemRef<'hir>],
),
}
@ -2593,7 +2577,7 @@ impl ItemKind<'_> {
}
}
pub fn generics(&self) -> Option<&Generics> {
pub fn generics(&self) -> Option<&Generics<'_>> {
Some(match *self {
ItemKind::Fn(_, ref generics, _)
| ItemKind::TyAlias(_, ref generics)
@ -2631,13 +2615,13 @@ pub struct TraitItemRef {
/// passes to find the impl they want without loading the ID (which
/// means fewer edges in the incremental compilation graph).
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct ImplItemRef {
pub struct ImplItemRef<'hir> {
pub id: ImplItemId,
#[stable_hasher(project(name))]
pub ident: Ident,
pub kind: AssocItemKind,
pub span: Span,
pub vis: Visibility,
pub vis: Visibility<'hir>,
pub defaultness: Defaultness,
}
@ -2657,16 +2641,16 @@ pub struct ForeignItem<'hir> {
pub kind: ForeignItemKind<'hir>,
pub hir_id: HirId,
pub span: Span,
pub vis: Visibility,
pub vis: Visibility<'hir>,
}
/// An item within an `extern` block.
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum ForeignItemKind<'hir> {
/// A foreign function.
Fn(&'hir FnDecl, &'hir [Ident], Generics),
Fn(&'hir FnDecl<'hir>, &'hir [Ident], Generics<'hir>),
/// A foreign static item (`static ext: u8`).
Static(&'hir Ty, Mutability),
Static(&'hir Ty<'hir>, Mutability),
/// A foreign type.
Type,
}
@ -2837,9 +2821,9 @@ pub enum Node<'hir> {
AnonConst(&'hir AnonConst),
Expr(&'hir Expr<'hir>),
Stmt(&'hir Stmt<'hir>),
PathSegment(&'hir PathSegment),
Ty(&'hir Ty),
TraitRef(&'hir TraitRef),
PathSegment(&'hir PathSegment<'hir>),
Ty(&'hir Ty<'hir>),
TraitRef(&'hir TraitRef<'hir>),
Binding(&'hir Pat<'hir>),
Pat(&'hir Pat<'hir>),
Arm(&'hir Arm<'hir>),
@ -2852,8 +2836,8 @@ pub enum Node<'hir> {
Ctor(&'hir VariantData<'hir>),
Lifetime(&'hir Lifetime),
GenericParam(&'hir GenericParam),
Visibility(&'hir Visibility),
GenericParam(&'hir GenericParam<'hir>),
Visibility(&'hir Visibility<'hir>),
Crate,
}

View file

@ -10,6 +10,7 @@ use syntax::util::parser::{self, AssocOp, Fixity};
use syntax_pos::{self, BytePos, FileName};
use crate::hir;
use crate::hir::HirVec;
use crate::hir::{GenericArg, GenericParam, GenericParamKind};
use crate::hir::{GenericBound, PatKind, RangeEnd, TraitBoundModifier};
@ -140,7 +141,7 @@ where
printer.s.eof()
}
pub fn visibility_qualified<S: Into<Cow<'static, str>>>(vis: &hir::Visibility, w: S) -> String {
pub fn visibility_qualified<S: Into<Cow<'static, str>>>(vis: &hir::Visibility<'_>, w: S) -> String {
to_string(NO_ANN, |s| {
s.print_visibility(vis);
s.s.word(w)
@ -266,7 +267,7 @@ impl<'a> State<'a> {
}
}
pub fn print_type(&mut self, ty: &hir::Ty) {
pub fn print_type(&mut self, ty: &hir::Ty<'_>) {
self.maybe_print_comment(ty.span.lo());
self.ibox(0);
match ty.kind {
@ -307,7 +308,7 @@ impl<'a> State<'a> {
}
hir::TyKind::Def(..) => {}
hir::TyKind::Path(ref qpath) => self.print_qpath(qpath, false),
hir::TyKind::TraitObject(ref bounds, ref lifetime) => {
hir::TyKind::TraitObject(bounds, ref lifetime) => {
let mut first = true;
for bound in bounds {
if first {
@ -398,9 +399,9 @@ impl<'a> State<'a> {
fn print_associated_const(
&mut self,
ident: ast::Ident,
ty: &hir::Ty,
ty: &hir::Ty<'_>,
default: Option<hir::BodyId>,
vis: &hir::Visibility,
vis: &hir::Visibility<'_>,
) {
self.s.word(visibility_qualified(vis, ""));
self.word_space("const");
@ -418,8 +419,8 @@ impl<'a> State<'a> {
fn print_associated_type(
&mut self,
ident: ast::Ident,
bounds: Option<&hir::GenericBounds>,
ty: Option<&hir::Ty>,
bounds: Option<hir::GenericBounds<'_>>,
ty: Option<&hir::Ty<'_>>,
) {
self.word_space("type");
self.print_ident(ident);
@ -437,7 +438,7 @@ impl<'a> State<'a> {
fn print_item_type(
&mut self,
item: &hir::Item<'_>,
generics: &hir::Generics,
generics: &hir::Generics<'_>,
inner: impl Fn(&mut Self),
) {
self.head(visibility_qualified(&item.vis, "type"));
@ -682,11 +683,11 @@ impl<'a> State<'a> {
self.ann.post(self, AnnNode::Item(item))
}
pub fn print_trait_ref(&mut self, t: &hir::TraitRef) {
pub fn print_trait_ref(&mut self, t: &hir::TraitRef<'_>) {
self.print_path(&t.path, false)
}
fn print_formal_generic_params(&mut self, generic_params: &[hir::GenericParam]) {
fn print_formal_generic_params(&mut self, generic_params: &[hir::GenericParam<'_>]) {
if !generic_params.is_empty() {
self.s.word("for");
self.print_generic_params(generic_params);
@ -694,7 +695,7 @@ impl<'a> State<'a> {
}
}
fn print_poly_trait_ref(&mut self, t: &hir::PolyTraitRef) {
fn print_poly_trait_ref(&mut self, t: &hir::PolyTraitRef<'_>) {
self.print_formal_generic_params(&t.bound_generic_params);
self.print_trait_ref(&t.trait_ref)
}
@ -702,10 +703,10 @@ impl<'a> State<'a> {
pub fn print_enum_def(
&mut self,
enum_definition: &hir::EnumDef<'_>,
generics: &hir::Generics,
generics: &hir::Generics<'_>,
name: ast::Name,
span: syntax_pos::Span,
visibility: &hir::Visibility,
visibility: &hir::Visibility<'_>,
) {
self.head(visibility_qualified(visibility, "enum"));
self.print_name(name);
@ -730,7 +731,7 @@ impl<'a> State<'a> {
self.bclose(span)
}
pub fn print_visibility(&mut self, vis: &hir::Visibility) {
pub fn print_visibility(&mut self, vis: &hir::Visibility<'_>) {
match vis.node {
hir::VisibilityKind::Public => self.word_nbsp("pub"),
hir::VisibilityKind::Crate(ast::CrateSugar::JustCrate) => self.word_nbsp("crate"),
@ -761,7 +762,7 @@ impl<'a> State<'a> {
pub fn print_struct(
&mut self,
struct_def: &hir::VariantData<'_>,
generics: &hir::Generics,
generics: &hir::Generics<'_>,
name: ast::Name,
span: syntax_pos::Span,
print_finalizer: bool,
@ -822,9 +823,9 @@ impl<'a> State<'a> {
pub fn print_method_sig(
&mut self,
ident: ast::Ident,
m: &hir::FnSig,
generics: &hir::Generics,
vis: &hir::Visibility,
m: &hir::FnSig<'_>,
generics: &hir::Generics<'_>,
vis: &hir::Visibility<'_>,
arg_names: &[ast::Ident],
body_id: Option<hir::BodyId>,
) {
@ -891,7 +892,7 @@ impl<'a> State<'a> {
hir::ImplItemKind::TyAlias(ref ty) => {
self.print_associated_type(ii.ident, None, Some(ty));
}
hir::ImplItemKind::OpaqueTy(ref bounds) => {
hir::ImplItemKind::OpaqueTy(bounds) => {
self.word_space("type");
self.print_ident(ii.ident);
self.print_bounds("= impl", bounds);
@ -1044,7 +1045,7 @@ impl<'a> State<'a> {
fn print_expr_struct(
&mut self,
qpath: &hir::QPath,
qpath: &hir::QPath<'_>,
fields: &[hir::Field<'_>],
wth: &Option<&'hir hir::Expr<'_>>,
) {
@ -1103,7 +1104,7 @@ impl<'a> State<'a> {
self.print_call_post(args)
}
fn print_expr_method_call(&mut self, segment: &hir::PathSegment, args: &[hir::Expr<'_>]) {
fn print_expr_method_call(&mut self, segment: &hir::PathSegment<'_>, args: &[hir::Expr<'_>]) {
let base_args = &args[1..];
self.print_expr_maybe_paren(&args[0], parser::PREC_POSTFIX);
self.s.word(".");
@ -1440,7 +1441,7 @@ impl<'a> State<'a> {
self.print_expr(coll)
}
pub fn print_path(&mut self, path: &hir::Path, colons_before_params: bool) {
pub fn print_path(&mut self, path: &hir::Path<'_>, colons_before_params: bool) {
self.maybe_print_comment(path.span.lo());
for (i, segment) in path.segments.iter().enumerate() {
@ -1458,14 +1459,14 @@ impl<'a> State<'a> {
}
}
pub fn print_path_segment(&mut self, segment: &hir::PathSegment) {
pub fn print_path_segment(&mut self, segment: &hir::PathSegment<'_>) {
if segment.ident.name != kw::PathRoot {
self.print_ident(segment.ident);
self.print_generic_args(segment.generic_args(), segment.infer_args, false);
}
}
pub fn print_qpath(&mut self, qpath: &hir::QPath, colons_before_params: bool) {
pub fn print_qpath(&mut self, qpath: &hir::QPath<'_>, colons_before_params: bool) {
match *qpath {
hir::QPath::Resolved(None, ref path) => self.print_path(path, colons_before_params),
hir::QPath::Resolved(Some(ref qself), ref path) => {
@ -1523,7 +1524,7 @@ impl<'a> State<'a> {
fn print_generic_args(
&mut self,
generic_args: &hir::GenericArgs,
generic_args: &hir::GenericArgs<'_>,
infer_args: bool,
colons_before_params: bool,
) {
@ -1586,7 +1587,7 @@ impl<'a> State<'a> {
self.word_space("=");
self.print_type(ty);
}
hir::TypeBindingKind::Constraint { ref bounds } => {
hir::TypeBindingKind::Constraint { bounds } => {
self.print_bounds(":", bounds);
}
}
@ -1814,11 +1815,11 @@ impl<'a> State<'a> {
pub fn print_fn(
&mut self,
decl: &hir::FnDecl,
decl: &hir::FnDecl<'_>,
header: hir::FnHeader,
name: Option<ast::Name>,
generics: &hir::Generics,
vis: &hir::Visibility,
generics: &hir::Generics<'_>,
vis: &hir::Visibility<'_>,
arg_names: &[ast::Ident],
body_id: Option<hir::BodyId>,
) {
@ -1858,7 +1859,7 @@ impl<'a> State<'a> {
self.print_where_clause(&generics.where_clause)
}
fn print_closure_params(&mut self, decl: &hir::FnDecl, body_id: hir::BodyId) {
fn print_closure_params(&mut self, decl: &hir::FnDecl<'_>, body_id: hir::BodyId) {
self.s.word("|");
let mut i = 0;
self.commasep(Inconsistent, &decl.inputs, |s, ty| {
@ -1903,7 +1904,7 @@ impl<'a> State<'a> {
pub fn print_bounds<'b>(
&mut self,
prefix: &'static str,
bounds: impl IntoIterator<Item = &'b hir::GenericBound>,
bounds: impl IntoIterator<Item = &'b hir::GenericBound<'b>>,
) {
let mut first = true;
for bound in bounds {
@ -1933,7 +1934,7 @@ impl<'a> State<'a> {
}
}
pub fn print_generic_params(&mut self, generic_params: &[GenericParam]) {
pub fn print_generic_params(&mut self, generic_params: &[GenericParam<'_>]) {
if !generic_params.is_empty() {
self.s.word("<");
@ -1943,7 +1944,7 @@ impl<'a> State<'a> {
}
}
pub fn print_generic_param(&mut self, param: &GenericParam) {
pub fn print_generic_param(&mut self, param: &GenericParam<'_>) {
if let GenericParamKind::Const { .. } = param.kind {
self.word_space("const");
}
@ -1953,9 +1954,9 @@ impl<'a> State<'a> {
match param.kind {
GenericParamKind::Lifetime { .. } => {
let mut sep = ":";
for bound in &param.bounds {
for bound in param.bounds {
match bound {
GenericBound::Outlives(lt) => {
GenericBound::Outlives(ref lt) => {
self.s.word(sep);
self.print_lifetime(lt);
sep = "+";
@ -1965,7 +1966,7 @@ impl<'a> State<'a> {
}
}
GenericParamKind::Type { ref default, .. } => {
self.print_bounds(":", &param.bounds);
self.print_bounds(":", param.bounds);
match default {
Some(default) => {
self.s.space();
@ -1986,7 +1987,7 @@ impl<'a> State<'a> {
self.print_ident(lifetime.name.ident())
}
pub fn print_where_clause(&mut self, where_clause: &hir::WhereClause) {
pub fn print_where_clause(&mut self, where_clause: &hir::WhereClause<'_>) {
if where_clause.predicates.is_empty() {
return;
}
@ -2003,7 +2004,7 @@ impl<'a> State<'a> {
&hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate {
ref bound_generic_params,
ref bounded_ty,
ref bounds,
bounds,
..
}) => {
self.print_formal_generic_params(bound_generic_params);
@ -2056,12 +2057,12 @@ impl<'a> State<'a> {
}
}
pub fn print_mt(&mut self, mt: &hir::MutTy, print_const: bool) {
pub fn print_mt(&mut self, mt: &hir::MutTy<'_>, print_const: bool) {
self.print_mutability(mt.mutbl, print_const);
self.print_type(&mt.ty)
}
pub fn print_fn_output(&mut self, decl: &hir::FnDecl) {
pub fn print_fn_output(&mut self, decl: &hir::FnDecl<'_>) {
if let hir::DefaultReturn(..) = decl.output {
return;
}
@ -2085,9 +2086,9 @@ impl<'a> State<'a> {
&mut self,
abi: Abi,
unsafety: hir::Unsafety,
decl: &hir::FnDecl,
decl: &hir::FnDecl<'_>,
name: Option<ast::Name>,
generic_params: &[hir::GenericParam],
generic_params: &[hir::GenericParam<'_>],
arg_names: &[ast::Ident],
) {
self.ibox(INDENT_UNIT);
@ -2096,11 +2097,8 @@ impl<'a> State<'a> {
self.print_generic_params(generic_params);
}
let generics = hir::Generics {
params: hir::HirVec::new(),
where_clause: hir::WhereClause {
predicates: hir::HirVec::new(),
span: syntax_pos::DUMMY_SP,
},
params: HirVec::new(),
where_clause: hir::WhereClause { predicates: &[], span: syntax_pos::DUMMY_SP },
span: syntax_pos::DUMMY_SP,
};
self.print_fn(
@ -2164,7 +2162,7 @@ impl<'a> State<'a> {
}
}
pub fn print_fn_header_info(&mut self, header: hir::FnHeader, vis: &hir::Visibility) {
pub fn print_fn_header_info(&mut self, header: hir::FnHeader, vis: &hir::Visibility<'_>) {
self.s.word(visibility_qualified(vis, ""));
match header.constness {

View file

@ -22,14 +22,6 @@ pub fn P<T: 'static>(value: T) -> P<T> {
P { ptr: box value }
}
impl<T: 'static> P<T> {
// HACK(eddyb) used by HIR lowering in a few places still.
// NOTE: do not make this more public than `pub(super)`.
pub(super) fn into_inner(self) -> T {
*self.ptr
}
}
impl<T: ?Sized> Deref for P<T> {
type Target = T;

View file

@ -73,7 +73,7 @@ impl Visitor<'tcx> for CaptureCollector<'a, 'tcx> {
NestedVisitorMap::None
}
fn visit_path(&mut self, path: &'tcx hir::Path, _: hir::HirId) {
fn visit_path(&mut self, path: &'tcx hir::Path<'tcx>, _: hir::HirId) {
if let Res::Local(var_id) = path.res {
self.visit_local_use(var_id, path.span);
}

View file

@ -106,7 +106,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::ImplItemId {
}
}
impl<'a> HashStable<StableHashingContext<'a>> for hir::Ty {
impl<'a> HashStable<StableHashingContext<'a>> for hir::Ty<'_> {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
hcx.while_hashing_hir_bodies(true, |hcx| {
let hir::Ty { hir_id: _, ref kind, ref span } = *self;
@ -168,7 +168,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::ImplItem<'_> {
}
}
impl<'a> HashStable<StableHashingContext<'a>> for hir::VisibilityKind {
impl<'a> HashStable<StableHashingContext<'a>> for hir::VisibilityKind<'_> {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
mem::discriminant(self).hash_stable(hcx, hasher);
match *self {

View file

@ -107,7 +107,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindLocalByTypeVisitor<'a, 'tcx> {
fn closure_return_type_suggestion(
span: Span,
err: &mut DiagnosticBuilder<'_>,
output: &FunctionRetTy,
output: &FunctionRetTy<'_>,
body: &Body<'_>,
descr: &str,
name: &str,
@ -460,7 +460,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
/// needed, suggest annotating the call, otherwise point out the resulting type of the call.
fn annotate_method_call(
&self,
segment: &hir::PathSegment,
segment: &hir::PathSegment<'_>,
e: &Expr<'_>,
err: &mut DiagnosticBuilder<'_>,
) {

View file

@ -25,7 +25,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
&self,
region: Region<'tcx>,
br: &ty::BoundRegion,
) -> Option<(&hir::Ty, &hir::FnDecl)> {
) -> Option<(&hir::Ty<'_>, &hir::FnDecl<'_>)> {
if let Some(anon_reg) = self.tcx().is_suitable_region(region) {
let def_id = anon_reg.def_id;
if let Some(hir_id) = self.tcx().hir().as_local_hir_id(def_id) {
@ -57,9 +57,9 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
// to the anonymous region.
fn find_component_for_bound_region(
&self,
arg: &'tcx hir::Ty,
arg: &'tcx hir::Ty<'tcx>,
br: &ty::BoundRegion,
) -> Option<&'tcx hir::Ty> {
) -> Option<&'tcx hir::Ty<'tcx>> {
let mut nested_visitor = FindNestedTypeVisitor {
tcx: self.tcx(),
bound_region: *br,
@ -85,7 +85,7 @@ struct FindNestedTypeVisitor<'tcx> {
bound_region: ty::BoundRegion,
// The type where the anonymous lifetime appears
// for e.g., Vec<`&u8`> and <`&u8`>
found_type: Option<&'tcx hir::Ty>,
found_type: Option<&'tcx hir::Ty<'tcx>>,
current_index: ty::DebruijnIndex,
}
@ -94,7 +94,7 @@ impl Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
NestedVisitorMap::OnlyBodies(&self.tcx.hir())
}
fn visit_ty(&mut self, arg: &'tcx hir::Ty) {
fn visit_ty(&mut self, arg: &'tcx hir::Ty<'tcx>) {
match arg.kind {
hir::TyKind::BareFn(_) => {
self.current_index.shift_in(1);
@ -103,7 +103,7 @@ impl Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
return;
}
hir::TyKind::TraitObject(ref bounds, _) => {
hir::TyKind::TraitObject(bounds, _) => {
for bound in bounds {
self.current_index.shift_in(1);
self.visit_poly_trait_ref(bound, hir::TraitBoundModifier::None);
@ -250,7 +250,7 @@ impl Visitor<'tcx> for TyPathVisitor<'tcx> {
}
}
fn visit_ty(&mut self, arg: &'tcx hir::Ty) {
fn visit_ty(&mut self, arg: &'tcx hir::Ty<'tcx>) {
// ignore nested types
//
// If you have a type like `Foo<'a, &Ty>` we

View file

@ -106,7 +106,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
&self,
scope_def_id: DefId,
br: ty::BoundRegion,
decl: &hir::FnDecl,
decl: &hir::FnDecl<'_>,
) -> Option<Span> {
let ret_ty = self.tcx().type_of(scope_def_id);
if let ty::FnDef(_, _) = ret_ty.kind {

View file

@ -452,7 +452,7 @@ pub struct LateContext<'a, 'tcx> {
last_node_with_lint_attrs: hir::HirId,
/// Generic type parameters in scope for the item we are in.
pub generics: Option<&'tcx hir::Generics>,
pub generics: Option<&'tcx hir::Generics<'tcx>>,
/// We are only looking at one module
only_module: bool,
@ -956,7 +956,7 @@ impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> hir_visit::Visitor<'tcx>
fn visit_fn(
&mut self,
fk: hir_visit::FnKind<'tcx>,
decl: &'tcx hir::FnDecl,
decl: &'tcx hir::FnDecl<'tcx>,
body_id: hir::BodyId,
span: Span,
id: hir::HirId,
@ -976,7 +976,7 @@ impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> hir_visit::Visitor<'tcx>
&mut self,
s: &'tcx hir::VariantData<'tcx>,
_: ast::Name,
_: &'tcx hir::Generics,
_: &'tcx hir::Generics<'tcx>,
_: hir::HirId,
_: Span,
) {
@ -995,7 +995,7 @@ impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> hir_visit::Visitor<'tcx>
fn visit_variant(
&mut self,
v: &'tcx hir::Variant<'tcx>,
g: &'tcx hir::Generics,
g: &'tcx hir::Generics<'tcx>,
item_id: hir::HirId,
) {
self.with_lint_attrs(v.id, &v.attrs, |cx| {
@ -1005,7 +1005,7 @@ impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> hir_visit::Visitor<'tcx>
})
}
fn visit_ty(&mut self, t: &'tcx hir::Ty) {
fn visit_ty(&mut self, t: &'tcx hir::Ty<'tcx>) {
lint_callback!(self, check_ty, t);
hir_visit::walk_ty(self, t);
}
@ -1038,22 +1038,26 @@ impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> hir_visit::Visitor<'tcx>
hir_visit::walk_arm(self, a);
}
fn visit_generic_param(&mut self, p: &'tcx hir::GenericParam) {
fn visit_generic_param(&mut self, p: &'tcx hir::GenericParam<'tcx>) {
lint_callback!(self, check_generic_param, p);
hir_visit::walk_generic_param(self, p);
}
fn visit_generics(&mut self, g: &'tcx hir::Generics) {
fn visit_generics(&mut self, g: &'tcx hir::Generics<'tcx>) {
lint_callback!(self, check_generics, g);
hir_visit::walk_generics(self, g);
}
fn visit_where_predicate(&mut self, p: &'tcx hir::WherePredicate) {
fn visit_where_predicate(&mut self, p: &'tcx hir::WherePredicate<'tcx>) {
lint_callback!(self, check_where_predicate, p);
hir_visit::walk_where_predicate(self, p);
}
fn visit_poly_trait_ref(&mut self, t: &'tcx hir::PolyTraitRef, m: hir::TraitBoundModifier) {
fn visit_poly_trait_ref(
&mut self,
t: &'tcx hir::PolyTraitRef<'tcx>,
m: hir::TraitBoundModifier,
) {
lint_callback!(self, check_poly_trait_ref, t, m);
hir_visit::walk_poly_trait_ref(self, t, m);
}
@ -1089,7 +1093,7 @@ impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> hir_visit::Visitor<'tcx>
hir_visit::walk_lifetime(self, lt);
}
fn visit_path(&mut self, p: &'tcx hir::Path, id: hir::HirId) {
fn visit_path(&mut self, p: &'tcx hir::Path<'tcx>, id: hir::HirId) {
lint_callback!(self, check_path, p, id);
hir_visit::walk_path(self, p);
}

View file

@ -76,7 +76,7 @@ declare_lint_pass!(TyTyKind => [
]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyTyKind {
fn check_path(&mut self, cx: &LateContext<'_, '_>, path: &'tcx Path, _: HirId) {
fn check_path(&mut self, cx: &LateContext<'_, '_>, path: &'tcx Path<'tcx>, _: HirId) {
let segments = path.segments.iter().rev().skip(1).rev();
if let Some(last) = segments.last() {
@ -94,7 +94,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyTyKind {
}
}
fn check_ty(&mut self, cx: &LateContext<'_, '_>, ty: &'tcx Ty) {
fn check_ty(&mut self, cx: &LateContext<'_, '_>, ty: &'tcx Ty<'tcx>) {
match &ty.kind {
TyKind::Path(qpath) => {
if let QPath::Resolved(_, path) = qpath {
@ -159,7 +159,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyTyKind {
}
}
fn lint_ty_kind_usage(cx: &LateContext<'_, '_>, segment: &PathSegment) -> bool {
fn lint_ty_kind_usage(cx: &LateContext<'_, '_>, segment: &PathSegment<'_>) -> bool {
if let Some(res) = segment.res {
if let Some(did) = res.opt_def_id() {
return cx.tcx.is_diagnostic_item(sym::TyKind, did);
@ -169,7 +169,7 @@ fn lint_ty_kind_usage(cx: &LateContext<'_, '_>, segment: &PathSegment) -> bool {
false
}
fn is_ty_or_ty_ctxt(cx: &LateContext<'_, '_>, ty: &Ty) -> Option<String> {
fn is_ty_or_ty_ctxt(cx: &LateContext<'_, '_>, ty: &Ty<'_>) -> Option<String> {
match &ty.kind {
TyKind::Path(qpath) => {
if let QPath::Resolved(_, path) = qpath {
@ -187,7 +187,7 @@ fn is_ty_or_ty_ctxt(cx: &LateContext<'_, '_>, ty: &Ty) -> Option<String> {
None
}
fn gen_args(segment: &PathSegment) -> String {
fn gen_args(segment: &PathSegment<'_>) -> String {
if let Some(args) = &segment.args {
let lifetimes = args
.args

View file

@ -107,20 +107,20 @@ macro_rules! late_lint_methods {
fn check_pat(a: &$hir hir::Pat<$hir>);
fn check_expr(a: &$hir hir::Expr<$hir>);
fn check_expr_post(a: &$hir hir::Expr<$hir>);
fn check_ty(a: &$hir hir::Ty);
fn check_generic_param(a: &$hir hir::GenericParam);
fn check_generics(a: &$hir hir::Generics);
fn check_where_predicate(a: &$hir hir::WherePredicate);
fn check_poly_trait_ref(a: &$hir hir::PolyTraitRef, b: hir::TraitBoundModifier);
fn check_ty(a: &$hir hir::Ty<$hir>);
fn check_generic_param(a: &$hir hir::GenericParam<$hir>);
fn check_generics(a: &$hir hir::Generics<$hir>);
fn check_where_predicate(a: &$hir hir::WherePredicate<$hir>);
fn check_poly_trait_ref(a: &$hir hir::PolyTraitRef<$hir>, b: hir::TraitBoundModifier);
fn check_fn(
a: hir::intravisit::FnKind<$hir>,
b: &$hir hir::FnDecl,
b: &$hir hir::FnDecl<$hir>,
c: &$hir hir::Body<$hir>,
d: Span,
e: hir::HirId);
fn check_fn_post(
a: hir::intravisit::FnKind<$hir>,
b: &$hir hir::FnDecl,
b: &$hir hir::FnDecl<$hir>,
c: &$hir hir::Body<$hir>,
d: Span,
e: hir::HirId
@ -135,7 +135,7 @@ macro_rules! late_lint_methods {
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_path(a: &$hir hir::Path<$hir>, b: hir::HirId);
fn check_attribute(a: &$hir ast::Attribute);
/// Called when entering a syntax node that can have lint attributes such
@ -643,7 +643,7 @@ impl intravisit::Visitor<'tcx> for LintLevelMapBuilder<'_, 'tcx> {
fn visit_variant(
&mut self,
v: &'tcx hir::Variant<'tcx>,
g: &'tcx hir::Generics,
g: &'tcx hir::Generics<'tcx>,
item_id: hir::HirId,
) {
self.with_lint_attrs(v.id, &v.attrs, |builder| {

View file

@ -8,7 +8,6 @@
use crate::hir::def::{DefKind, Res};
use crate::hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
use crate::hir::map::Map;
use crate::hir::ptr::P;
use crate::hir::{GenericArg, GenericParam, ItemLocalId, LifetimeName, Node, ParamName, QPath};
use crate::ty::{self, DefIdTree, GenericParamDefKind, TyCtxt};
@ -44,7 +43,7 @@ pub enum LifetimeDefOrigin {
}
impl LifetimeDefOrigin {
fn from_param(param: &GenericParam) -> Self {
fn from_param(param: &GenericParam<'_>) -> Self {
match param.kind {
GenericParamKind::Lifetime { kind } => match kind {
LifetimeParamKind::InBand => LifetimeDefOrigin::InBand,
@ -74,7 +73,7 @@ pub enum Region {
}
impl Region {
fn early(hir_map: &Map<'_>, index: &mut u32, param: &GenericParam) -> (ParamName, Region) {
fn early(hir_map: &Map<'_>, index: &mut u32, param: &GenericParam<'_>) -> (ParamName, Region) {
let i = *index;
*index += 1;
let def_id = hir_map.local_def_id(param.hir_id);
@ -83,7 +82,7 @@ impl Region {
(param.name.modern(), Region::EarlyBound(i, def_id, origin))
}
fn late(hir_map: &Map<'_>, param: &GenericParam) -> (ParamName, Region) {
fn late(hir_map: &Map<'_>, param: &GenericParam<'_>) -> (ParamName, Region) {
let depth = ty::INNERMOST;
let def_id = hir_map.local_def_id(param.hir_id);
let origin = LifetimeDefOrigin::from_param(param);
@ -517,7 +516,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
}
}
fn visit_ty(&mut self, ty: &'tcx hir::Ty) {
fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) {
debug!("visit_ty: id={:?} ty={:?}", ty.hir_id, ty);
debug!("visit_ty: ty.kind={:?}", ty.kind);
match ty.kind {
@ -549,7 +548,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
});
self.is_in_fn_syntax = was_in_fn_syntax;
}
hir::TyKind::TraitObject(ref bounds, ref lifetime) => {
hir::TyKind::TraitObject(bounds, ref lifetime) => {
debug!("visit_ty: TraitObject(bounds={:?}, lifetime={:?})", bounds, lifetime);
for bound in bounds {
self.visit_poly_trait_ref(bound, hir::TraitBoundModifier::None);
@ -590,7 +589,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
};
self.with(scope, |_, this| this.visit_ty(&mt.ty));
}
hir::TyKind::Def(item_id, ref lifetimes) => {
hir::TyKind::Def(item_id, lifetimes) => {
// Resolve the lifetimes in the bounds to the lifetime defs in the generics.
// `fn foo<'a>() -> impl MyTrait<'a> { ... }` desugars to
// `type MyAnonTy<'b> = impl MyTrait<'b>;`
@ -604,7 +603,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
return;
}
// RPIT (return position impl trait)
hir::ItemKind::OpaqueTy(hir::OpaqueTy { ref generics, ref bounds, .. }) => {
hir::ItemKind::OpaqueTy(hir::OpaqueTy { ref generics, bounds, .. }) => {
(generics, bounds)
}
ref i => bug!("`impl Trait` pointed to non-opaque type?? {:#?}", i),
@ -738,7 +737,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|this| intravisit::walk_trait_item(this, trait_item),
);
}
Type(ref bounds, ref ty) => {
Type(bounds, ref ty) => {
let generics = &trait_item.generics;
let mut index = self.next_early_index();
debug!("visit_ty: index = {}", index);
@ -823,7 +822,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
this.visit_ty(ty);
});
}
OpaqueTy(ref bounds) => {
OpaqueTy(bounds) => {
let generics = &impl_item.generics;
let mut index = self.next_early_index();
let mut next_early_index = index;
@ -881,7 +880,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
self.resolve_lifetime_ref(lifetime_ref);
}
fn visit_path(&mut self, path: &'tcx hir::Path, _: hir::HirId) {
fn visit_path(&mut self, path: &'tcx hir::Path<'tcx>, _: hir::HirId) {
for (i, segment) in path.segments.iter().enumerate() {
let depth = path.segments.len() - i - 1;
if let Some(ref args) = segment.args {
@ -890,7 +889,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
}
}
fn visit_fn_decl(&mut self, fd: &'tcx hir::FnDecl) {
fn visit_fn_decl(&mut self, fd: &'tcx hir::FnDecl<'tcx>) {
let output = match fd.output {
hir::DefaultReturn(_) => None,
hir::Return(ref ty) => Some(&**ty),
@ -898,28 +897,28 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
self.visit_fn_like_elision(&fd.inputs, output);
}
fn visit_generics(&mut self, generics: &'tcx hir::Generics) {
fn visit_generics(&mut self, generics: &'tcx hir::Generics<'tcx>) {
check_mixed_explicit_and_in_band_defs(self.tcx, &generics.params);
for param in &generics.params {
match param.kind {
GenericParamKind::Lifetime { .. } => {}
GenericParamKind::Type { ref default, .. } => {
walk_list!(self, visit_param_bound, &param.bounds);
walk_list!(self, visit_param_bound, param.bounds);
if let Some(ref ty) = default {
self.visit_ty(&ty);
}
}
GenericParamKind::Const { ref ty, .. } => {
walk_list!(self, visit_param_bound, &param.bounds);
walk_list!(self, visit_param_bound, param.bounds);
self.visit_ty(&ty);
}
}
}
for predicate in &generics.where_clause.predicates {
for predicate in generics.where_clause.predicates {
match predicate {
&hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate {
ref bounded_ty,
ref bounds,
bounds,
ref bound_generic_params,
..
}) => {
@ -956,7 +955,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
}
&hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
ref lifetime,
ref bounds,
bounds,
..
}) => {
self.visit_lifetime(lifetime);
@ -976,7 +975,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
fn visit_poly_trait_ref(
&mut self,
trait_ref: &'tcx hir::PolyTraitRef,
trait_ref: &'tcx hir::PolyTraitRef<'tcx>,
_modifier: hir::TraitBoundModifier,
) {
debug!("visit_poly_trait_ref(trait_ref={:?})", trait_ref);
@ -1014,7 +1013,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
};
self.with(scope, |old_scope, this| {
this.check_lifetime_params(old_scope, &trait_ref.bound_generic_params);
walk_list!(this, visit_generic_param, &trait_ref.bound_generic_params);
walk_list!(this, visit_generic_param, trait_ref.bound_generic_params);
this.visit_trait_ref(&trait_ref.trait_ref)
})
} else {
@ -1046,7 +1045,7 @@ fn shadower_label(span: Span) -> Shadower {
fn original_lifetime(span: Span) -> Original {
Original { kind: ShadowKind::Lifetime, span: span }
}
fn shadower_lifetime(param: &hir::GenericParam) -> Shadower {
fn shadower_lifetime(param: &hir::GenericParam<'_>) -> Shadower {
Shadower { kind: ShadowKind::Lifetime, span: param.span }
}
@ -1059,7 +1058,7 @@ impl ShadowKind {
}
}
fn check_mixed_explicit_and_in_band_defs(tcx: TyCtxt<'_>, params: &P<[hir::GenericParam]>) {
fn check_mixed_explicit_and_in_band_defs(tcx: TyCtxt<'_>, params: &[hir::GenericParam<'_>]) {
let lifetime_params: Vec<_> = params
.iter()
.filter_map(|param| match param.kind {
@ -1252,9 +1251,9 @@ fn compute_object_lifetime_defaults(tcx: TyCtxt<'_>) -> HirIdMap<Vec<ObjectLifet
/// for each type parameter.
fn object_lifetime_defaults_for_item(
tcx: TyCtxt<'_>,
generics: &hir::Generics,
generics: &hir::Generics<'_>,
) -> Vec<ObjectLifetimeDefault> {
fn add_bounds(set: &mut Set1<hir::LifetimeName>, bounds: &[hir::GenericBound]) {
fn add_bounds(set: &mut Set1<hir::LifetimeName>, bounds: &[hir::GenericBound<'_>]) {
for bound in bounds {
if let hir::GenericBound::Outlives(ref lifetime) = *bound {
set.insert(lifetime.name.modern());
@ -1273,7 +1272,7 @@ fn object_lifetime_defaults_for_item(
add_bounds(&mut set, &param.bounds);
let param_def_id = tcx.hir().local_def_id(param.hir_id);
for predicate in &generics.where_clause.predicates {
for predicate in generics.where_clause.predicates {
// Look for `type: ...` where clauses.
let data = match *predicate {
hir::WherePredicate::BoundPredicate(ref data) => data,
@ -1368,7 +1367,11 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
/// helper method to determine the span to remove when suggesting the
/// deletion of a lifetime
fn lifetime_deletion_span(&self, name: ast::Ident, generics: &hir::Generics) -> Option<Span> {
fn lifetime_deletion_span(
&self,
name: ast::Ident,
generics: &hir::Generics<'_>,
) -> Option<Span> {
generics.params.iter().enumerate().find_map(|(i, param)| {
if param.name.ident() == name {
let mut in_band = false;
@ -1417,7 +1420,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
let mut remove_use = None;
let mut elide_use = None;
let mut find_arg_use_span = |inputs: &hir::HirVec<hir::Ty>| {
let mut find_arg_use_span = |inputs: &[hir::Ty<'_>]| {
for input in inputs {
match input.kind {
hir::TyKind::Rptr(lt, _) => {
@ -1459,12 +1462,12 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
match parent {
Node::Item(item) => {
if let hir::ItemKind::Fn(sig, _, _) = &item.kind {
find_arg_use_span(&sig.decl.inputs);
find_arg_use_span(sig.decl.inputs);
}
}
Node::ImplItem(impl_item) => {
if let hir::ImplItemKind::Method(sig, _) = &impl_item.kind {
find_arg_use_span(&sig.decl.inputs);
find_arg_use_span(sig.decl.inputs);
}
}
_ => {}
@ -1656,8 +1659,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
fn visit_early_late<F>(
&mut self,
parent_id: Option<hir::HirId>,
decl: &'tcx hir::FnDecl,
generics: &'tcx hir::Generics,
decl: &'tcx hir::FnDecl<'tcx>,
generics: &'tcx hir::Generics<'tcx>,
walk: F,
) where
F: for<'b, 'c> FnOnce(&'b mut LifetimeContext<'c, 'tcx>),
@ -1854,7 +1857,12 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
}
}
fn visit_segment_args(&mut self, res: Res, depth: usize, generic_args: &'tcx hir::GenericArgs) {
fn visit_segment_args(
&mut self,
res: Res,
depth: usize,
generic_args: &'tcx hir::GenericArgs<'tcx>,
) {
debug!(
"visit_segment_args(res={:?}, depth={:?}, generic_args={:?})",
res, depth, generic_args,
@ -2036,7 +2044,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
});
// Resolve lifetimes found in the type `XX` from `Item = XX` bindings.
for b in &generic_args.bindings {
for b in generic_args.bindings {
let scope = Scope::ObjectLifetimeDefault {
lifetime: if has_lifetime_parameter { None } else { Some(Region::Static) },
s: self.scope,
@ -2045,7 +2053,11 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
}
}
fn visit_fn_like_elision(&mut self, inputs: &'tcx [hir::Ty], output: Option<&'tcx hir::Ty>) {
fn visit_fn_like_elision(
&mut self,
inputs: &'tcx [hir::Ty<'tcx>],
output: Option<&'tcx hir::Ty<'tcx>>,
) {
debug!("visit_fn_like_elision: enter");
let mut arg_elide = Elide::FreshLateAnon(Cell::new(0));
let arg_scope = Scope::Elision { elide: arg_elide.clone(), s: self.scope };
@ -2125,7 +2137,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
if has_self {
struct SelfVisitor<'a> {
map: &'a NamedRegionMap,
impl_self: Option<&'a hir::TyKind>,
impl_self: Option<&'a hir::TyKind<'a>>,
lifetime: Set1<Region>,
}
@ -2163,7 +2175,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
NestedVisitorMap::None
}
fn visit_ty(&mut self, ty: &'a hir::Ty) {
fn visit_ty(&mut self, ty: &'a hir::Ty<'a>) {
if let hir::TyKind::Rptr(lifetime_ref, ref mt) = ty.kind {
if let hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) = mt.ty.kind
{
@ -2251,12 +2263,12 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
NestedVisitorMap::None
}
fn visit_ty(&mut self, ty: &hir::Ty) {
fn visit_ty(&mut self, ty: &hir::Ty<'_>) {
if let hir::TyKind::BareFn(_) = ty.kind {
self.outer_index.shift_in(1);
}
match ty.kind {
hir::TyKind::TraitObject(ref bounds, ref lifetime) => {
hir::TyKind::TraitObject(bounds, ref lifetime) => {
for bound in bounds {
self.visit_poly_trait_ref(bound, hir::TraitBoundModifier::None);
}
@ -2276,7 +2288,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
}
}
fn visit_generic_param(&mut self, param: &hir::GenericParam) {
fn visit_generic_param(&mut self, param: &hir::GenericParam<'_>) {
if let hir::GenericParamKind::Lifetime { .. } = param.kind {
// FIXME(eddyb) Do we want this? It only makes a difference
// if this `for<'a>` lifetime parameter is never used.
@ -2288,7 +2300,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
fn visit_poly_trait_ref(
&mut self,
trait_ref: &hir::PolyTraitRef,
trait_ref: &hir::PolyTraitRef<'_>,
modifier: hir::TraitBoundModifier,
) {
self.outer_index.shift_in(1);
@ -2523,7 +2535,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
fn check_lifetime_params(
&mut self,
old_scope: ScopeRef<'_>,
params: &'tcx [hir::GenericParam],
params: &'tcx [hir::GenericParam<'tcx>],
) {
let lifetimes: Vec<_> = params
.iter()
@ -2570,9 +2582,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
// It is a soft error to shadow a lifetime within a parent scope.
self.check_lifetime_param_for_shadowing(old_scope, &lifetime_i);
for bound in &lifetime_i.bounds {
for bound in lifetime_i.bounds {
match bound {
hir::GenericBound::Outlives(lt) => match lt.name {
hir::GenericBound::Outlives(ref lt) => match lt.name {
hir::LifetimeName::Underscore => self.tcx.sess.delay_span_bug(
lt.span,
"use of `'_` in illegal place, but not caught by lowering",
@ -2617,7 +2629,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
fn check_lifetime_param_for_shadowing(
&self,
mut old_scope: ScopeRef<'_>,
param: &'tcx hir::GenericParam,
param: &'tcx hir::GenericParam<'tcx>,
) {
for label in &self.labels_in_fn {
// FIXME (#24278): non-hygienic comparison
@ -2755,13 +2767,13 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
/// T as Trait<''b>>::Foo` does not constrain `'a` or `'b`.
fn insert_late_bound_lifetimes(
map: &mut NamedRegionMap,
decl: &hir::FnDecl,
generics: &hir::Generics,
decl: &hir::FnDecl<'_>,
generics: &hir::Generics<'_>,
) {
debug!("insert_late_bound_lifetimes(decl={:?}, generics={:?})", decl, generics);
let mut constrained_by_input = ConstrainedCollector::default();
for arg_ty in &decl.inputs {
for arg_ty in decl.inputs {
constrained_by_input.visit_ty(arg_ty);
}
@ -2840,7 +2852,7 @@ fn insert_late_bound_lifetimes(
NestedVisitorMap::None
}
fn visit_ty(&mut self, ty: &'v hir::Ty) {
fn visit_ty(&mut self, ty: &'v hir::Ty<'v>) {
match ty.kind {
hir::TyKind::Path(hir::QPath::Resolved(Some(_), _))
| hir::TyKind::Path(hir::QPath::TypeRelative(..)) => {

View file

@ -306,7 +306,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
});
}
fn visit_variant(&mut self, var: &'tcx Variant<'tcx>, g: &'tcx Generics, item_id: HirId) {
fn visit_variant(&mut self, var: &'tcx Variant<'tcx>, g: &'tcx Generics<'tcx>, 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() {
v.annotate(ctor_hir_id, &var.attrs, var.span, AnnotationKind::Required, |_| {});
@ -381,7 +381,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> {
intravisit::walk_impl_item(self, ii);
}
fn visit_variant(&mut self, var: &'tcx Variant<'tcx>, g: &'tcx Generics, item_id: HirId) {
fn visit_variant(&mut self, var: &'tcx Variant<'tcx>, g: &'tcx Generics<'tcx>, item_id: HirId) {
self.check_missing_stability(var.id, var.span, "variant");
intravisit::walk_variant(self, var, g, item_id);
}
@ -886,7 +886,7 @@ impl Visitor<'tcx> for Checker<'tcx> {
intravisit::walk_item(self, item);
}
fn visit_path(&mut self, path: &'tcx hir::Path, id: hir::HirId) {
fn visit_path(&mut self, path: &'tcx hir::Path<'tcx>, id: hir::HirId) {
if let Some(def_id) = path.res.opt_def_id() {
self.tcx.check_stability(def_id, Some(id), path.span)
}

View file

@ -1154,7 +1154,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
};
let suggest_restriction =
|generics: &hir::Generics, msg, err: &mut DiagnosticBuilder<'_>| {
|generics: &hir::Generics<'_>, msg, err: &mut DiagnosticBuilder<'_>| {
let span = generics.where_clause.span_for_predicates_or_empty_place();
if !span.from_expansion() && span.desugaring_kind().is_none() {
err.span_suggestion(
@ -2851,7 +2851,7 @@ impl ArgKind {
/// Suggest restricting a type param with a new bound.
pub fn suggest_constraining_type_param(
generics: &hir::Generics,
generics: &hir::Generics<'_>,
err: &mut DiagnosticBuilder<'_>,
param_name: &str,
constraint: &str,

View file

@ -464,7 +464,7 @@ impl<'tcx> TypeckTables<'tcx> {
}
/// Returns the final resolution of a `QPath` in an `Expr` or `Pat` node.
pub fn qpath_res(&self, qpath: &hir::QPath, id: hir::HirId) -> Res {
pub fn qpath_res(&self, qpath: &hir::QPath<'_>, id: hir::HirId) -> Res {
match *qpath {
hir::QPath::Resolved(_, ref path) => path.res,
hir::QPath::TypeRelative(..) => self

View file

@ -298,7 +298,7 @@ impl<'tcx> DefIdTree for TyCtxt<'tcx> {
}
impl Visibility {
pub fn from_hir(visibility: &hir::Visibility, id: hir::HirId, tcx: TyCtxt<'_>) -> Self {
pub fn from_hir(visibility: &hir::Visibility<'_>, id: hir::HirId, tcx: TyCtxt<'_>) -> Self {
match visibility.node {
hir::VisibilityKind::Public => Visibility::Public,
hir::VisibilityKind::Crate(_) => Visibility::Restricted(DefId::local(CRATE_DEF_INDEX)),
@ -2757,7 +2757,7 @@ impl<'tcx> TyCtxt<'tcx> {
fn associated_item_from_trait_item_ref(
self,
parent_def_id: DefId,
parent_vis: &hir::Visibility,
parent_vis: &hir::Visibility<'_>,
trait_item_ref: &hir::TraitItemRef,
) -> AssocItem {
let def_id = self.hir().local_def_id(trait_item_ref.id.hir_id);
@ -2783,7 +2783,7 @@ impl<'tcx> TyCtxt<'tcx> {
fn associated_item_from_impl_item_ref(
self,
parent_def_id: DefId,
impl_item_ref: &hir::ImplItemRef,
impl_item_ref: &hir::ImplItemRef<'_>,
) -> AssocItem {
let def_id = self.hir().local_def_id(impl_item_ref.id.hir_id);
let (kind, has_self) = match impl_item_ref.kind {

View file

@ -694,7 +694,7 @@ pub fn object_region_bounds<'tcx>(
/// Find the span of a generic bound affecting an associated type.
fn get_generic_bound_spans(
generics: &hir::Generics,
generics: &hir::Generics<'_>,
trait_name: Option<&Ident>,
assoc_item_name: Ident,
) -> Vec<Span> {
@ -729,7 +729,7 @@ fn get_generic_bound_spans(
bounds
}
fn is_self_path(kind: &hir::TyKind) -> bool {
fn is_self_path(kind: &hir::TyKind<'_>) -> bool {
match kind {
hir::TyKind::Path(hir::QPath::Resolved(None, path)) => {
let mut s = path.segments.iter();

View file

@ -987,7 +987,7 @@ impl UnreachablePub {
cx: &LateContext<'_, '_>,
what: &str,
id: hir::HirId,
vis: &hir::Visibility,
vis: &hir::Visibility<'_>,
span: Span,
exportable: bool,
) {
@ -1069,7 +1069,7 @@ declare_lint_pass!(
);
impl TypeAliasBounds {
fn is_type_variable_assoc(qpath: &hir::QPath) -> bool {
fn is_type_variable_assoc(qpath: &hir::QPath<'_>) -> bool {
match *qpath {
hir::QPath::TypeRelative(ref ty, _) => {
// If this is a type variable, we found a `T::Assoc`.
@ -1085,7 +1085,7 @@ impl TypeAliasBounds {
}
}
fn suggest_changing_assoc_types(ty: &hir::Ty, err: &mut DiagnosticBuilder<'_>) {
fn suggest_changing_assoc_types(ty: &hir::Ty<'_>, err: &mut DiagnosticBuilder<'_>) {
// Access to associates types should use `<T as Bound>::Assoc`, which does not need a
// bound. Let's see if this type does that.
@ -1099,7 +1099,7 @@ impl TypeAliasBounds {
intravisit::NestedVisitorMap::None
}
fn visit_qpath(&mut self, qpath: &'v hir::QPath, id: hir::HirId, span: Span) {
fn visit_qpath(&mut self, qpath: &'v hir::QPath<'v>, id: hir::HirId, span: Span) {
if TypeAliasBounds::is_type_variable_assoc(qpath) {
self.err.span_help(
span,
@ -1537,7 +1537,7 @@ impl ExplicitOutlivesRequirements {
fn collect_outlived_lifetimes<'tcx>(
&self,
param: &'tcx hir::GenericParam,
param: &'tcx hir::GenericParam<'tcx>,
tcx: TyCtxt<'tcx>,
inferred_outlives: &'tcx [(ty::Predicate<'tcx>, Span)],
ty_generics: &'tcx ty::Generics,
@ -1558,7 +1558,7 @@ impl ExplicitOutlivesRequirements {
fn collect_outlives_bound_spans<'tcx>(
&self,
tcx: TyCtxt<'tcx>,
bounds: &hir::GenericBounds,
bounds: &hir::GenericBounds<'_>,
inferred_outlives: &[ty::Region<'tcx>],
infer_static: bool,
) -> Vec<(usize, Span)> {
@ -1589,7 +1589,7 @@ impl ExplicitOutlivesRequirements {
fn consolidate_outlives_bound_spans(
&self,
lo: Span,
bounds: &hir::GenericBounds,
bounds: &hir::GenericBounds<'_>,
bound_spans: Vec<(usize, Span)>,
) -> Vec<Span> {
if bounds.is_empty() {

View file

@ -293,7 +293,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
}
}
fn check_generic_param(&mut self, cx: &LateContext<'_, '_>, param: &hir::GenericParam) {
fn check_generic_param(&mut self, cx: &LateContext<'_, '_>, param: &hir::GenericParam<'_>) {
if let GenericParamKind::Lifetime { .. } = param.kind {
self.check_snake_case(cx, "lifetime", &param.name.ident());
}
@ -303,7 +303,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
&mut self,
cx: &LateContext<'_, '_>,
fk: FnKind<'_>,
_: &hir::FnDecl,
_: &hir::FnDecl<'_>,
_: &hir::Body<'_>,
_: Span,
id: hir::HirId,
@ -336,7 +336,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
}
fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::TraitItem<'_>) {
if let hir::TraitItemKind::Method(_, hir::TraitMethod::Required(pnames)) = &item.kind {
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 {
self.check_snake_case(cx, "variable", param_name);
@ -425,7 +425,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals {
}
}
fn check_generic_param(&mut self, cx: &LateContext<'_, '_>, param: &hir::GenericParam) {
fn check_generic_param(&mut self, cx: &LateContext<'_, '_>, param: &hir::GenericParam<'_>) {
if let GenericParamKind::Const { .. } = param.kind {
NonUpperCaseGlobals::check_upper_case(cx, "const parameter", &param.name.ident());
}

View file

@ -963,12 +963,12 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
}
}
fn check_foreign_fn(&mut self, id: hir::HirId, decl: &hir::FnDecl) {
fn check_foreign_fn(&mut self, id: hir::HirId, decl: &hir::FnDecl<'_>) {
let def_id = self.cx.tcx.hir().local_def_id(id);
let sig = self.cx.tcx.fn_sig(def_id);
let sig = self.cx.tcx.erase_late_bound_regions(&sig);
for (input_ty, input_hir) in sig.inputs().iter().zip(&decl.inputs) {
for (input_ty, input_hir) in sig.inputs().iter().zip(decl.inputs) {
self.check_type_for_ffi_and_report_errors(input_hir.span, input_ty, false);
}

View file

@ -664,7 +664,7 @@ impl EncodeContext<'tcx> {
id: hir::HirId,
md: &hir::Mod<'_>,
attrs: &[ast::Attribute],
vis: &hir::Visibility,
vis: &hir::Visibility<'_>,
) {
let tcx = self.tcx;
let def_id = tcx.hir().local_def_id(id);
@ -1547,7 +1547,7 @@ impl Visitor<'tcx> for EncodeContext<'tcx> {
let def_id = self.tcx.hir().local_def_id(ni.hir_id);
self.encode_info_for_foreign_item(def_id, ni);
}
fn visit_generics(&mut self, generics: &'tcx hir::Generics) {
fn visit_generics(&mut self, generics: &'tcx hir::Generics<'tcx>) {
intravisit::walk_generics(self, generics);
self.encode_info_for_generics(generics);
}
@ -1568,7 +1568,7 @@ impl EncodeContext<'tcx> {
}
}
fn encode_info_for_generics(&mut self, generics: &hir::Generics) {
fn encode_info_for_generics(&mut self, generics: &hir::Generics<'tcx>) {
for param in &generics.params {
let def_id = self.tcx.hir().local_def_id(param.hir_id);
match param.kind {

View file

@ -410,7 +410,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
) -> Option<RegionName> {
let mir_hir_id = infcx.tcx.hir().as_local_hir_id(mir_def_id)?;
let fn_decl = infcx.tcx.hir().fn_decl_by_hir_id(mir_hir_id)?;
let argument_hir_ty: &hir::Ty = fn_decl.inputs.get(argument_index)?;
let argument_hir_ty: &hir::Ty<'_> = fn_decl.inputs.get(argument_index)?;
match argument_hir_ty.kind {
// This indicates a variable with no type annotation, like
// `|x|`... in that case, we can't highlight the type but
@ -504,10 +504,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
tcx: TyCtxt<'tcx>,
needle_fr: RegionVid,
argument_ty: Ty<'tcx>,
argument_hir_ty: &hir::Ty,
argument_hir_ty: &hir::Ty<'_>,
renctx: &mut RegionErrorNamingCtx,
) -> Option<RegionName> {
let search_stack: &mut Vec<(Ty<'tcx>, &hir::Ty)> =
let search_stack: &mut Vec<(Ty<'tcx>, &hir::Ty<'_>)> =
&mut vec![(argument_ty, argument_hir_ty)];
while let Some((ty, hir_ty)) = search_stack.pop() {
@ -570,7 +570,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// just worry about trying to match up the rustc type
// with the HIR types:
(ty::Tuple(elem_tys), hir::TyKind::Tup(elem_hir_tys)) => {
search_stack.extend(elem_tys.iter().map(|k| k.expect_ty()).zip(elem_hir_tys));
search_stack.extend(elem_tys.iter().map(|k| k.expect_ty()).zip(*elem_hir_tys));
}
(ty::Slice(elem_ty), hir::TyKind::Slice(elem_hir_ty))
@ -600,9 +600,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
&self,
substs: SubstsRef<'tcx>,
needle_fr: RegionVid,
last_segment: &'hir hir::PathSegment,
last_segment: &'hir hir::PathSegment<'hir>,
renctx: &mut RegionErrorNamingCtx,
search_stack: &mut Vec<(Ty<'tcx>, &'hir hir::Ty)>,
search_stack: &mut Vec<(Ty<'tcx>, &'hir hir::Ty<'hir>)>,
) -> Option<RegionName> {
// Did the user give explicit arguments? (e.g., `Foo<..>`)
let args = last_segment.args.as_ref()?;
@ -647,8 +647,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
&self,
substs: SubstsRef<'tcx>,
needle_fr: RegionVid,
args: &'hir hir::GenericArgs,
search_stack: &mut Vec<(Ty<'tcx>, &'hir hir::Ty)>,
args: &'hir hir::GenericArgs<'hir>,
search_stack: &mut Vec<(Ty<'tcx>, &'hir hir::Ty<'hir>)>,
) -> Option<&'hir hir::Lifetime> {
for (kind, hir_arg) in substs.iter().zip(&args.args) {
match (kind.unpack(), hir_arg) {

View file

@ -255,7 +255,7 @@ fn const_not_var(
err: &mut DiagnosticBuilder<'_>,
tcx: TyCtxt<'_>,
pat: &Pat<'_>,
path: &hir::Path,
path: &hir::Path<'_>,
) {
let descr = path.res.descr();
err.span_label(

View file

@ -732,7 +732,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
/// Takes a HIR Path. If the path is a constant, evaluates it and feeds
/// it to `const_to_pat`. Any other path (like enum variants without fields)
/// is converted to the corresponding pattern via `lower_variant_or_leaf`.
fn lower_path(&mut self, qpath: &hir::QPath, id: hir::HirId, span: Span) -> Pat<'tcx> {
fn lower_path(&mut self, qpath: &hir::QPath<'_>, id: hir::HirId, span: Span) -> Pat<'tcx> {
let ty = self.tables.node_type(id);
let res = self.tables.qpath_res(qpath, id);
let is_associated_const = match res {

View file

@ -77,7 +77,7 @@ fn mir_keys(tcx: TyCtxt<'_>, krate: CrateNum) -> &DefIdSet {
&mut self,
v: &'tcx hir::VariantData<'tcx>,
_: ast::Name,
_: &'tcx hir::Generics,
_: &'tcx hir::Generics<'tcx>,
_: hir::HirId,
_: Span,
) {

View file

@ -229,7 +229,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
&mut self,
def: &'tcx hir::VariantData<'tcx>,
_: ast::Name,
_: &hir::Generics,
_: &hir::Generics<'_>,
_: hir::HirId,
_: syntax_pos::Span,
) {
@ -295,12 +295,12 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
self.in_pat = false;
}
fn visit_path(&mut self, path: &'tcx hir::Path, _: hir::HirId) {
fn visit_path(&mut self, path: &'tcx hir::Path<'tcx>, _: hir::HirId) {
self.handle_res(path.res);
intravisit::walk_path(self, path);
}
fn visit_ty(&mut self, ty: &'tcx hir::Ty) {
fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) {
match ty.kind {
TyKind::Def(item_id, _) => {
let item = self.tcx.hir().expect_item(item_id.id);
@ -619,7 +619,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
fn visit_variant(
&mut self,
variant: &'tcx hir::Variant<'tcx>,
g: &'tcx hir::Generics,
g: &'tcx hir::Generics<'tcx>,
id: hir::HirId,
) {
if self.should_warn_about_variant(&variant) {

View file

@ -160,7 +160,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
hir_visit::walk_expr(self, ex)
}
fn visit_ty(&mut self, t: &'v hir::Ty) {
fn visit_ty(&mut self, t: &'v hir::Ty<'v>) {
self.record("Ty", Id::Node(t.hir_id), t);
hir_visit::walk_ty(self, t)
}
@ -168,7 +168,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
fn visit_fn(
&mut self,
fk: hir_visit::FnKind<'v>,
fd: &'v hir::FnDecl,
fd: &'v hir::FnDecl<'v>,
b: hir::BodyId,
s: Span,
id: hir::HirId,
@ -177,7 +177,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
hir_visit::walk_fn(self, fk, fd, b, s, id)
}
fn visit_where_predicate(&mut self, predicate: &'v hir::WherePredicate) {
fn visit_where_predicate(&mut self, predicate: &'v hir::WherePredicate<'v>) {
self.record("WherePredicate", Id::None, predicate);
hir_visit::walk_where_predicate(self, predicate)
}
@ -192,7 +192,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
hir_visit::walk_impl_item(self, ii)
}
fn visit_param_bound(&mut self, bounds: &'v hir::GenericBound) {
fn visit_param_bound(&mut self, bounds: &'v hir::GenericBound<'v>) {
self.record("GenericBound", Id::None, bounds);
hir_visit::walk_param_bound(self, bounds)
}
@ -205,7 +205,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
fn visit_variant(
&mut self,
v: &'v hir::Variant<'v>,
g: &'v hir::Generics,
g: &'v hir::Generics<'v>,
item_id: hir::HirId,
) {
self.record("Variant", Id::None, v);
@ -217,22 +217,22 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
hir_visit::walk_lifetime(self, lifetime)
}
fn visit_qpath(&mut self, qpath: &'v hir::QPath, id: hir::HirId, span: Span) {
fn visit_qpath(&mut self, qpath: &'v hir::QPath<'v>, id: hir::HirId, span: Span) {
self.record("QPath", Id::None, qpath);
hir_visit::walk_qpath(self, qpath, id, span)
}
fn visit_path(&mut self, path: &'v hir::Path, _id: hir::HirId) {
fn visit_path(&mut self, path: &'v hir::Path<'v>, _id: hir::HirId) {
self.record("Path", Id::None, path);
hir_visit::walk_path(self, path)
}
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v hir::PathSegment) {
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v hir::PathSegment<'v>) {
self.record("PathSegment", Id::None, path_segment);
hir_visit::walk_path_segment(self, path_span, path_segment)
}
fn visit_assoc_type_binding(&mut self, type_binding: &'v hir::TypeBinding) {
fn visit_assoc_type_binding(&mut self, type_binding: &'v hir::TypeBinding<'v>) {
self.record("TypeBinding", Id::Node(type_binding.hir_id), type_binding);
hir_visit::walk_assoc_type_binding(self, type_binding)
}

View file

@ -162,7 +162,7 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
fn visit_fn(
&mut self,
fk: FnKind<'tcx>,
fd: &'tcx hir::FnDecl,
fd: &'tcx hir::FnDecl<'tcx>,
b: hir::BodyId,
s: Span,
id: HirId,
@ -351,7 +351,7 @@ impl IrMaps<'tcx> {
fn visit_fn<'tcx>(
ir: &mut IrMaps<'tcx>,
fk: FnKind<'tcx>,
decl: &'tcx hir::FnDecl,
decl: &'tcx hir::FnDecl<'tcx>,
body_id: hir::BodyId,
sp: Span,
id: hir::HirId,
@ -1285,7 +1285,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
fn access_path(
&mut self,
hir_id: HirId,
path: &hir::Path,
path: &hir::Path<'_>,
succ: LiveNode,
acc: u32,
) -> LiveNode {

View file

@ -378,7 +378,7 @@ impl Visitor<'tcx> for PubRestrictedVisitor<'tcx> {
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
NestedVisitorMap::All(&self.tcx.hir())
}
fn visit_vis(&mut self, vis: &'tcx hir::Visibility) {
fn visit_vis(&mut self, vis: &'tcx hir::Visibility<'tcx>) {
self.has_pub_restricted = self.has_pub_restricted || vis.node.is_pub_restricted();
}
}
@ -644,7 +644,10 @@ impl EmbargoVisitor<'tcx> {
///
/// FIXME: This solution won't work with glob imports and doesn't respect
/// namespaces. See <https://github.com/rust-lang/rust/pull/57922#discussion_r251234202>.
fn update_visibility_of_intermediate_use_statements(&mut self, segments: &[hir::PathSegment]) {
fn update_visibility_of_intermediate_use_statements(
&mut self,
segments: &[hir::PathSegment<'_>],
) {
if let Some([module, segment]) = segments.rchunks_exact(2).next() {
if let Some(item) = module
.res
@ -1199,7 +1202,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
self.in_body = orig_in_body;
}
fn visit_ty(&mut self, hir_ty: &'tcx hir::Ty) {
fn visit_ty(&mut self, hir_ty: &'tcx hir::Ty<'tcx>) {
self.span = hir_ty.span;
if self.in_body {
// Types in bodies.
@ -1218,7 +1221,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
intravisit::walk_ty(self, hir_ty);
}
fn visit_trait_ref(&mut self, trait_ref: &'tcx hir::TraitRef) {
fn visit_trait_ref(&mut self, trait_ref: &'tcx hir::TraitRef<'tcx>) {
self.span = trait_ref.path.span;
if !self.in_body {
// Avoid calling `hir_trait_to_predicates` in bodies, it will ICE.
@ -1282,7 +1285,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
// we prohibit access to private statics from other crates, this allows to give
// more code internal visibility at link time. (Access to private functions
// is already prohibited by type privacy for function types.)
fn visit_qpath(&mut self, qpath: &'tcx hir::QPath, id: hir::HirId, span: Span) {
fn visit_qpath(&mut self, qpath: &'tcx hir::QPath<'tcx>, id: hir::HirId, span: Span) {
let def = match self.tables.qpath_res(qpath, id) {
Res::Def(kind, def_id) => Some((kind, def_id)),
_ => None,
@ -1397,7 +1400,7 @@ struct ObsoleteCheckTypeForPrivatenessVisitor<'a, 'b, 'tcx> {
}
impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
fn path_is_private_type(&self, path: &hir::Path) -> bool {
fn path_is_private_type(&self, path: &hir::Path<'_>) -> bool {
let did = match path.res {
Res::PrimTy(..) | Res::SelfTy(..) | Res::Err => return false,
res => res.def_id(),
@ -1423,7 +1426,7 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
self.access_levels.is_public(trait_id)
}
fn check_generic_bound(&mut self, bound: &hir::GenericBound) {
fn check_generic_bound(&mut self, bound: &hir::GenericBound<'_>) {
if let hir::GenericBound::Trait(ref trait_ref, _) = *bound {
if self.path_is_private_type(&trait_ref.trait_ref.path) {
self.old_error_set.insert(trait_ref.trait_ref.hir_ref_id);
@ -1431,7 +1434,7 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
}
}
fn item_is_public(&self, id: &hir::HirId, vis: &hir::Visibility) -> bool {
fn item_is_public(&self, id: &hir::HirId, vis: &hir::Visibility<'_>) -> bool {
self.access_levels.is_reachable(*id) || vis.node.is_pub()
}
}
@ -1441,7 +1444,7 @@ impl<'a, 'b, 'tcx, 'v> Visitor<'v> for ObsoleteCheckTypeForPrivatenessVisitor<'a
NestedVisitorMap::None
}
fn visit_ty(&mut self, ty: &hir::Ty) {
fn visit_ty(&mut self, ty: &hir::Ty<'_>) {
if let hir::TyKind::Path(hir::QPath::Resolved(_, ref path)) = ty.kind {
if self.inner.path_is_private_type(path) {
self.contains_private = true;
@ -1649,13 +1652,13 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
intravisit::walk_item(self, item);
}
fn visit_generics(&mut self, generics: &'tcx hir::Generics) {
fn visit_generics(&mut self, generics: &'tcx hir::Generics<'tcx>) {
for param in &generics.params {
for bound in &param.bounds {
for bound in param.bounds {
self.check_generic_bound(bound);
}
}
for predicate in &generics.where_clause.predicates {
for predicate in generics.where_clause.predicates {
match predicate {
hir::WherePredicate::BoundPredicate(bound_pred) => {
for bound in bound_pred.bounds.iter() {
@ -1676,7 +1679,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
}
}
fn visit_ty(&mut self, t: &'tcx hir::Ty) {
fn visit_ty(&mut self, t: &'tcx hir::Ty<'tcx>) {
if let hir::TyKind::Path(hir::QPath::Resolved(_, ref path)) = t.kind {
if self.path_is_private_type(path) {
self.old_error_set.insert(t.hir_id);
@ -1688,7 +1691,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
fn visit_variant(
&mut self,
v: &'tcx hir::Variant<'tcx>,
g: &'tcx hir::Generics,
g: &'tcx hir::Generics<'tcx>,
item_id: hir::HirId,
) {
if self.access_levels.is_reachable(v.id) {

View file

@ -85,7 +85,7 @@ pub trait AstConv<'tcx> {
&self,
span: Span,
item_def_id: DefId,
item_segment: &hir::PathSegment,
item_segment: &hir::PathSegment<'_>,
poly_trait_ref: ty::PolyTraitRef<'tcx>,
) -> Ty<'tcx>;
@ -114,7 +114,7 @@ struct ConvertedBinding<'a, 'tcx> {
enum ConvertedBindingKind<'a, 'tcx> {
Equality(Ty<'tcx>),
Constraint(&'a [hir::GenericBound]),
Constraint(&'a [hir::GenericBound<'a>]),
}
#[derive(PartialEq)]
@ -186,7 +186,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
&self,
span: Span,
def_id: DefId,
item_segment: &hir::PathSegment,
item_segment: &hir::PathSegment<'_>,
) -> SubstsRef<'tcx> {
let (substs, assoc_bindings, _) = self.create_substs_for_ast_path(
span,
@ -203,7 +203,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}
/// Report error if there is an explicit type parameter when using `impl Trait`.
fn check_impl_trait(tcx: TyCtxt<'_>, seg: &hir::PathSegment, generics: &ty::Generics) -> bool {
fn check_impl_trait(
tcx: TyCtxt<'_>,
seg: &hir::PathSegment<'_>,
generics: &ty::Generics,
) -> bool {
let explicit = !seg.infer_args;
let impl_trait = generics.params.iter().any(|param| match param.kind {
ty::GenericParamDefKind::Type {
@ -248,14 +252,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
tcx: TyCtxt<'_>,
span: Span,
def: &ty::Generics,
seg: &hir::PathSegment,
seg: &hir::PathSegment<'_>,
is_method_call: bool,
) -> bool {
let empty_args = P(hir::GenericArgs {
args: HirVec::new(),
bindings: HirVec::new(),
parenthesized: false,
});
let empty_args =
P(hir::GenericArgs { args: HirVec::new(), bindings: &[], parenthesized: false });
let suppress_mismatch = Self::check_impl_trait(tcx, seg, &def);
Self::check_generic_arg_count(
tcx,
@ -275,7 +276,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
tcx: TyCtxt<'_>,
span: Span,
def: &ty::Generics,
args: &hir::GenericArgs,
args: &hir::GenericArgs<'_>,
position: GenericArgPosition,
has_self: bool,
infer_args: bool,
@ -471,8 +472,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
parent_substs: &[subst::GenericArg<'tcx>],
has_self: bool,
self_ty: Option<Ty<'tcx>>,
args_for_def_id: impl Fn(DefId) -> (Option<&'b GenericArgs>, bool),
provided_kind: impl Fn(&GenericParamDef, &GenericArg) -> subst::GenericArg<'tcx>,
args_for_def_id: impl Fn(DefId) -> (Option<&'b GenericArgs<'b>>, bool),
provided_kind: impl Fn(&GenericParamDef, &GenericArg<'_>) -> subst::GenericArg<'tcx>,
mut inferred_kind: impl FnMut(
Option<&[subst::GenericArg<'tcx>]>,
&GenericParamDef,
@ -619,7 +620,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
span: Span,
def_id: DefId,
parent_substs: &[subst::GenericArg<'tcx>],
generic_args: &'a hir::GenericArgs,
generic_args: &'a hir::GenericArgs<'_>,
infer_args: bool,
self_ty: Option<Ty<'tcx>>,
) -> (SubstsRef<'tcx>, Vec<ConvertedBinding<'a, 'tcx>>, Option<Vec<Span>>) {
@ -794,7 +795,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
tcx: TyCtxt<'tcx>,
span: Span,
item_def_id: DefId,
item_segment: &hir::PathSegment,
item_segment: &hir::PathSegment<'_>,
parent_substs: SubstsRef<'tcx>,
) -> SubstsRef<'tcx> {
if tcx.generics_of(item_def_id).params.is_empty() {
@ -895,7 +896,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
/// are disallowed. Otherwise, they are pushed onto the vector given.
pub fn instantiate_mono_trait_ref(
&self,
trait_ref: &hir::TraitRef,
trait_ref: &hir::TraitRef<'_>,
self_ty: Ty<'tcx>,
) -> ty::TraitRef<'tcx> {
self.prohibit_generics(trait_ref.path.segments.split_last().unwrap().1);
@ -911,7 +912,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
/// The given trait-ref must actually be a trait.
pub(super) fn instantiate_poly_trait_ref_inner(
&self,
trait_ref: &hir::TraitRef,
trait_ref: &hir::TraitRef<'_>,
span: Span,
self_ty: Ty<'tcx>,
bounds: &mut Bounds<'tcx>,
@ -986,7 +987,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
/// however.
pub fn instantiate_poly_trait_ref(
&self,
poly_trait_ref: &hir::PolyTraitRef,
poly_trait_ref: &hir::PolyTraitRef<'_>,
self_ty: Ty<'tcx>,
bounds: &mut Bounds<'tcx>,
) -> Option<Vec<Span>> {
@ -1004,7 +1005,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
span: Span,
trait_def_id: DefId,
self_ty: Ty<'tcx>,
trait_segment: &hir::PathSegment,
trait_segment: &hir::PathSegment<'_>,
) -> ty::TraitRef<'tcx> {
let (substs, assoc_bindings, _) =
self.create_substs_for_ast_trait_ref(span, trait_def_id, self_ty, trait_segment);
@ -1018,7 +1019,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
&self,
span: Span,
trait_def_id: DefId,
trait_segment: &'a hir::PathSegment,
trait_segment: &'a hir::PathSegment<'a>,
) {
let trait_def = self.tcx().trait_def(trait_def_id);
@ -1076,7 +1077,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
span: Span,
trait_def_id: DefId,
self_ty: Ty<'tcx>,
trait_segment: &'a hir::PathSegment,
trait_segment: &'a hir::PathSegment<'a>,
) -> (SubstsRef<'tcx>, Vec<ConvertedBinding<'a, 'tcx>>, Option<Vec<Span>>) {
debug!("create_substs_for_ast_trait_ref(trait_segment={:?})", trait_segment);
@ -1104,7 +1105,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}
// Returns `true` if a bounds list includes `?Sized`.
pub fn is_unsized(&self, ast_bounds: &[hir::GenericBound], span: Span) -> bool {
pub fn is_unsized(&self, ast_bounds: &[hir::GenericBound<'_>], span: Span) -> bool {
let tcx = self.tcx();
// Try to find an unbound in bounds.
@ -1168,7 +1169,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
fn add_bounds(
&self,
param_ty: Ty<'tcx>,
ast_bounds: &[hir::GenericBound],
ast_bounds: &[hir::GenericBound<'_>],
bounds: &mut Bounds<'tcx>,
) {
let mut trait_bounds = Vec::new();
@ -1212,7 +1213,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
pub fn compute_bounds(
&self,
param_ty: Ty<'tcx>,
ast_bounds: &[hir::GenericBound],
ast_bounds: &[hir::GenericBound<'_>],
sized_by_default: SizedByDefault,
span: Span,
) -> Bounds<'tcx> {
@ -1388,7 +1389,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
Ok(())
}
fn ast_path_to_ty(&self, span: Span, did: DefId, item_segment: &hir::PathSegment) -> Ty<'tcx> {
fn ast_path_to_ty(
&self,
span: Span,
did: DefId,
item_segment: &hir::PathSegment<'_>,
) -> Ty<'tcx> {
let substs = self.ast_path_substs_for_ty(span, did, item_segment);
self.normalize_ty(span, self.tcx().at(span).type_of(did).subst(self.tcx(), substs))
}
@ -1396,7 +1402,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
fn conv_object_ty_poly_trait_ref(
&self,
span: Span,
trait_bounds: &[hir::PolyTraitRef],
trait_bounds: &[hir::PolyTraitRef<'_>],
lifetime: &hir::Lifetime,
) -> Ty<'tcx> {
let tcx = self.tcx();
@ -1617,7 +1623,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
&self,
associated_types: FxHashMap<Span, BTreeSet<DefId>>,
potential_assoc_types: Vec<Span>,
trait_bounds: &[hir::PolyTraitRef],
trait_bounds: &[hir::PolyTraitRef<'_>],
) {
if !associated_types.values().any(|v| v.len() > 0) {
return;
@ -2046,7 +2052,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
span: Span,
qself_ty: Ty<'tcx>,
qself_res: Res,
assoc_segment: &hir::PathSegment,
assoc_segment: &hir::PathSegment<'_>,
permit_variants: bool,
) -> Result<(Ty<'tcx>, DefKind, DefId), ErrorReported> {
let tcx = self.tcx();
@ -2204,8 +2210,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
span: Span,
opt_self_ty: Option<Ty<'tcx>>,
item_def_id: DefId,
trait_segment: &hir::PathSegment,
item_segment: &hir::PathSegment,
trait_segment: &hir::PathSegment<'_>,
item_segment: &hir::PathSegment<'_>,
) -> Ty<'tcx> {
let tcx = self.tcx();
@ -2265,7 +2271,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
self.normalize_ty(span, tcx.mk_projection(item_def_id, item_substs))
}
pub fn prohibit_generics<'a, T: IntoIterator<Item = &'a hir::PathSegment>>(
pub fn prohibit_generics<'a, T: IntoIterator<Item = &'a hir::PathSegment<'a>>>(
&self,
segments: T,
) -> bool {
@ -2311,7 +2317,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
break;
}
}
for binding in &segment.generic_args().bindings {
for binding in segment.generic_args().bindings {
has_err = true;
Self::prohibit_assoc_ty_binding(self.tcx(), binding.span);
break;
@ -2333,7 +2339,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// FIXME(eddyb, varkor) handle type paths here too, not just value ones.
pub fn def_ids_for_value_path_segments(
&self,
segments: &[hir::PathSegment],
segments: &[hir::PathSegment<'_>],
self_ty: Option<Ty<'tcx>>,
kind: DefKind,
def_id: DefId,
@ -2461,7 +2467,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
pub fn res_to_ty(
&self,
opt_self_ty: Option<Ty<'tcx>>,
path: &hir::Path,
path: &hir::Path<'_>,
permit_variants: bool,
) -> Ty<'tcx> {
let tcx = self.tcx();
@ -2510,7 +2516,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}
Res::Def(DefKind::TyParam, def_id) => {
assert_eq!(opt_self_ty, None);
self.prohibit_generics(&path.segments);
self.prohibit_generics(path.segments);
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
let item_id = tcx.hir().get_parent_node(hir_id);
@ -2522,13 +2528,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
Res::SelfTy(Some(_), None) => {
// `Self` in trait or type alias.
assert_eq!(opt_self_ty, None);
self.prohibit_generics(&path.segments);
self.prohibit_generics(path.segments);
tcx.types.self_param
}
Res::SelfTy(_, Some(def_id)) => {
// `Self` in impl (we know the concrete type).
assert_eq!(opt_self_ty, None);
self.prohibit_generics(&path.segments);
self.prohibit_generics(path.segments);
// Try to evaluate any array length constants.
self.normalize_ty(span, tcx.at(span).type_of(def_id))
}
@ -2545,7 +2551,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}
Res::PrimTy(prim_ty) => {
assert_eq!(opt_self_ty, None);
self.prohibit_generics(&path.segments);
self.prohibit_generics(path.segments);
match prim_ty {
hir::Bool => tcx.types.bool,
hir::Char => tcx.types.char,
@ -2565,7 +2571,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
/// Parses the programmer's textual representation of a type into our
/// internal notion of a type.
pub fn ast_ty_to_ty(&self, ast_ty: &hir::Ty) -> Ty<'tcx> {
pub fn ast_ty_to_ty(&self, ast_ty: &hir::Ty<'_>) -> Ty<'tcx> {
debug!("ast_ty_to_ty(id={:?}, ast_ty={:?} ty_ty={:?})", ast_ty.hir_id, ast_ty, ast_ty.kind);
let tcx = self.tcx();
@ -2698,7 +2704,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
tcx.mk_const(const_)
}
pub fn impl_trait_ty_to_ty(&self, def_id: DefId, lifetimes: &[hir::GenericArg]) -> Ty<'tcx> {
pub fn impl_trait_ty_to_ty(
&self,
def_id: DefId,
lifetimes: &[hir::GenericArg<'_>],
) -> Ty<'tcx> {
debug!("impl_trait_ty_to_ty(def_id={:?}, lifetimes={:?})", def_id, lifetimes);
let tcx = self.tcx();
@ -2733,7 +2743,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
ty
}
pub fn ty_of_arg(&self, ty: &hir::Ty, expected_ty: Option<Ty<'tcx>>) -> Ty<'tcx> {
pub fn ty_of_arg(&self, ty: &hir::Ty<'_>, expected_ty: Option<Ty<'tcx>>) -> Ty<'tcx> {
match ty.kind {
hir::TyKind::Infer if expected_ty.is_some() => {
self.record_ty(ty.hir_id, expected_ty.unwrap(), ty.span);
@ -2747,7 +2757,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
&self,
unsafety: hir::Unsafety,
abi: abi::Abi,
decl: &hir::FnDecl,
decl: &hir::FnDecl<'_>,
) -> ty::PolyFnSig<'tcx> {
debug!("ty_of_fn");

View file

@ -37,7 +37,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self,
expr: &hir::Expr<'_>,
_capture: hir::CaptureBy,
decl: &'tcx hir::FnDecl,
decl: &'tcx hir::FnDecl<'tcx>,
body_id: hir::BodyId,
gen: Option<hir::Movability>,
expected: Expectation<'tcx>,
@ -59,7 +59,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self,
expr: &hir::Expr<'_>,
opt_kind: Option<ty::ClosureKind>,
decl: &'tcx hir::FnDecl,
decl: &'tcx hir::FnDecl<'tcx>,
body: &'tcx hir::Body<'tcx>,
gen: Option<hir::Movability>,
expected_sig: Option<ExpectedSig<'tcx>>,
@ -282,7 +282,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn sig_of_closure(
&self,
expr_def_id: DefId,
decl: &hir::FnDecl,
decl: &hir::FnDecl<'_>,
body: &hir::Body<'_>,
expected_sig: Option<ExpectedSig<'tcx>>,
) -> ClosureSignatures<'tcx> {
@ -298,7 +298,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn sig_of_closure_no_expectation(
&self,
expr_def_id: DefId,
decl: &hir::FnDecl,
decl: &hir::FnDecl<'_>,
body: &hir::Body<'_>,
) -> ClosureSignatures<'tcx> {
debug!("sig_of_closure_no_expectation()");
@ -358,7 +358,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn sig_of_closure_with_expectation(
&self,
expr_def_id: DefId,
decl: &hir::FnDecl,
decl: &hir::FnDecl<'_>,
body: &hir::Body<'_>,
expected_sig: ExpectedSig<'tcx>,
) -> ClosureSignatures<'tcx> {
@ -413,7 +413,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn sig_of_closure_with_mismatched_number_of_arguments(
&self,
expr_def_id: DefId,
decl: &hir::FnDecl,
decl: &hir::FnDecl<'_>,
body: &hir::Body<'_>,
expected_sig: ExpectedSig<'tcx>,
) -> ClosureSignatures<'tcx> {
@ -446,7 +446,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn check_supplied_sig_against_expectation(
&self,
expr_def_id: DefId,
decl: &hir::FnDecl,
decl: &hir::FnDecl<'_>,
body: &hir::Body<'_>,
expected_sigs: &ClosureSignatures<'tcx>,
) -> InferResult<'tcx, ()> {
@ -535,7 +535,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn supplied_sig_of_closure(
&self,
expr_def_id: DefId,
decl: &hir::FnDecl,
decl: &hir::FnDecl<'_>,
body: &hir::Body<'_>,
) -> ty::PolyFnSig<'tcx> {
let astconv: &dyn AstConv<'_> = self;
@ -687,7 +687,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Converts the types that the user supplied, in case that doing
/// so should yield an error, but returns back a signature where
/// all parameters are of type `TyErr`.
fn error_sig_of_closure(&self, decl: &hir::FnDecl) -> ty::PolyFnSig<'tcx> {
fn error_sig_of_closure(&self, decl: &hir::FnDecl<'_>) -> ty::PolyFnSig<'tcx> {
let astconv: &dyn AstConv<'_> = self;
let supplied_arguments = decl.inputs.iter().map(|a| {

View file

@ -873,12 +873,12 @@ fn compare_synthetic_generics<'tcx>(
let impl_m = tcx.hir().as_local_hir_id(impl_m.def_id)?;
let impl_m = tcx.hir().impl_item(hir::ImplItemId { hir_id: impl_m });
let input_tys = match impl_m.kind {
hir::ImplItemKind::Method(ref sig, _) => &sig.decl.inputs,
hir::ImplItemKind::Method(ref sig, _) => sig.decl.inputs,
_ => unreachable!(),
};
struct Visitor(Option<Span>, hir::def_id::DefId);
impl<'v> hir::intravisit::Visitor<'v> for Visitor {
fn visit_ty(&mut self, ty: &'v hir::Ty) {
fn visit_ty(&mut self, ty: &'v hir::Ty<'v>) {
hir::intravisit::walk_ty(self, ty);
if let hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) =
ty.kind

View file

@ -469,7 +469,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
fn check_expr_path(&self, qpath: &hir::QPath, expr: &'tcx hir::Expr<'tcx>) -> Ty<'tcx> {
fn check_expr_path(&self, qpath: &hir::QPath<'_>, expr: &'tcx hir::Expr<'tcx>) -> Ty<'tcx> {
let tcx = self.tcx;
let (res, opt_ty, segs) = self.resolve_ty_and_res_ufcs(qpath, expr.hir_id, expr.span);
let ty = match res {
@ -853,7 +853,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn check_method_call(
&self,
expr: &'tcx hir::Expr<'tcx>,
segment: &hir::PathSegment,
segment: &hir::PathSegment<'_>,
span: Span,
args: &'tcx [hir::Expr<'tcx>],
expected: Expectation<'tcx>,
@ -893,7 +893,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn report_extended_method_error(
&self,
segment: &hir::PathSegment,
segment: &hir::PathSegment<'_>,
span: Span,
args: &'tcx [hir::Expr<'tcx>],
rcvr_t: Ty<'tcx>,
@ -941,7 +941,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn check_expr_cast(
&self,
e: &'tcx hir::Expr<'tcx>,
t: &'tcx hir::Ty,
t: &'tcx hir::Ty<'tcx>,
expr: &'tcx hir::Expr<'tcx>,
) -> Ty<'tcx> {
// Find the type of `e`. Supply hints based on the type we are casting to,
@ -1087,7 +1087,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self,
expr: &hir::Expr<'_>,
expected: Expectation<'tcx>,
qpath: &QPath,
qpath: &QPath<'_>,
fields: &'tcx [hir::Field<'tcx>],
base_expr: &'tcx Option<&'tcx hir::Expr<'tcx>>,
) -> Ty<'tcx> {

View file

@ -43,7 +43,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
call_expr: &'tcx hir::Expr<'tcx>,
unadjusted_self_ty: Ty<'tcx>,
pick: probe::Pick<'tcx>,
segment: &hir::PathSegment,
segment: &hir::PathSegment<'_>,
) -> ConfirmResult<'tcx> {
debug!(
"confirm(unadjusted_self_ty={:?}, pick={:?}, generic_args={:?})",
@ -69,7 +69,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
&mut self,
unadjusted_self_ty: Ty<'tcx>,
pick: probe::Pick<'tcx>,
segment: &hir::PathSegment,
segment: &hir::PathSegment<'_>,
) -> ConfirmResult<'tcx> {
// Adjust the self expression the user provided and obtain the adjusted type.
let self_ty = self.adjust_self_ty(unadjusted_self_ty, &pick);
@ -292,7 +292,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
fn instantiate_method_substs(
&mut self,
pick: &probe::Pick<'tcx>,
seg: &hir::PathSegment,
seg: &hir::PathSegment<'_>,
parent_substs: SubstsRef<'tcx>,
) -> SubstsRef<'tcx> {
// Determine the values for the generic parameters of the method.

View file

@ -178,7 +178,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn lookup_method(
&self,
self_ty: Ty<'tcx>,
segment: &hir::PathSegment,
segment: &hir::PathSegment<'_>,
span: Span,
call_expr: &'tcx hir::Expr<'tcx>,
self_expr: &'tcx hir::Expr<'tcx>,

View file

@ -953,7 +953,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
#[derive(Copy, Clone)]
pub enum SelfSource<'a> {
QPath(&'a hir::Ty),
QPath(&'a hir::Ty<'a>),
MethodCall(&'a hir::Expr<'a> /* rcvr */),
}

View file

@ -784,7 +784,7 @@ fn adt_destructor(tcx: TyCtxt<'_>, def_id: DefId) -> Option<ty::Destructor> {
fn primary_body_of(
tcx: TyCtxt<'_>,
id: hir::HirId,
) -> Option<(hir::BodyId, Option<&hir::Ty>, Option<&hir::FnHeader>, Option<&hir::FnDecl>)> {
) -> Option<(hir::BodyId, Option<&hir::Ty<'_>>, Option<&hir::FnHeader>, Option<&hir::FnDecl<'_>>)> {
match tcx.hir().get(id) {
Node::Item(item) => match item.kind {
hir::ItemKind::Const(ref ty, body) | hir::ItemKind::Static(ref ty, _, body) => {
@ -1196,7 +1196,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
fn visit_fn(
&mut self,
_: intravisit::FnKind<'tcx>,
_: &'tcx hir::FnDecl,
_: &'tcx hir::FnDecl<'tcx>,
_: hir::BodyId,
_: Span,
_: hir::HirId,
@ -1228,7 +1228,7 @@ fn check_fn<'a, 'tcx>(
inherited: &'a Inherited<'a, 'tcx>,
param_env: ty::ParamEnv<'tcx>,
fn_sig: ty::FnSig<'tcx>,
decl: &'tcx hir::FnDecl,
decl: &'tcx hir::FnDecl<'tcx>,
fn_id: hir::HirId,
body: &'tcx hir::Body<'tcx>,
can_be_generator: Option<hir::Movability>,
@ -1902,7 +1902,7 @@ fn check_impl_items_against_trait<'tcx>(
full_impl_span: Span,
impl_id: DefId,
impl_trait_ref: ty::TraitRef<'tcx>,
impl_item_refs: &[hir::ImplItemRef],
impl_item_refs: &[hir::ImplItemRef<'_>],
) {
let impl_span = tcx.sess.source_map().def_span(full_impl_span);
@ -2511,7 +2511,7 @@ pub fn check_enum<'tcx>(
check_transparent(tcx, sp, def_id);
}
fn report_unexpected_variant_res(tcx: TyCtxt<'_>, res: Res, span: Span, qpath: &QPath) {
fn report_unexpected_variant_res(tcx: TyCtxt<'_>, res: Res, span: Span, qpath: &QPath<'_>) {
span_err!(
tcx.sess,
span,
@ -2600,7 +2600,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
&self,
span: Span,
item_def_id: DefId,
item_segment: &hir::PathSegment,
item_segment: &hir::PathSegment<'_>,
poly_trait_ref: ty::PolyTraitRef<'tcx>,
) -> Ty<'tcx> {
let (trait_ref, _) = self.replace_bound_vars_with_fresh_vars(
@ -3105,13 +3105,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
pub fn to_ty(&self, ast_t: &hir::Ty) -> Ty<'tcx> {
pub fn to_ty(&self, ast_t: &hir::Ty<'_>) -> Ty<'tcx> {
let t = AstConv::ast_ty_to_ty(self, ast_t);
self.register_wf_obligation(t, ast_t.span, traits::MiscObligation);
t
}
pub fn to_ty_saving_user_provided_ty(&self, ast_ty: &hir::Ty) -> Ty<'tcx> {
pub fn to_ty_saving_user_provided_ty(&self, ast_ty: &hir::Ty<'_>) -> Ty<'tcx> {
let ty = self.to_ty(ast_ty);
debug!("to_ty_saving_user_provided_ty: ty={:?}", ty);
@ -4100,7 +4100,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn check_struct_path(
&self,
qpath: &QPath,
qpath: &QPath<'_>,
hir_id: hir::HirId,
) -> Option<(&'tcx ty::VariantDef, Ty<'tcx>)> {
let path_span = match *qpath {
@ -4159,7 +4159,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// The newly resolved definition is written into `type_dependent_defs`.
fn finish_resolving_struct_path(
&self,
qpath: &QPath,
qpath: &QPath<'_>,
path_span: Span,
hir_id: hir::HirId,
) -> (Res, Ty<'tcx>) {
@ -4194,10 +4194,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// resolution. The newly resolved definition is written into `type_dependent_defs`.
pub fn resolve_ty_and_res_ufcs<'b>(
&self,
qpath: &'b QPath,
qpath: &'b QPath<'b>,
hir_id: hir::HirId,
span: Span,
) -> (Res, Option<Ty<'tcx>>, &'b [hir::PathSegment]) {
) -> (Res, Option<Ty<'tcx>>, &'b [hir::PathSegment<'b>]) {
debug!("resolve_ty_and_res_ufcs: qpath={:?} hir_id={:?} span={:?}", qpath, hir_id, span);
let (ty, qself, item_segment) = match *qpath {
QPath::Resolved(ref opt_qself, ref path) => {
@ -4545,13 +4545,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
/// Given a function block's `HirId`, returns its `FnDecl` if it exists, or `None` otherwise.
fn get_parent_fn_decl(&self, blk_id: hir::HirId) -> Option<(&'tcx hir::FnDecl, ast::Ident)> {
fn get_parent_fn_decl(
&self,
blk_id: hir::HirId,
) -> Option<(&'tcx hir::FnDecl<'tcx>, ast::Ident)> {
let parent = self.tcx.hir().get(self.tcx.hir().get_parent_item(blk_id));
self.get_node_fn_decl(parent).map(|(fn_decl, ident, _)| (fn_decl, ident))
}
/// Given a function `Node`, return its `FnDecl` if it exists, or `None` otherwise.
fn get_node_fn_decl(&self, node: Node<'tcx>) -> Option<(&'tcx hir::FnDecl, ast::Ident, bool)> {
fn get_node_fn_decl(
&self,
node: Node<'tcx>,
) -> Option<(&'tcx hir::FnDecl<'tcx>, ast::Ident, bool)> {
match node {
Node::Item(&hir::Item { ident, kind: hir::ItemKind::Fn(ref sig, ..), .. }) => {
// This is less than ideal, it will not suggest a return type span on any
@ -4575,7 +4581,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Given a `HirId`, return the `FnDecl` of the method it is enclosed by and whether a
/// suggestion can be made, `None` otherwise.
pub fn get_fn_decl(&self, blk_id: hir::HirId) -> Option<(&'tcx hir::FnDecl, bool)> {
pub fn get_fn_decl(&self, blk_id: hir::HirId) -> Option<(&'tcx hir::FnDecl<'tcx>, bool)> {
// Get enclosing Fn, if it is a function or a trait method, unless there's a `loop` or
// `while` before reaching it, as block tail returns are not available in them.
self.tcx.hir().get_return_block(blk_id).and_then(|blk_id| {
@ -4908,7 +4914,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn suggest_missing_return_type(
&self,
err: &mut DiagnosticBuilder<'_>,
fn_decl: &hir::FnDecl,
fn_decl: &hir::FnDecl<'_>,
expected: Ty<'tcx>,
found: Ty<'tcx>,
can_suggest: bool,
@ -5075,7 +5081,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// number of type parameters and type.
pub fn instantiate_value_path(
&self,
segments: &[hir::PathSegment],
segments: &[hir::PathSegment<'_>],
self_ty: Option<Ty<'tcx>>,
res: Res,
span: Span,

View file

@ -554,7 +554,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn check_pat_struct(
&self,
pat: &'tcx Pat<'tcx>,
qpath: &hir::QPath,
qpath: &hir::QPath<'_>,
fields: &'tcx [hir::FieldPat<'tcx>],
etc: bool,
expected: Ty<'tcx>,
@ -587,8 +587,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn check_pat_path(
&self,
pat: &Pat<'_>,
path_resolution: (Res, Option<Ty<'tcx>>, &'b [hir::PathSegment]),
qpath: &hir::QPath,
path_resolution: (Res, Option<Ty<'tcx>>, &'b [hir::PathSegment<'b>]),
qpath: &hir::QPath<'_>,
expected: Ty<'tcx>,
) -> Ty<'tcx> {
let tcx = self.tcx;
@ -622,7 +622,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn check_pat_tuple_struct(
&self,
pat: &Pat<'_>,
qpath: &hir::QPath,
qpath: &hir::QPath<'_>,
subpats: &'tcx [&'tcx Pat<'tcx>],
ddpos: Option<usize>,
expected: Ty<'tcx>,
@ -724,7 +724,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self,
pat_span: Span,
res: Res,
qpath: &hir::QPath,
qpath: &hir::QPath<'_>,
subpats: &'tcx [&'tcx Pat<'tcx>],
fields: &'tcx [ty::FieldDef],
expected: Ty<'tcx>,

View file

@ -421,7 +421,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionCtxt<'a, 'tcx> {
fn visit_fn(
&mut self,
fk: intravisit::FnKind<'tcx>,
_: &'tcx hir::FnDecl,
_: &'tcx hir::FnDecl<'tcx>,
body_id: hir::BodyId,
span: Span,
hir_id: hir::HirId,

View file

@ -194,7 +194,7 @@ fn check_associated_item(
tcx: TyCtxt<'_>,
item_id: hir::HirId,
span: Span,
sig_if_method: Option<&hir::FnSig>,
sig_if_method: Option<&hir::FnSig<'_>>,
) {
debug!("check_associated_item: {:?}", item_id);
@ -391,8 +391,8 @@ fn check_item_type(tcx: TyCtxt<'_>, item_id: hir::HirId, ty_span: Span, allow_fo
fn check_impl<'tcx>(
tcx: TyCtxt<'tcx>,
item: &'tcx hir::Item<'tcx>,
ast_self_ty: &hir::Ty,
ast_trait_ref: &Option<hir::TraitRef>,
ast_self_ty: &hir::Ty<'_>,
ast_trait_ref: &Option<hir::TraitRef<'_>>,
) {
debug!("check_impl: {:?}", item);
@ -774,7 +774,7 @@ const HELP_FOR_SELF_TYPE: &str = "consider changing to `self`, `&self`, `&mut se
fn check_method_receiver<'fcx, 'tcx>(
fcx: &FnCtxt<'fcx, 'tcx>,
fn_sig: &hir::FnSig,
fn_sig: &hir::FnSig<'_>,
method: &ty::AssocItem,
self_ty: Ty<'tcx>,
) {
@ -961,7 +961,7 @@ fn receiver_is_implemented(
fn check_variances_for_type_defn<'tcx>(
tcx: TyCtxt<'tcx>,
item: &hir::Item<'tcx>,
hir_generics: &hir::Generics,
hir_generics: &hir::Generics<'_>,
) {
let item_def_id = tcx.hir().local_def_id(item.hir_id);
let ty = tcx.type_of(item_def_id);

View file

@ -310,7 +310,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> {
self.write_ty_to_tables(l.hir_id, var_ty);
}
fn visit_ty(&mut self, hir_ty: &'tcx hir::Ty) {
fn visit_ty(&mut self, hir_ty: &'tcx hir::Ty<'tcx>) {
intravisit::walk_ty(self, hir_ty);
let ty = self.fcx.node_ty(hir_ty.hir_id);
let ty = self.resolve(&ty, &hir_ty.span);

View file

@ -20,7 +20,7 @@ impl UnsafetyChecker<'tcx> {
fn check_unsafety_coherence(
&mut self,
item: &'v hir::Item<'v>,
impl_generics: Option<&hir::Generics>,
impl_generics: Option<&hir::Generics<'_>>,
unsafety: hir::Unsafety,
polarity: hir::ImplPolarity,
) {

View file

@ -116,7 +116,7 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
intravisit::walk_item(self, item);
}
fn visit_generics(&mut self, generics: &'tcx hir::Generics) {
fn visit_generics(&mut self, generics: &'tcx hir::Generics<'tcx>) {
for param in &generics.params {
match param.kind {
hir::GenericParamKind::Lifetime { .. } => {}
@ -173,7 +173,7 @@ impl ItemCtxt<'tcx> {
ItemCtxt { tcx, item_def_id }
}
pub fn to_ty(&self, ast_ty: &'tcx hir::Ty) -> Ty<'tcx> {
pub fn to_ty(&self, ast_ty: &'tcx hir::Ty<'tcx>) -> Ty<'tcx> {
AstConv::ast_ty_to_ty(self, ast_ty)
}
}
@ -216,7 +216,7 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> {
&self,
span: Span,
item_def_id: DefId,
item_segment: &hir::PathSegment,
item_segment: &hir::PathSegment<'_>,
poly_trait_ref: ty::PolyTraitRef<'tcx>,
) -> Ty<'tcx> {
if let Some(trait_ref) = poly_trait_ref.no_bound_vars() {
@ -343,7 +343,7 @@ impl ItemCtxt<'tcx> {
/// bounds for a type parameter `X` if `X::Foo` is used.
fn type_parameter_bounds_in_generics(
&self,
ast_generics: &'tcx hir::Generics,
ast_generics: &'tcx hir::Generics<'tcx>,
param_id: hir::HirId,
ty: Ty<'tcx>,
only_self_bounds: OnlySelfBounds,
@ -386,7 +386,7 @@ impl ItemCtxt<'tcx> {
/// parameter with ID `param_id`. We use this so as to avoid running
/// `ast_ty_to_ty`, because we want to avoid triggering an all-out
/// conversion of the type to avoid inducing unnecessary cycles.
fn is_param(tcx: TyCtxt<'_>, ast_ty: &hir::Ty, param_id: hir::HirId) -> bool {
fn is_param(tcx: TyCtxt<'_>, ast_ty: &hir::Ty<'_>, param_id: hir::HirId) -> bool {
if let hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) = ast_ty.kind {
match path.res {
Res::SelfTy(Some(def_id), None) | Res::Def(DefKind::TyParam, def_id) => {
@ -803,7 +803,7 @@ fn has_late_bound_regions<'tcx>(tcx: TyCtxt<'tcx>, node: Node<'tcx>) -> Option<S
NestedVisitorMap::None
}
fn visit_ty(&mut self, ty: &'tcx hir::Ty) {
fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) {
if self.has_late_bound_regions.is_some() {
return;
}
@ -819,7 +819,7 @@ fn has_late_bound_regions<'tcx>(tcx: TyCtxt<'tcx>, node: Node<'tcx>) -> Option<S
fn visit_poly_trait_ref(
&mut self,
tr: &'tcx hir::PolyTraitRef,
tr: &'tcx hir::PolyTraitRef<'tcx>,
m: hir::TraitBoundModifier,
) {
if self.has_late_bound_regions.is_some() {
@ -852,8 +852,8 @@ fn has_late_bound_regions<'tcx>(tcx: TyCtxt<'tcx>, node: Node<'tcx>) -> Option<S
fn has_late_bound_regions<'tcx>(
tcx: TyCtxt<'tcx>,
generics: &'tcx hir::Generics,
decl: &'tcx hir::FnDecl,
generics: &'tcx hir::Generics<'tcx>,
decl: &'tcx hir::FnDecl<'tcx>,
) -> Option<Span> {
let mut visitor = LateBoundRegionsDetector {
tcx,
@ -1699,7 +1699,7 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
}
}
pub fn get_infer_ret_ty(output: &'_ hir::FunctionRetTy) -> Option<&hir::Ty> {
pub fn get_infer_ret_ty(output: &'hir hir::FunctionRetTy<'hir>) -> Option<&'hir hir::Ty<'hir>> {
if let hir::FunctionRetTy::Return(ref ty) = output {
if let hir::TyKind::Infer = ty.kind {
return Some(&**ty);
@ -1841,8 +1841,8 @@ fn impl_polarity(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ImplPolarity {
/// `resolve_lifetime::early_bound_lifetimes`.
fn early_bound_lifetimes_from_generics<'a, 'tcx: 'a>(
tcx: TyCtxt<'tcx>,
generics: &'a hir::Generics,
) -> impl Iterator<Item = &'a hir::GenericParam> + Captures<'tcx> {
generics: &'a hir::Generics<'a>,
) -> impl Iterator<Item = &'a hir::GenericParam<'a>> + Captures<'tcx> {
generics.params.iter().filter(move |param| match param.kind {
GenericParamKind::Lifetime { .. } => !tcx.is_late_bound(param.hir_id),
_ => false,
@ -1947,7 +1947,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
let icx = ItemCtxt::new(tcx, def_id);
const NO_GENERICS: &hir::Generics = &hir::Generics::empty();
const NO_GENERICS: &hir::Generics<'_> = &hir::Generics::empty();
let mut predicates = UniquePredicates::new();
@ -2116,7 +2116,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
// Add in the bounds that appear in the where-clause.
let where_clause = &ast_generics.where_clause;
for predicate in &where_clause.predicates {
for predicate in where_clause.predicates {
match predicate {
&hir::WherePredicate::BoundPredicate(ref bound_pred) => {
let ty = icx.to_ty(&bound_pred.bounded_ty);
@ -2323,7 +2323,7 @@ fn associated_item_predicates(
fn predicates_from_bound<'tcx>(
astconv: &dyn AstConv<'tcx>,
param_ty: Ty<'tcx>,
bound: &'tcx hir::GenericBound,
bound: &'tcx hir::GenericBound<'tcx>,
) -> Vec<(ty::Predicate<'tcx>, Span)> {
match *bound {
hir::GenericBound::Trait(ref tr, hir::TraitBoundModifier::None) => {
@ -2343,7 +2343,7 @@ fn predicates_from_bound<'tcx>(
fn compute_sig_of_foreign_fn_decl<'tcx>(
tcx: TyCtxt<'tcx>,
def_id: DefId,
decl: &'tcx hir::FnDecl,
decl: &'tcx hir::FnDecl<'tcx>,
abi: abi::Abi,
) -> ty::PolyFnSig<'tcx> {
let unsafety = if abi == abi::Abi::RustIntrinsic {
@ -2359,7 +2359,7 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
&& abi != abi::Abi::PlatformIntrinsic
&& !tcx.features().simd_ffi
{
let check = |ast_ty: &hir::Ty, ty: Ty<'_>| {
let check = |ast_ty: &hir::Ty<'_>, ty: Ty<'_>| {
if ty.is_simd() {
tcx.sess
.struct_span_err(

View file

@ -89,7 +89,7 @@ impl ItemLikeVisitor<'tcx> for ImplWfCheck<'tcx> {
fn enforce_impl_params_are_constrained(
tcx: TyCtxt<'_>,
impl_def_id: DefId,
impl_item_refs: &[hir::ImplItemRef],
impl_item_refs: &[hir::ImplItemRef<'_>],
) {
// Every lifetime used in an associated type must be constrained.
let impl_self_ty = tcx.type_of(impl_def_id);
@ -201,7 +201,7 @@ fn report_unused_parameter(tcx: TyCtxt<'_>, span: Span, kind: &str, name: &str)
}
/// Enforce that we do not have two items in an impl with the same name.
fn enforce_impl_items_are_distinct(tcx: TyCtxt<'_>, impl_item_refs: &[hir::ImplItemRef]) {
fn enforce_impl_items_are_distinct(tcx: TyCtxt<'_>, impl_item_refs: &[hir::ImplItemRef<'_>]) {
let mut seen_type_items = FxHashMap::default();
let mut seen_value_items = FxHashMap::default();
for impl_item_ref in impl_item_refs {

View file

@ -119,7 +119,7 @@ pub struct TypeAndSubsts<'tcx> {
ty: Ty<'tcx>,
}
fn require_c_abi_if_c_variadic(tcx: TyCtxt<'_>, decl: &hir::FnDecl, abi: Abi, span: Span) {
fn require_c_abi_if_c_variadic(tcx: TyCtxt<'_>, decl: &hir::FnDecl<'_>, abi: Abi, span: Span) {
if decl.c_variadic && !(abi == Abi::C || abi == Abi::Cdecl) {
let mut err = struct_span_err!(
tcx.sess,
@ -356,7 +356,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorReported> {
/// A quasi-deprecated helper used in rustdoc and clippy to get
/// the type from a HIR node.
pub fn hir_ty_to_ty<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: &hir::Ty) -> Ty<'tcx> {
pub fn hir_ty_to_ty<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: &hir::Ty<'_>) -> Ty<'tcx> {
// In case there are any projections, etc., find the "environment"
// def-ID that will be used to determine the traits/predicates in
// scope. This is derived from the enclosing item-like thing.
@ -367,7 +367,10 @@ pub fn hir_ty_to_ty<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: &hir::Ty) -> Ty<'tcx> {
astconv::AstConv::ast_ty_to_ty(&item_cx, hir_ty)
}
pub fn hir_trait_to_predicates<'tcx>(tcx: TyCtxt<'tcx>, hir_trait: &hir::TraitRef) -> Bounds<'tcx> {
pub fn hir_trait_to_predicates<'tcx>(
tcx: TyCtxt<'tcx>,
hir_trait: &hir::TraitRef<'_>,
) -> Bounds<'tcx> {
// In case there are any projections, etc., find the "environment"
// def-ID that will be used to determine the traits/predicates in
// scope. This is derived from the enclosing item-like thing.

View file

@ -306,7 +306,7 @@ impl Clean<Attributes> for [ast::Attribute] {
}
}
impl Clean<GenericBound> for hir::GenericBound {
impl Clean<GenericBound> for hir::GenericBound<'_> {
fn clean(&self, cx: &DocContext<'_>) -> GenericBound {
match *self {
hir::GenericBound::Outlives(lt) => GenericBound::Outlives(lt.clean(cx)),
@ -406,7 +406,7 @@ impl Clean<Lifetime> for hir::Lifetime {
}
}
impl Clean<Lifetime> for hir::GenericParam {
impl Clean<Lifetime> for hir::GenericParam<'_> {
fn clean(&self, _: &DocContext<'_>) -> Lifetime {
match self.kind {
hir::GenericParamKind::Lifetime { .. } => {
@ -469,7 +469,7 @@ impl Clean<Option<Lifetime>> for ty::RegionKind {
}
}
impl Clean<WherePredicate> for hir::WherePredicate {
impl Clean<WherePredicate> for hir::WherePredicate<'_> {
fn clean(&self, cx: &DocContext<'_>) -> WherePredicate {
match *self {
hir::WherePredicate::BoundPredicate(ref wbp) => WherePredicate::BoundPredicate {
@ -615,7 +615,7 @@ impl Clean<GenericParamDef> for ty::GenericParamDef {
}
}
impl Clean<GenericParamDef> for hir::GenericParam {
impl Clean<GenericParamDef> for hir::GenericParam<'_> {
fn clean(&self, cx: &DocContext<'_>) -> GenericParamDef {
let (name, kind) = match self.kind {
hir::GenericParamKind::Lifetime { .. } => {
@ -657,12 +657,12 @@ impl Clean<GenericParamDef> for hir::GenericParam {
}
}
impl Clean<Generics> for hir::Generics {
impl Clean<Generics> for hir::Generics<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Generics {
// Synthetic type-parameters are inserted after normal ones.
// In order for normal parameters to be able to refer to synthetic ones,
// scans them first.
fn is_impl_trait(param: &hir::GenericParam) -> bool {
fn is_impl_trait(param: &hir::GenericParam<'_>) -> bool {
match param.kind {
hir::GenericParamKind::Type { synthetic, .. } => {
synthetic == Some(hir::SyntheticTyParamKind::ImplTrait)
@ -892,7 +892,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
}
impl<'a> Clean<Method>
for (&'a hir::FnSig, &'a hir::Generics, hir::BodyId, Option<hir::Defaultness>)
for (&'a hir::FnSig<'a>, &'a hir::Generics<'a>, hir::BodyId, Option<hir::Defaultness>)
{
fn clean(&self, cx: &DocContext<'_>) -> Method {
let (generics, decl) =
@ -933,7 +933,7 @@ impl Clean<Item> for doctree::Function<'_> {
}
}
impl<'a> Clean<Arguments> for (&'a [hir::Ty], &'a [ast::Ident]) {
impl<'a> Clean<Arguments> for (&'a [hir::Ty<'a>], &'a [ast::Ident]) {
fn clean(&self, cx: &DocContext<'_>) -> Arguments {
Arguments {
values: self
@ -953,7 +953,7 @@ impl<'a> Clean<Arguments> for (&'a [hir::Ty], &'a [ast::Ident]) {
}
}
impl<'a> Clean<Arguments> for (&'a [hir::Ty], hir::BodyId) {
impl<'a> Clean<Arguments> for (&'a [hir::Ty<'a>], hir::BodyId) {
fn clean(&self, cx: &DocContext<'_>) -> Arguments {
let body = cx.tcx.hir().body(self.1);
@ -971,9 +971,9 @@ impl<'a> Clean<Arguments> for (&'a [hir::Ty], hir::BodyId) {
}
}
impl<'a, A: Copy> Clean<FnDecl> for (&'a hir::FnDecl, A)
impl<'a, A: Copy> Clean<FnDecl> for (&'a hir::FnDecl<'a>, A)
where
(&'a [hir::Ty], A): Clean<Arguments>,
(&'a [hir::Ty<'a>], A): Clean<Arguments>,
{
fn clean(&self, cx: &DocContext<'_>) -> FnDecl {
FnDecl {
@ -1013,7 +1013,7 @@ impl<'tcx> Clean<FnDecl> for (DefId, ty::PolyFnSig<'tcx>) {
}
}
impl Clean<FunctionRetTy> for hir::FunctionRetTy {
impl Clean<FunctionRetTy> for hir::FunctionRetTy<'_> {
fn clean(&self, cx: &DocContext<'_>) -> FunctionRetTy {
match *self {
hir::Return(ref typ) => Return(typ.clean(cx)),
@ -1075,13 +1075,13 @@ impl Clean<bool> for hir::IsAuto {
}
}
impl Clean<Type> for hir::TraitRef {
impl Clean<Type> for hir::TraitRef<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Type {
resolve_type(cx, self.path.clean(cx), self.hir_ref_id)
}
}
impl Clean<PolyTrait> for hir::PolyTraitRef {
impl Clean<PolyTrait> for hir::PolyTraitRef<'_> {
fn clean(&self, cx: &DocContext<'_>) -> PolyTrait {
PolyTrait {
trait_: self.trait_ref.clean(cx),
@ -1324,7 +1324,7 @@ impl Clean<Item> for ty::AssocItem {
}
}
impl Clean<Type> for hir::Ty {
impl Clean<Type> for hir::Ty<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Type {
use rustc::hir::*;
@ -1480,7 +1480,7 @@ impl Clean<Type> for hir::Ty {
if let ty::Projection(proj) = ty.kind {
res = Res::Def(DefKind::Trait, proj.trait_ref(cx.tcx).def_id);
}
let trait_path = hir::Path { span: self.span, res, segments: vec![].into() };
let trait_path = hir::Path { span: self.span, res, segments: &[] };
Type::QPath {
name: segment.ident.name.clean(cx),
self_type: box qself.clean(cx),
@ -1760,7 +1760,7 @@ impl Clean<Item> for ty::FieldDef {
}
}
impl Clean<Visibility> for hir::Visibility {
impl Clean<Visibility> for hir::Visibility<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Visibility {
match self.node {
hir::VisibilityKind::Public => Visibility::Public,
@ -1937,7 +1937,7 @@ impl Clean<Span> for syntax_pos::Span {
}
}
impl Clean<Path> for hir::Path {
impl Clean<Path> for hir::Path<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Path {
Path {
global: self.is_global(),
@ -1947,7 +1947,7 @@ impl Clean<Path> for hir::Path {
}
}
impl Clean<GenericArgs> for hir::GenericArgs {
impl Clean<GenericArgs> for hir::GenericArgs<'_> {
fn clean(&self, cx: &DocContext<'_>) -> GenericArgs {
if self.parenthesized {
let output = self.bindings[0].ty().clean(cx);
@ -1979,7 +1979,7 @@ impl Clean<GenericArgs> for hir::GenericArgs {
}
}
impl Clean<PathSegment> for hir::PathSegment {
impl Clean<PathSegment> for hir::PathSegment<'_> {
fn clean(&self, cx: &DocContext<'_>) -> PathSegment {
PathSegment { name: self.ident.name.clean(cx), args: self.generic_args().clean(cx) }
}
@ -2038,7 +2038,7 @@ impl Clean<Item> for doctree::OpaqueTy<'_> {
}
}
impl Clean<BareFunctionDecl> for hir::BareFnTy {
impl Clean<BareFunctionDecl> for hir::BareFnTy<'_> {
fn clean(&self, cx: &DocContext<'_>) -> BareFunctionDecl {
let (generic_params, decl) = enter_impl_trait(cx, || {
(self.generic_params.clean(cx), (&*self.decl, &self.param_names[..]).clean(cx))
@ -2377,13 +2377,13 @@ impl Clean<Deprecation> for attr::Deprecation {
}
}
impl Clean<TypeBinding> for hir::TypeBinding {
impl Clean<TypeBinding> for hir::TypeBinding<'_> {
fn clean(&self, cx: &DocContext<'_>) -> TypeBinding {
TypeBinding { name: self.ident.name.clean(cx), kind: self.kind.clean(cx) }
}
}
impl Clean<TypeBindingKind> for hir::TypeBindingKind {
impl Clean<TypeBindingKind> for hir::TypeBindingKind<'_> {
fn clean(&self, cx: &DocContext<'_>) -> TypeBindingKind {
match *self {
hir::TypeBindingKind::Equality { ref ty } => {

View file

@ -28,7 +28,7 @@ pub struct Module<'hir> {
pub statics: Vec<Static<'hir>>,
pub constants: Vec<Constant<'hir>>,
pub traits: Vec<Trait<'hir>>,
pub vis: &'hir hir::Visibility,
pub vis: &'hir hir::Visibility<'hir>,
pub impls: Vec<Impl<'hir>>,
pub foreigns: Vec<ForeignItem<'hir>>,
pub macros: Vec<Macro<'hir>>,
@ -41,7 +41,7 @@ impl Module<'hir> {
pub fn new(
name: Option<Name>,
attrs: &'hir [ast::Attribute],
vis: &'hir hir::Visibility,
vis: &'hir hir::Visibility<'hir>,
) -> Module<'hir> {
Module {
name: name,
@ -83,31 +83,31 @@ pub enum StructType {
}
pub struct Struct<'hir> {
pub vis: &'hir hir::Visibility,
pub vis: &'hir hir::Visibility<'hir>,
pub id: hir::HirId,
pub struct_type: StructType,
pub name: Name,
pub generics: &'hir hir::Generics,
pub generics: &'hir hir::Generics<'hir>,
pub attrs: &'hir [ast::Attribute],
pub fields: &'hir [hir::StructField<'hir>],
pub whence: Span,
}
pub struct Union<'hir> {
pub vis: &'hir hir::Visibility,
pub vis: &'hir hir::Visibility<'hir>,
pub id: hir::HirId,
pub struct_type: StructType,
pub name: Name,
pub generics: &'hir hir::Generics,
pub generics: &'hir hir::Generics<'hir>,
pub attrs: &'hir [ast::Attribute],
pub fields: &'hir [hir::StructField<'hir>],
pub whence: Span,
}
pub struct Enum<'hir> {
pub vis: &'hir hir::Visibility,
pub vis: &'hir hir::Visibility<'hir>,
pub variants: Vec<Variant<'hir>>,
pub generics: &'hir hir::Generics,
pub generics: &'hir hir::Generics<'hir>,
pub attrs: &'hir [ast::Attribute],
pub id: hir::HirId,
pub whence: Span,
@ -123,54 +123,54 @@ pub struct Variant<'hir> {
}
pub struct Function<'hir> {
pub decl: &'hir hir::FnDecl,
pub decl: &'hir hir::FnDecl<'hir>,
pub attrs: &'hir [ast::Attribute],
pub id: hir::HirId,
pub name: Name,
pub vis: &'hir hir::Visibility,
pub vis: &'hir hir::Visibility<'hir>,
pub header: hir::FnHeader,
pub whence: Span,
pub generics: &'hir hir::Generics,
pub generics: &'hir hir::Generics<'hir>,
pub body: hir::BodyId,
}
pub struct Typedef<'hir> {
pub ty: &'hir hir::Ty,
pub gen: &'hir hir::Generics,
pub ty: &'hir hir::Ty<'hir>,
pub gen: &'hir hir::Generics<'hir>,
pub name: Name,
pub id: hir::HirId,
pub attrs: &'hir [ast::Attribute],
pub whence: Span,
pub vis: &'hir hir::Visibility,
pub vis: &'hir hir::Visibility<'hir>,
}
pub struct OpaqueTy<'hir> {
pub opaque_ty: &'hir hir::OpaqueTy,
pub opaque_ty: &'hir hir::OpaqueTy<'hir>,
pub name: Name,
pub id: hir::HirId,
pub attrs: &'hir [ast::Attribute],
pub whence: Span,
pub vis: &'hir hir::Visibility,
pub vis: &'hir hir::Visibility<'hir>,
}
#[derive(Debug)]
pub struct Static<'hir> {
pub type_: &'hir hir::Ty,
pub type_: &'hir hir::Ty<'hir>,
pub mutability: hir::Mutability,
pub expr: hir::BodyId,
pub name: Name,
pub attrs: &'hir [ast::Attribute],
pub vis: &'hir hir::Visibility,
pub vis: &'hir hir::Visibility<'hir>,
pub id: hir::HirId,
pub whence: Span,
}
pub struct Constant<'hir> {
pub type_: &'hir hir::Ty,
pub type_: &'hir hir::Ty<'hir>,
pub expr: hir::BodyId,
pub name: Name,
pub attrs: &'hir [ast::Attribute],
pub vis: &'hir hir::Visibility,
pub vis: &'hir hir::Visibility<'hir>,
pub id: hir::HirId,
pub whence: Span,
}
@ -180,22 +180,22 @@ pub struct Trait<'hir> {
pub unsafety: hir::Unsafety,
pub name: Name,
pub items: Vec<&'hir hir::TraitItem<'hir>>,
pub generics: &'hir hir::Generics,
pub bounds: &'hir [hir::GenericBound],
pub generics: &'hir hir::Generics<'hir>,
pub bounds: &'hir [hir::GenericBound<'hir>],
pub attrs: &'hir [ast::Attribute],
pub id: hir::HirId,
pub whence: Span,
pub vis: &'hir hir::Visibility,
pub vis: &'hir hir::Visibility<'hir>,
}
pub struct TraitAlias<'hir> {
pub name: Name,
pub generics: &'hir hir::Generics,
pub bounds: &'hir [hir::GenericBound],
pub generics: &'hir hir::Generics<'hir>,
pub bounds: &'hir [hir::GenericBound<'hir>],
pub attrs: &'hir [ast::Attribute],
pub id: hir::HirId,
pub whence: Span,
pub vis: &'hir hir::Visibility,
pub vis: &'hir hir::Visibility<'hir>,
}
#[derive(Debug)]
@ -203,18 +203,18 @@ pub struct Impl<'hir> {
pub unsafety: hir::Unsafety,
pub polarity: hir::ImplPolarity,
pub defaultness: hir::Defaultness,
pub generics: &'hir hir::Generics,
pub trait_: &'hir Option<hir::TraitRef>,
pub for_: &'hir hir::Ty,
pub generics: &'hir hir::Generics<'hir>,
pub trait_: &'hir Option<hir::TraitRef<'hir>>,
pub for_: &'hir hir::Ty<'hir>,
pub items: Vec<&'hir hir::ImplItem<'hir>>,
pub attrs: &'hir [ast::Attribute],
pub whence: Span,
pub vis: &'hir hir::Visibility,
pub vis: &'hir hir::Visibility<'hir>,
pub id: hir::HirId,
}
pub struct ForeignItem<'hir> {
pub vis: &'hir hir::Visibility,
pub vis: &'hir hir::Visibility<'hir>,
pub id: hir::HirId,
pub name: Name,
pub kind: &'hir hir::ForeignItemKind<'hir>,
@ -238,7 +238,7 @@ pub struct ExternCrate<'hir> {
pub name: Name,
pub cnum: CrateNum,
pub path: Option<String>,
pub vis: &'hir hir::Visibility,
pub vis: &'hir hir::Visibility<'hir>,
pub attrs: &'hir [ast::Attribute],
pub whence: Span,
}
@ -246,9 +246,9 @@ pub struct ExternCrate<'hir> {
pub struct Import<'hir> {
pub name: Name,
pub id: hir::HirId,
pub vis: &'hir hir::Visibility,
pub vis: &'hir hir::Visibility<'hir>,
pub attrs: &'hir [ast::Attribute],
pub path: &'hir hir::Path,
pub path: &'hir hir::Path<'hir>,
pub glob: bool,
pub whence: Span,
}