From deac631d7ff93db4d1d61ae9717444f60767003e Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 30 Nov 2019 15:20:35 +0100 Subject: [PATCH 1/7] Use Arena inside hir::FnSig. --- src/librustc/hir/intravisit.rs | 2 +- src/librustc/hir/lowering/item.rs | 4 +++- src/librustc/hir/map/blocks.rs | 12 ++++++------ src/librustc/hir/map/mod.rs | 4 ++-- src/librustc/hir/mod.rs | 10 +++++----- src/librustc/hir/print.rs | 2 +- src/librustc_typeck/check/wfcheck.rs | 4 ++-- src/librustdoc/clean/mod.rs | 2 +- 8 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 659bfc4e63c6b..519c1fe4cc8e4 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -45,7 +45,7 @@ pub enum FnKind<'a> { ItemFn(Ident, &'a Generics, FnHeader, &'a Visibility, &'a [Attribute]), /// `fn foo(&self)` - Method(Ident, &'a FnSig, Option<&'a Visibility>, &'a [Attribute]), + Method(Ident, &'a FnSig<'a>, Option<&'a Visibility>, &'a [Attribute]), /// `|x, y| {}` Closure(&'a [Attribute]), diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index 0157e89c96b04..4f1769dfd245b 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -323,6 +323,7 @@ impl<'hir> LoweringContext<'_, 'hir> { ) }, ); + let decl = this.arena.alloc(decl.into_inner()); let sig = hir::FnSig { decl, header: this.lower_fn_header(header) }; hir::ItemKind::Fn(sig, generics, body_id) }) @@ -1253,7 +1254,7 @@ impl<'hir> LoweringContext<'_, 'hir> { fn_def_id: DefId, impl_trait_return_allow: bool, is_async: Option, - ) -> (hir::Generics, hir::FnSig) { + ) -> (hir::Generics, hir::FnSig<'hir>) { let header = self.lower_fn_header(sig.header); let (generics, decl) = self.add_in_band_defs( generics, @@ -1268,6 +1269,7 @@ impl<'hir> LoweringContext<'_, 'hir> { ) }, ); + let decl = self.arena.alloc(decl.into_inner()); (generics, hir::FnSig { header, decl }) } diff --git a/src/librustc/hir/map/blocks.rs b/src/librustc/hir/map/blocks.rs index 7701c33f9162a..6d8fd9d2f011a 100644 --- a/src/librustc/hir/map/blocks.rs +++ b/src/librustc/hir/map/blocks.rs @@ -151,7 +151,7 @@ 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, ) } @@ -159,7 +159,7 @@ impl<'a> FnLikeNode<'a> { pub fn decl(self) -> &'a FnDecl { 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 +167,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 +175,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 +197,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,7 +209,7 @@ impl<'a> FnLikeNode<'a> { M: FnOnce( ast::HirId, Ident, - &'a ast::FnSig, + &'a ast::FnSig<'a>, Option<&'a ast::Visibility>, ast::BodyId, Span, diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index cc5cb58173fd6..d933f1e49e4a3 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -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), @@ -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 { diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 8a450cf167a36..f54bc51baf1fe 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -1917,9 +1917,9 @@ pub struct MutTy { /// 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, + pub decl: &'hir FnDecl, } // The bodies for items are stored "out of line", in a separate @@ -1960,7 +1960,7 @@ pub enum TraitItemKind<'hir> { /// An associated constant with an optional value (otherwise `impl`s must contain a value). Const(&'hir Ty, Option), /// A method with an optional body. - Method(FnSig, TraitMethod), + Method(FnSig<'hir>, TraitMethod), /// An associated type with (possibly empty) bounds and optional concrete /// type. Type(GenericBounds, Option<&'hir Ty>), @@ -1994,7 +1994,7 @@ pub enum ImplItemKind<'hir> { /// of the expression. Const(&'hir Ty, BodyId), /// A method implementation with the given signature and body. - Method(FnSig, BodyId), + Method(FnSig<'hir>, BodyId), /// An associated type. TyAlias(&'hir Ty), /// An associated `type = impl Trait`. @@ -2528,7 +2528,7 @@ pub enum ItemKind<'hir> { /// A `const` item. Const(&'hir Ty, BodyId), /// A function declaration. - Fn(FnSig, Generics, BodyId), + Fn(FnSig<'hir>, Generics, BodyId), /// A module. Mod(Mod<'hir>), /// An external module, e.g. `extern { .. }`. diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 11a596a831777..9e2702a0ff256 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -822,7 +822,7 @@ impl<'a> State<'a> { pub fn print_method_sig( &mut self, ident: ast::Ident, - m: &hir::FnSig, + m: &hir::FnSig<'_>, generics: &hir::Generics, vis: &hir::Visibility, arg_names: &[ast::Ident], diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 4c349a27c215a..1c8278480aa20 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -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); @@ -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>, ) { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index e5c0a6aadce43..bf0e3872995b6 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -892,7 +892,7 @@ impl<'a, 'tcx> Clean for (&'a ty::Generics, ty::GenericPredicates<'tcx } impl<'a> Clean - for (&'a hir::FnSig, &'a hir::Generics, hir::BodyId, Option) + for (&'a hir::FnSig<'a>, &'a hir::Generics, hir::BodyId, Option) { fn clean(&self, cx: &DocContext<'_>) -> Method { let (generics, decl) = From 66f91980473db385d3560cfa4a1e9f889fb6f906 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 30 Nov 2019 15:28:32 +0100 Subject: [PATCH 2/7] Use Arena inside hir::TraitMethod. --- src/librustc/hir/intravisit.rs | 2 +- src/librustc/hir/lowering/item.rs | 1 + src/librustc/hir/mod.rs | 6 +++--- src/librustc_lint/nonstandard_style.rs | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 519c1fe4cc8e4..7011a572fb172 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -850,7 +850,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 ¶m_name in param_names { diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index 4f1769dfd245b..c82de81e737f4 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -787,6 +787,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))) diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index f54bc51baf1fe..84d8fb32e2da1 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -1946,9 +1946,9 @@ pub struct TraitItem<'hir> { /// 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), + Required(&'hir [Ident]), /// Both signature and body are provided in the trait. Provided(BodyId), @@ -1960,7 +1960,7 @@ pub enum TraitItemKind<'hir> { /// An associated constant with an optional value (otherwise `impl`s must contain a value). Const(&'hir Ty, Option), /// A method with an optional body. - Method(FnSig<'hir>, TraitMethod), + Method(FnSig<'hir>, TraitMethod<'hir>), /// An associated type with (possibly empty) bounds and optional concrete /// type. Type(GenericBounds, Option<&'hir Ty>), diff --git a/src/librustc_lint/nonstandard_style.rs b/src/librustc_lint/nonstandard_style.rs index 2752be9a6de99..8cf502b3a7405 100644 --- a/src/librustc_lint/nonstandard_style.rs +++ b/src/librustc_lint/nonstandard_style.rs @@ -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); From 6b87d5cdf1f60b14140b9c68c2ecb05f1a61e651 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 30 Nov 2019 17:46:46 +0100 Subject: [PATCH 3/7] Syntax for hir::Ty. --- src/librustc/arena.rs | 12 +- src/librustc/hir/intravisit.rs | 97 +++--- src/librustc/hir/lowering.rs | 97 +++--- src/librustc/hir/lowering/expr.rs | 2 +- src/librustc/hir/lowering/item.rs | 20 +- src/librustc/hir/map/blocks.rs | 20 +- src/librustc/hir/map/collector.rs | 16 +- src/librustc/hir/map/hir_id_validator.rs | 2 +- src/librustc/hir/map/mod.rs | 6 +- src/librustc/hir/mod.rs | 306 +++++++++--------- src/librustc/hir/print.rs | 70 ++-- src/librustc/hir/upvars.rs | 2 +- src/librustc/ich/impls_hir.rs | 4 +- .../infer/error_reporting/need_type_info.rs | 4 +- .../nice_region_error/find_anon_type.rs | 12 +- .../error_reporting/nice_region_error/util.rs | 2 +- src/librustc/lint/context.rs | 24 +- src/librustc/lint/internal.rs | 10 +- src/librustc/lint/mod.rs | 18 +- src/librustc/middle/resolve_lifetime.rs | 69 ++-- src/librustc/middle/stability.rs | 6 +- src/librustc/traits/error_reporting.rs | 4 +- src/librustc/ty/context.rs | 2 +- src/librustc/ty/mod.rs | 6 +- src/librustc/ty/wf.rs | 4 +- 25 files changed, 429 insertions(+), 386 deletions(-) diff --git a/src/librustc/arena.rs b/src/librustc/arena.rs index f604a66aebc01..1381772d5e86f 100644 --- a/src/librustc/arena.rs +++ b/src/librustc/arena.rs @@ -132,21 +132,21 @@ macro_rules! arena_types { [] 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>, + [] 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>, [] variant: rustc::hir::Variant<$tcx>, ], $tcx); ) diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 7011a572fb172..33e636a03bdae 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -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<'a>, 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,7 +445,7 @@ 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>, @@ -454,7 +454,7 @@ pub fn walk_poly_trait_ref<'v, V>( 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>, { @@ -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 { @@ -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,7 +647,7 @@ 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) { +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,13 +670,16 @@ 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); } -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 { @@ -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,7 +764,7 @@ 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, ¶m.attrs); match param.name { @@ -771,12 +779,15 @@ pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Generi walk_list!(visitor, visit_param_bound, ¶m.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); } -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, @@ -804,13 +815,13 @@ 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) { +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) } @@ -829,7 +840,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, @@ -927,7 +938,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt } } -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 +1110,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) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index ed84bd118f725..e58485fe3187f 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -212,7 +212,7 @@ enum ImplTraitContext<'a> { /// equivalent to a fresh universal parameter like `fn foo(x: T)`. /// /// Newly generated parameters should be inserted into the given `Vec`. - Universal(&'a mut Vec), + Universal(&'a mut Vec>), /// Treat `impl Trait` as shorthand for a new opaque type. /// Example: `fn foo() -> impl Debug`, where `impl Debug` is conceptually @@ -739,9 +739,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { parent_id: DefId, anonymous_lifetime_mode: AnonymousLifetimeMode, f: F, - ) -> (Vec, T) + ) -> (Vec>, T) where - F: FnOnce(&mut LoweringContext<'_, '_>) -> (Vec, T), + F: FnOnce(&mut LoweringContext<'_, '_>) -> (Vec>, T), { assert!(!self.is_collecting_in_band_lifetimes); assert!(self.lifetimes_to_define.is_empty()); @@ -772,7 +772,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 @@ -874,9 +874,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) -> T, + F: FnOnce(&mut LoweringContext<'_, '_>, &mut Vec>) -> T, { let (in_band_defs, (mut lowered_generics, res)) = self.with_in_scope_lifetime_defs(&generics.params, |this| { @@ -1026,7 +1026,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { &mut self, constraint: &AssocTyConstraint, itctx: ImplTraitContext<'_>, - ) -> hir::TypeBinding { + ) -> hir::TypeBinding<'hir> { debug!("lower_assoc_ty_constraint(constraint={:?}, itctx={:?})", constraint, itctx); let kind = match constraint.kind { @@ -1123,7 +1123,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { &mut self, arg: &ast::GenericArg, itctx: ImplTraitContext<'_>, - ) -> hir::GenericArg { + ) -> hir::GenericArg<'hir> { match arg { ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(<)), ast::GenericArg::Type(ty) => { @@ -1178,7 +1178,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } } - fn lower_ty(&mut self, t: &Ty, itctx: ImplTraitContext<'_>) -> P { + fn lower_ty(&mut self, t: &Ty, itctx: ImplTraitContext<'_>) -> P> { P(self.lower_ty_direct(t, itctx)) } @@ -1189,7 +1189,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { path: &Path, param_mode: ParamMode, itctx: ImplTraitContext<'_>, - ) -> hir::Ty { + ) -> 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); @@ -1199,15 +1199,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 { + fn ty_tup(&mut self, span: Span, tys: HirVec>) -> 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::Ty<'hir> { let kind = match t.kind { TyKind::Infer => hir::TyKind::Infer, TyKind::Err => hir::TyKind::Err, @@ -1376,8 +1376,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { span: Span, fn_def_id: Option, opaque_ty_node_id: NodeId, - lower_bounds: impl FnOnce(&mut LoweringContext<'_, '_>) -> hir::GenericBounds, - ) -> hir::TyKind { + lower_bounds: impl FnOnce(&mut LoweringContext<'_, '_>) -> 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, @@ -1433,7 +1433,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 { @@ -1461,8 +1461,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { &mut self, opaque_ty_id: NodeId, parent_index: DefIndex, - bounds: &hir::GenericBounds, - ) -> (HirVec, HirVec) { + bounds: &hir::GenericBounds<'hir>, + ) -> (HirVec>, HirVec>) { debug!( "lifetimes_from_impl_trait_bounds(opaque_ty_id={:?}, \ parent_index={:?}, \ @@ -1480,8 +1480,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { collect_elided_lifetimes: bool, currently_bound_lifetimes: Vec, already_defined_lifetimes: FxHashSet, - output_lifetimes: Vec, - output_lifetime_params: Vec, + output_lifetimes: Vec>, + output_lifetime_params: Vec>, } impl<'r, 'a, 'v, 'hir> hir::intravisit::Visitor<'v> for ImplTraitLifetimeCollector<'r, 'a, 'hir> { @@ -1491,7 +1491,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; @@ -1503,7 +1503,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; @@ -1523,7 +1523,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 @@ -1533,7 +1533,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 @@ -1639,7 +1639,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { p: &Path, param_mode: ParamMode, mut itctx: ImplTraitContext<'_>, - ) -> hir::QPath { + ) -> 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())); @@ -1799,7 +1799,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { p: &Path, param_mode: ParamMode, explicit_owner: Option, - ) -> hir::Path { + ) -> hir::Path<'hir> { hir::Path { res, segments: p @@ -1821,7 +1821,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } } - 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,7 +1836,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { parenthesized_generic_args: ParenthesizedGenericArgs, itctx: ImplTraitContext<'_>, explicit_owner: Option, - ) -> 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 { @@ -1981,7 +1981,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { data: &AngleBracketedArgs, param_mode: ParamMode, mut itctx: ImplTraitContext<'_>, - ) -> (hir::GenericArgs, bool) { + ) -> (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, @@ -2004,7 +2004,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`, where `Ref` has // a hidden lifetime parameter. This is needed for backwards @@ -2098,10 +2098,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { fn lower_fn_decl( &mut self, decl: &FnDecl, - mut in_band_ty_params: Option<(DefId, &mut Vec)>, + mut in_band_ty_params: Option<(DefId, &mut Vec>)>, impl_trait_return_allow: bool, make_ret_async: Option, - ) -> P { + ) -> P> { debug!( "lower_fn_decl(\ fn_decl: {:?}, \ @@ -2207,7 +2207,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={:?}, \ @@ -2384,7 +2384,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { output: &FunctionRetTy, fn_def_id: DefId, span: Span, - ) -> hir::GenericBound { + ) -> hir::GenericBound<'hir> { // Compute the `T` in `Future` from the return type. let output_ty = match output { FunctionRetTy::Ty(ty) => self.lower_ty(ty, ImplTraitContext::OpaqueTy(Some(fn_def_id))), @@ -2421,7 +2421,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { &mut self, tpb: &GenericBound, itctx: ImplTraitContext<'_>, - ) -> hir::GenericBound { + ) -> hir::GenericBound<'hir> { match *tpb { GenericBound::Trait(ref ty, modifier) => hir::GenericBound::Trait( self.lower_poly_trait_ref(ty, itctx), @@ -2473,7 +2473,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { params: &[GenericParam], add_bounds: &NodeMap>, mut itctx: ImplTraitContext<'_>, - ) -> hir::HirVec { + ) -> hir::HirVec> { params .iter() .map(|param| self.lower_generic_param(param, add_bounds, itctx.reborrow())) @@ -2485,7 +2485,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { param: &GenericParam, add_bounds: &NodeMap>, mut itctx: ImplTraitContext<'_>, - ) -> hir::GenericParam { + ) -> hir::GenericParam<'hir> { let mut bounds = self .with_anonymous_lifetime_mode(AnonymousLifetimeMode::ReportError, |this| { this.lower_param_bounds(¶m.bounds, itctx.reborrow()) @@ -2561,7 +2561,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } } - fn lower_trait_ref(&mut self, p: &TraitRef, itctx: ImplTraitContext<'_>) -> hir::TraitRef { + fn lower_trait_ref( + &mut self, + p: &TraitRef, + itctx: ImplTraitContext<'_>, + ) -> 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), @@ -2573,7 +2577,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { &mut self, p: &PolyTraitRef, mut itctx: ImplTraitContext<'_>, - ) -> hir::PolyTraitRef { + ) -> hir::PolyTraitRef<'hir> { let bound_generic_params = self.lower_generic_params( &p.bound_generic_params, &NodeMap::default(), @@ -2586,7 +2590,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { hir::PolyTraitRef { bound_generic_params, 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::MutTy<'hir> { hir::MutTy { ty: self.lower_ty(&mt.ty, itctx), mutbl: mt.mutbl } } @@ -2594,7 +2598,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { &mut self, bounds: &[GenericBound], mut itctx: ImplTraitContext<'_>, - ) -> hir::GenericBounds { + ) -> hir::GenericBounds<'hir> { bounds.iter().map(|bound| self.lower_param_bound(bound, itctx.reborrow())).collect() } @@ -3077,9 +3081,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { &mut self, span: Span, components: &[Symbol], - params: Option>, + params: Option>>, 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); @@ -3106,7 +3110,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } } - 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. diff --git a/src/librustc/hir/lowering/expr.rs b/src/librustc/hir/lowering/expr.rs index 8a9614c6cb2c0..a5871e02dd0b9 100644 --- a/src/librustc/hir/lowering/expr.rs +++ b/src/librustc/hir/lowering/expr.rs @@ -1338,7 +1338,7 @@ impl<'hir> LoweringContext<'_, 'hir> { &mut self, span: Span, components: &[Symbol], - params: Option>, + params: Option>>, attrs: AttrVec, ) -> hir::Expr<'hir> { let path = self.std_path(span, components, params, true); diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index c82de81e737f4..d4705e9795c87 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -258,7 +258,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 { @@ -466,7 +466,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> { @@ -635,7 +635,7 @@ 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 @@ -651,7 +651,7 @@ impl<'hir> LoweringContext<'_, 'hir> { 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), @@ -918,7 +918,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, @@ -952,7 +952,7 @@ impl<'hir> LoweringContext<'_, 'hir> { &mut self, v: &Visibility, explicit_owner: Option, - ) -> hir::Visibility { + ) -> hir::Visibility<'hir> { let node = match v.node { VisibilityKind::Public => hir::VisibilityKind::Public, VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar), @@ -1255,7 +1255,7 @@ impl<'hir> LoweringContext<'_, 'hir> { fn_def_id: DefId, impl_trait_return_allow: bool, is_async: Option, - ) -> (hir::Generics, hir::FnSig<'hir>) { + ) -> (hir::Generics<'hir>, hir::FnSig<'hir>) { let header = self.lower_fn_header(sig.header); let (generics, decl) = self.add_in_band_defs( generics, @@ -1316,7 +1316,7 @@ impl<'hir> LoweringContext<'_, 'hir> { &mut self, generics: &Generics, itctx: ImplTraitContext<'_>, - ) -> hir::Generics { + ) -> 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 @@ -1379,7 +1379,7 @@ 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 @@ -1392,7 +1392,7 @@ impl<'hir> LoweringContext<'_, 'hir> { }) } - 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, diff --git a/src/librustc/hir/map/blocks.rs b/src/librustc/hir/map/blocks.rs index 6d8fd9d2f011a..1267de4d9786c 100644 --- a/src/librustc/hir/map/blocks.rs +++ b/src/librustc/hir/map/blocks.rs @@ -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 } } } @@ -156,7 +162,7 @@ impl<'a> FnLikeNode<'a> { ) } - pub fn decl(self) -> &'a FnDecl { + pub fn decl(self) -> &'a FnDecl<'a> { self.handle( |i: ItemFnParts<'a>| &*i.decl, |_, _, sig: &'a ast::FnSig<'a>, _, _, _, _| &sig.decl, @@ -210,7 +216,7 @@ impl<'a> FnLikeNode<'a> { ast::HirId, Ident, &'a ast::FnSig<'a>, - Option<&'a ast::Visibility>, + Option<&'a ast::Visibility<'a>>, ast::BodyId, Span, &'a [Attribute], diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index 610be0a0753f0..28eff07a494d5 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -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; diff --git a/src/librustc/hir/map/hir_id_validator.rs b/src/librustc/hir/map/hir_id_validator.rs index 4c250aba96d09..a04fc8a562ffa 100644 --- a/src/librustc/hir/map/hir_id_validator.rs +++ b/src/librustc/hir/map/hir_id_validator.rs @@ -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 diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index d933f1e49e4a3..7f7af331b3c30 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -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), @@ -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 { @@ -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), diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 84d8fb32e2da1..3c6513a137f5c 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -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, + 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>, + pub args: Option<&'hir GenericArgs<'hir>>, /// Whether to infer remaining type parameters, if any. /// This only applies to expression and pattern paths, and @@ -358,9 +358,9 @@ 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 } } @@ -368,7 +368,7 @@ impl PathSegment { ident: Ident, hir_id: Option, res: Option, - args: GenericArgs, + args: GenericArgs<'_>, infer_args: bool, ) -> Self { PathSegment { @@ -380,11 +380,11 @@ impl PathSegment { } } - 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 +397,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,19 +429,19 @@ impl GenericArg { } #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] -pub struct GenericArgs { +pub struct GenericArgs<'hir> { /// The generic arguments for this path segment. - pub args: HirVec, + pub args: HirVec>, /// Bindings (equality constraints) on associated types, if present. /// E.g., `Foo`. - pub bindings: HirVec, + 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 } } @@ -450,7 +450,7 @@ impl GenericArgs { 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 +499,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 +513,7 @@ impl GenericBound { } } -pub type GenericBounds = HirVec; +pub type GenericBounds<'hir> = &'hir [GenericBound<'hir>]; #[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum LifetimeParamKind { @@ -535,29 +535,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>, + default: Option<&'hir Ty<'hir>>, synthetic: Option, }, Const { - ty: P, + 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, - 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,14 +570,14 @@ 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, - pub where_clause: WhereClause, +pub struct Generics<'hir> { + pub params: HirVec>, + 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 }, @@ -602,7 +602,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 +629,13 @@ pub enum SyntheticTyParamKind { /// A where-clause in a definition. #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] -pub struct WhereClause { - pub predicates: HirVec, +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 { if self.predicates.is_empty() { None } else { Some(self.span) } } @@ -649,16 +649,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 +670,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, + pub bound_generic_params: &'hir [GenericParam<'hir>], /// The type being bounded. - pub bounded_ty: P, + 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, - pub rhs_ty: P, + pub lhs_ty: &'hir Ty<'hir>, + pub rhs_ty: &'hir Ty<'hir>, } #[derive(RustcEncodable, RustcDecodable, Debug)] @@ -820,7 +820,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 +1003,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` denotes its position. /// `0 <= position <= subpats.len()` - TupleStruct(QPath, &'hir [&'hir Pat<'hir>], Option), + TupleStruct(QPath<'hir>, &'hir [&'hir Pat<'hir>], Option), /// 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` denotes its position. @@ -1258,7 +1258,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 +1583,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 +1663,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 +1673,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 +1695,7 @@ pub enum ExprKind<'hir> { /// /// This may also be a generator literal or an `async block` as indicated by the /// `Option`. - Closure(CaptureBy, &'hir FnDecl, BodyId, Span, Option), + Closure(CaptureBy, &'hir FnDecl<'hir>, BodyId, Span, Option), /// A block (e.g., `'label: { ... }`). Block(&'hir Block<'hir>, Option, D}`. - Enum(EnumDef<'hir>, Generics), + Enum(EnumDef<'hir>, Generics<'hir>), /// A struct definition, e.g., `struct Foo {x: A}`. - Struct(VariantData<'hir>, Generics), + Struct(VariantData<'hir>, Generics<'hir>), /// A union definition, e.g., `union Foo {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 Trait for Foo { .. }`. Impl( Unsafety, ImplPolarity, Defaultness, - Generics, - Option, // (optional) trait this impl implements - &'hir Ty, // self - &'hir [ImplItemRef], + Generics<'hir>, + Option>, // (optional) trait this impl implements + &'hir Ty<'hir>, // self + &'hir [ImplItemRef<'hir>], ), } @@ -2593,7 +2593,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 +2631,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 +2657,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 +2837,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 +2852,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, } diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 9e2702a0ff256..84e824f64df93 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -140,7 +140,7 @@ where printer.s.eof() } -pub fn visibility_qualified>>(vis: &hir::Visibility, w: S) -> String { +pub fn visibility_qualified>>(vis: &hir::Visibility<'_>, w: S) -> String { to_string(NO_ANN, |s| { s.print_visibility(vis); s.s.word(w) @@ -266,7 +266,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 { @@ -398,9 +398,9 @@ impl<'a> State<'a> { fn print_associated_const( &mut self, ident: ast::Ident, - ty: &hir::Ty, + ty: &hir::Ty<'_>, default: Option, - vis: &hir::Visibility, + vis: &hir::Visibility<'_>, ) { self.s.word(visibility_qualified(vis, "")); self.word_space("const"); @@ -418,8 +418,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 +437,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 +682,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 +694,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 +702,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 +730,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 +761,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, @@ -823,8 +823,8 @@ impl<'a> State<'a> { &mut self, ident: ast::Ident, m: &hir::FnSig<'_>, - generics: &hir::Generics, - vis: &hir::Visibility, + generics: &hir::Generics<'_>, + vis: &hir::Visibility<'_>, arg_names: &[ast::Ident], body_id: Option, ) { @@ -1044,7 +1044,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 +1103,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 +1440,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 +1458,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 +1523,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, ) { @@ -1814,11 +1814,11 @@ impl<'a> State<'a> { pub fn print_fn( &mut self, - decl: &hir::FnDecl, + decl: &hir::FnDecl<'_>, header: hir::FnHeader, name: Option, - generics: &hir::Generics, - vis: &hir::Visibility, + generics: &hir::Generics<'_>, + vis: &hir::Visibility<'_>, arg_names: &[ast::Ident], body_id: Option, ) { @@ -1858,7 +1858,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 +1903,7 @@ impl<'a> State<'a> { pub fn print_bounds<'b>( &mut self, prefix: &'static str, - bounds: impl IntoIterator, + bounds: impl IntoIterator>, ) { let mut first = true; for bound in bounds { @@ -1933,7 +1933,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 +1943,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"); } @@ -1986,7 +1986,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; } @@ -2056,12 +2056,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 +2085,9 @@ impl<'a> State<'a> { &mut self, abi: Abi, unsafety: hir::Unsafety, - decl: &hir::FnDecl, + decl: &hir::FnDecl<'_>, name: Option, - generic_params: &[hir::GenericParam], + generic_params: &[hir::GenericParam<'_>], arg_names: &[ast::Ident], ) { self.ibox(INDENT_UNIT); @@ -2164,7 +2164,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 { diff --git a/src/librustc/hir/upvars.rs b/src/librustc/hir/upvars.rs index d7de226df59ec..827cf7513944f 100644 --- a/src/librustc/hir/upvars.rs +++ b/src/librustc/hir/upvars.rs @@ -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); } diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 31d4f8513b2aa..214a50456d576 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -106,7 +106,7 @@ impl<'a> HashStable> for hir::ImplItemId { } } -impl<'a> HashStable> for hir::Ty { +impl<'a> HashStable> 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> for hir::ImplItem<'_> { } } -impl<'a> HashStable> for hir::VisibilityKind { +impl<'a> HashStable> for hir::VisibilityKind<'_> { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { mem::discriminant(self).hash_stable(hcx, hasher); match *self { diff --git a/src/librustc/infer/error_reporting/need_type_info.rs b/src/librustc/infer/error_reporting/need_type_info.rs index 6b977393806ee..5a6d336ee1b92 100644 --- a/src/librustc/infer/error_reporting/need_type_info.rs +++ b/src/librustc/infer/error_reporting/need_type_info.rs @@ -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<'_>, ) { diff --git a/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs b/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs index decc00826dd9c..9077a48f85036 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs @@ -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); @@ -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 diff --git a/src/librustc/infer/error_reporting/nice_region_error/util.rs b/src/librustc/infer/error_reporting/nice_region_error/util.rs index 638c8f5200719..95feef313c07a 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/util.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/util.rs @@ -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 { let ret_ty = self.tcx().type_of(scope_def_id); if let ty::FnDef(_, _) = ret_ty.kind { diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 4e1e62512acd2..44258b62ca32f 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -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); } diff --git a/src/librustc/lint/internal.rs b/src/librustc/lint/internal.rs index 55ed46e774ded..bd75eda1879b1 100644 --- a/src/librustc/lint/internal.rs +++ b/src/librustc/lint/internal.rs @@ -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 { +fn is_ty_or_ty_ctxt(cx: &LateContext<'_, '_>, ty: &Ty<'_>) -> Option { 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 { None } -fn gen_args(segment: &PathSegment) -> String { +fn gen_args(segment: &PathSegment<'_>) -> String { if let Some(args) = &segment.args { let lifetimes = args .args diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 97b38db416597..f4684bd52224f 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -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| { diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 7950ff421b4a5..82f19478b94e6 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -44,7 +44,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 +74,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 +83,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 +517,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 { @@ -881,7 +881,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 +890,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,7 +898,7 @@ 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 { @@ -976,7 +976,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); @@ -1046,7 +1046,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 +1059,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: &P<[hir::GenericParam<'_>]>) { let lifetime_params: Vec<_> = params .iter() .filter_map(|param| match param.kind { @@ -1252,9 +1252,9 @@ fn compute_object_lifetime_defaults(tcx: TyCtxt<'_>) -> HirIdMap, - generics: &hir::Generics, + generics: &hir::Generics<'_>, ) -> Vec { - fn add_bounds(set: &mut Set1, bounds: &[hir::GenericBound]) { + fn add_bounds(set: &mut Set1, bounds: &[hir::GenericBound<'_>]) { for bound in bounds { if let hir::GenericBound::Outlives(ref lifetime) = *bound { set.insert(lifetime.name.modern()); @@ -1368,7 +1368,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 { + fn lifetime_deletion_span( + &self, + name: ast::Ident, + generics: &hir::Generics<'_>, + ) -> Option { generics.params.iter().enumerate().find_map(|(i, param)| { if param.name.ident() == name { let mut in_band = false; @@ -1417,7 +1421,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| { + let mut find_arg_use_span = |inputs: &hir::HirVec>| { for input in inputs { match input.kind { hir::TyKind::Rptr(lt, _) => { @@ -1656,8 +1660,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { fn visit_early_late( &mut self, parent_id: Option, - 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 +1858,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, @@ -2045,7 +2054,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 +2138,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, } @@ -2163,7 +2176,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,7 +2264,7 @@ 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); } @@ -2276,7 +2289,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 +2301,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 +2536,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() @@ -2617,7 +2630,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,8 +2768,8 @@ 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); @@ -2840,7 +2853,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(..)) => { diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index f1c07f36da5d0..b692459eb517f 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -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) } diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index f7d9cb34fa925..878675f981259 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -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, diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 2659caf030b0c..d92fd34d7e4c5 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -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 diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 8834e0e5a08c4..2c40c9dc9efbb 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -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 { diff --git a/src/librustc/ty/wf.rs b/src/librustc/ty/wf.rs index 900c425fac2da..afd1b690232e7 100644 --- a/src/librustc/ty/wf.rs +++ b/src/librustc/ty/wf.rs @@ -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 { @@ -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(); From 5865d563eacaff1b0d3836390f4ce3e1e78b849e Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 1 Dec 2019 00:17:43 +0100 Subject: [PATCH 4/7] Visit for hir::Ty. --- src/librustc/hir/intravisit.rs | 42 +++++++++--------- src/librustc/hir/mod.rs | 4 +- src/librustc/hir/print.rs | 24 +++++------ .../nice_region_error/find_anon_type.rs | 2 +- src/librustc/middle/resolve_lifetime.rs | 43 +++++++++---------- 5 files changed, 55 insertions(+), 60 deletions(-) diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 33e636a03bdae..c265b53b37d52 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -450,7 +450,7 @@ pub fn walk_poly_trait_ref<'v, V>( ) 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); } @@ -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); @@ -598,17 +598,17 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) { 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<'v>) { 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); } @@ -648,7 +648,7 @@ pub fn walk_qpath<'v, V: Visitor<'v>>( } pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path<'v>) { - for segment in &path.segments { + for segment in path.segments { visitor.visit_path_segment(path.span, segment); } } @@ -673,7 +673,7 @@ pub fn walk_generic_args<'v, V: Visitor<'v>>( 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>>( @@ -686,7 +686,7 @@ pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>( TypeBindingKind::Equality { ref ty } => { visitor.visit_ty(ty); } - TypeBindingKind::Constraint { ref bounds } => { + TypeBindingKind::Constraint { bounds } => { walk_list!(visitor, visit_param_bound, bounds); } } @@ -766,7 +766,7 @@ 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<'v>) { visitor.visit_id(param.hir_id); - walk_list!(visitor, visit_attribute, ¶m.attrs); + walk_list!(visitor, visit_attribute, param.attrs); match param.name { ParamName::Plain(ident) => visitor.visit_ident(ident), ParamName::Error | ParamName::Fresh(_) => {} @@ -776,12 +776,12 @@ 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, ¶m.bounds); + walk_list!(visitor, visit_param_bound, param.bounds); } 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>>( @@ -791,17 +791,15 @@ pub fn walk_where_predicate<'v, V: Visitor<'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); } @@ -822,7 +820,7 @@ pub fn walk_fn_ret_ty<'v, V: Visitor<'v>>(visitor: &mut V, ret_ty: &'v FunctionR } pub fn walk_fn_decl<'v, V: Visitor<'v>>(visitor: &mut V, function_declaration: &'v FnDecl<'v>) { - for ty in &function_declaration.inputs { + for ty in function_declaration.inputs { visitor.visit_ty(ty) } walk_fn_ret_ty(visitor, &function_declaration.output) @@ -877,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); @@ -931,7 +929,7 @@ 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); } diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 3c6513a137f5c..a0b45639be9c2 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -443,7 +443,7 @@ pub struct GenericArgs<'hir> { 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 { @@ -580,7 +580,7 @@ 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, } } diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 84e824f64df93..61afdab3e1cf6 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -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}; @@ -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 { @@ -418,7 +419,7 @@ impl<'a> State<'a> { fn print_associated_type( &mut self, ident: ast::Ident, - bounds: Option<&hir::GenericBounds<'_>>, + bounds: Option>, ty: Option<&hir::Ty<'_>>, ) { self.word_space("type"); @@ -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); @@ -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); } } @@ -1953,9 +1954,9 @@ impl<'a> State<'a> { match param.kind { GenericParamKind::Lifetime { .. } => { let mut sep = ":"; - for bound in ¶m.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(":", ¶m.bounds); + self.print_bounds(":", param.bounds); match default { Some(default) => { self.s.space(); @@ -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); @@ -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( diff --git a/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs b/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs index 9077a48f85036..0b226336faca3 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs @@ -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); diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 82f19478b94e6..29e3bcfe6a15c 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -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}; @@ -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; @@ -904,22 +903,22 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { match param.kind { GenericParamKind::Lifetime { .. } => {} GenericParamKind::Type { ref default, .. } => { - walk_list!(self, visit_param_bound, ¶m.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, ¶m.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); @@ -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 { @@ -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 { @@ -1273,7 +1272,7 @@ fn object_lifetime_defaults_for_item( add_bounds(&mut set, ¶m.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, @@ -1421,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>| { + let mut find_arg_use_span = |inputs: &[hir::Ty<'_>]| { for input in inputs { match input.kind { hir::TyKind::Rptr(lt, _) => { @@ -1463,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); } } _ => {} @@ -2045,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, @@ -2269,7 +2268,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { 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); } @@ -2583,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", @@ -2774,7 +2773,7 @@ fn insert_late_bound_lifetimes( 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); } From c737c0702134888a88cb847c5286c600a78ffea9 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 1 Dec 2019 11:22:58 +0100 Subject: [PATCH 5/7] Lowering for hir::Ty. --- src/librustc/arena.rs | 8 + src/librustc/hir/lowering.rs | 332 ++++++++++++++++-------------- src/librustc/hir/lowering/expr.rs | 32 +-- src/librustc/hir/lowering/item.rs | 81 +++----- src/librustc/hir/mod.rs | 16 -- src/librustc/hir/ptr.rs | 8 - 6 files changed, 231 insertions(+), 246 deletions(-) diff --git a/src/librustc/arena.rs b/src/librustc/arena.rs index 1381772d5e86f..f551d9e31a658 100644 --- a/src/librustc/arena.rs +++ b/src/librustc/arena.rs @@ -128,7 +128,12 @@ 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>, @@ -142,12 +147,15 @@ macro_rules! arena_types { [] pat: rustc::hir::Pat<$tcx>, [] 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<$tcx>, + [] type_binding: rustc::hir::TypeBinding<$tcx>, [] variant: rustc::hir::Variant<$tcx>, + [] where_predicate: rustc::hir::WherePredicate<$tcx>, ], $tcx); ) } diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index e58485fe3187f..110788c66c759 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -206,13 +206,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(x: T)`. /// /// Newly generated parameters should be inserted into the given `Vec`. - Universal(&'a mut Vec>), + Universal(&'b mut Vec>), /// Treat `impl Trait` as shorthand for a new opaque type. /// Example: `fn foo() -> impl Debug`, where `impl Debug` is conceptually @@ -237,13 +237,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,7 +741,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { f: F, ) -> (Vec>, T) where - F: FnOnce(&mut LoweringContext<'_, '_>) -> (Vec>, T), + F: FnOnce(&mut Self) -> (Vec>, T), { assert!(!self.is_collecting_in_band_lifetimes); assert!(self.lifetimes_to_define.is_empty()); @@ -796,8 +796,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 }, @@ -847,7 +847,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { // for them. fn with_in_scope_lifetime_defs(&mut self, params: &[GenericParam], f: F) -> T where - F: FnOnce(&mut LoweringContext<'_, '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,7 +876,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { f: F, ) -> (hir::Generics<'hir>, T) where - F: FnOnce(&mut LoweringContext<'_, '_>, &mut Vec>) -> T, + F: FnOnce(&mut Self, &mut Vec>) -> T, { let (in_band_defs, (mut lowered_generics, res)) = self.with_in_scope_lifetime_defs(&generics.params, |this| { @@ -897,7 +897,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { }); let mut lowered_params: Vec<_> = - lowered_generics.params.into_iter().chain(in_band_defs).collect(); + lowered_generics.params.into_iter().chain(in_band_defs.into_iter()).collect(); // FIXME(const_generics): the compiler doesn't always cope with // unsorted generic parameters at the moment, so we make sure @@ -916,7 +916,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { fn with_dyn_type_scope(&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; @@ -1025,7 +1025,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { fn lower_assoc_ty_constraint( &mut self, constraint: &AssocTyConstraint, - itctx: ImplTraitContext<'_>, + itctx: ImplTraitContext<'_, 'hir>, ) -> hir::TypeBinding<'hir> { debug!("lower_assoc_ty_constraint(constraint={:?}, itctx={:?})", constraint, itctx); @@ -1122,7 +1122,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { fn lower_generic_arg( &mut self, arg: &ast::GenericArg, - itctx: ImplTraitContext<'_>, + itctx: ImplTraitContext<'_, 'hir>, ) -> hir::GenericArg<'hir> { match arg { ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(<)), @@ -1178,8 +1178,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } } - fn lower_ty(&mut self, t: &Ty, itctx: ImplTraitContext<'_>) -> P> { - 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( @@ -1188,7 +1188,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { qself: &Option, path: &Path, param_mode: ParamMode, - itctx: ImplTraitContext<'_>, + 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); @@ -1203,11 +1203,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { hir::Ty { hir_id: self.next_id(), kind, span } } - fn ty_tup(&mut self, span: Span, tys: HirVec>) -> hir::Ty<'hir> { + 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<'hir> { + 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, @@ -1223,23 +1223,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); } @@ -1251,11 +1260,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, }), )) @@ -1267,21 +1276,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) @@ -1314,7 +1323,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 { @@ -1325,10 +1334,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)], }), )) } @@ -1376,7 +1385,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { span: Span, fn_def_id: Option, opaque_ty_node_id: NodeId, - lower_bounds: impl FnOnce(&mut LoweringContext<'_, '_>) -> hir::GenericBounds<'hir>, + 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={:?})", @@ -1411,7 +1420,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, @@ -1461,8 +1470,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { &mut self, opaque_ty_id: NodeId, parent_index: DefIndex, - bounds: &hir::GenericBounds<'hir>, - ) -> (HirVec>, HirVec>) { + bounds: hir::GenericBounds<'hir>, + ) -> (&'hir [hir::GenericArg<'hir>], HirVec>) { debug!( "lifetimes_from_impl_trait_bounds(opaque_ty_id={:?}, \ parent_index={:?}, \ @@ -1603,8 +1612,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 }, }); } @@ -1626,10 +1635,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( @@ -1638,7 +1647,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { qself: &Option, p: &Path, param_mode: ParamMode, - mut itctx: ImplTraitContext<'_>, + 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())); @@ -1647,12 +1656,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 @@ -1728,8 +1735,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { itctx.reborrow(), None, ) - }) - .collect(), + }, + )), span: p.span, }); @@ -1749,7 +1756,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { // e.g., `Vec` in `Vec::new` or `::Item` in // `::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", @@ -1763,7 +1770,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { // 3. `<>::IntoIter>::Item` // * final path is `<<>::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, @@ -1781,7 +1788,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. @@ -1802,21 +1809,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { ) -> 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, } } @@ -1834,7 +1837,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { param_mode: ParamMode, expected_lifetimes: usize, parenthesized_generic_args: ParenthesizedGenericArgs, - itctx: ImplTraitContext<'_>, + itctx: ImplTraitContext<'_, 'hir>, explicit_owner: Option, ) -> hir::PathSegment<'hir> { let (mut generic_args, infer_args) = if let Some(ref generic_args) = segment.args { @@ -1967,20 +1970,20 @@ 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<'_>, + 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 { @@ -1991,10 +1994,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, @@ -2012,13 +2014,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 { @@ -2027,7 +2028,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, + ) }) } @@ -2050,7 +2054,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 { @@ -2101,7 +2104,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { mut in_band_ty_params: Option<(DefId, &mut Vec>)>, impl_trait_return_allow: bool, make_ret_async: Option, - ) -> P> { + ) -> &'hir hir::FnDecl<'hir> { debug!( "lower_fn_decl(\ fn_decl: {:?}, \ @@ -2131,16 +2134,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(¶m.ty, ImplTraitContext::Universal(ibty)) - } else { - this.lower_ty_direct(¶m.ty, ImplTraitContext::disallowed()) - } - }) - .collect::>() + this.arena.alloc_from_iter(inputs.iter().map(|param| { + if let Some((_, ibty)) = &mut in_band_ty_params { + this.lower_ty_direct(¶m.ty, ImplTraitContext::Universal(ibty)) + } else { + this.lower_ty_direct(¶m.ty, ImplTraitContext::disallowed()) + } + })) }); let output = if let Some(ret_id) = make_ret_async { @@ -2161,7 +2161,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } }; - P(hir::FnDecl { + self.arena.alloc(hir::FnDecl { inputs, output, c_variadic, @@ -2309,19 +2309,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, }; @@ -2360,22 +2359,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` @@ -2388,13 +2387,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { // Compute the `T` in `Future` 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, &[])), }; // "" - 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(), @@ -2404,13 +2403,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { }); // ::std::future::Future - 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, @@ -2420,7 +2423,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { fn lower_param_bound( &mut self, tpb: &GenericBound, - itctx: ImplTraitContext<'_>, + itctx: ImplTraitContext<'_, 'hir>, ) -> hir::GenericBound<'hir> { match *tpb { GenericBound::Trait(ref ty, modifier) => hir::GenericBound::Trait( @@ -2472,8 +2475,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { &mut self, params: &[GenericParam], add_bounds: &NodeMap>, - mut itctx: ImplTraitContext<'_>, - ) -> hir::HirVec> { + mut itctx: ImplTraitContext<'_, 'hir>, + ) -> HirVec> { params .iter() .map(|param| self.lower_generic_param(param, add_bounds, itctx.reborrow())) @@ -2484,11 +2487,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { &mut self, param: &GenericParam, add_bounds: &NodeMap>, - mut itctx: ImplTraitContext<'_>, + mut itctx: ImplTraitContext<'_, 'hir>, ) -> hir::GenericParam<'hir> { let mut bounds = self .with_anonymous_lifetime_mode(AnonymousLifetimeMode::ReportError, |this| { - this.lower_param_bounds(¶m.bounds, itctx.reborrow()) + this.lower_param_bounds_mut(¶m.bounds, itctx.reborrow()) }); let (name, kind) = match param.kind { @@ -2524,8 +2527,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { GenericParamKind::Type { ref default, .. } => { let add_bounds = add_bounds.get(¶m.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 { @@ -2555,8 +2558,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { name, span: param.ident.span, pure_wrt_drop: attr::contains_name(¶m.attrs, sym::may_dangle), - attrs: self.lower_attrs(¶m.attrs), - bounds, + attrs: self.lower_attrs_arena(¶m.attrs), + bounds: self.arena.alloc_from_iter(bounds), kind, } } @@ -2564,7 +2567,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { fn lower_trait_ref( &mut self, p: &TraitRef, - itctx: ImplTraitContext<'_>, + 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, @@ -2576,7 +2579,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { fn lower_poly_trait_ref( &mut self, p: &PolyTraitRef, - mut itctx: ImplTraitContext<'_>, + mut itctx: ImplTraitContext<'_, 'hir>, ) -> hir::PolyTraitRef<'hir> { let bound_generic_params = self.lower_generic_params( &p.bound_generic_params, @@ -2587,18 +2590,30 @@ 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<'hir> { + 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<'_>, + itctx: ImplTraitContext<'_, 'hir>, ) -> hir::GenericBounds<'hir> { + self.arena.alloc_from_iter(self.lower_param_bounds_mut(bounds, itctx)) + } + + fn lower_param_bounds_mut( + &mut self, + bounds: &[GenericBound], + mut itctx: ImplTraitContext<'_, 'hir>, + ) -> Vec> { bounds.iter().map(|bound| self.lower_param_bound(bound, itctx.reborrow())).collect() } @@ -2836,10 +2851,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)], }), )), } @@ -3035,7 +3050,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 { @@ -3081,7 +3096,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { &mut self, span: Span, components: &[Symbol], - params: Option>>, + params: Option<&'hir hir::GenericArgs<'hir>>, is_value: bool, ) -> hir::Path<'hir> { let ns = if is_value { Namespace::ValueNS } else { Namespace::TypeNS }; @@ -3106,7 +3121,7 @@ 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), } } @@ -3122,7 +3137,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { 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, }; @@ -3130,7 +3145,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)), } diff --git a/src/librustc/hir/lowering/expr.rs b/src/librustc/hir/lowering/expr.rs index a5871e02dd0b9..c32cfdd07e0b8 100644 --- a/src/librustc/hir/lowering/expr.rs +++ b/src/librustc/hir/lowering/expr.rs @@ -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) @@ -670,7 +667,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; @@ -733,7 +729,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. @@ -816,7 +811,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) @@ -1325,9 +1320,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())); @@ -1338,11 +1334,15 @@ impl<'hir> LoweringContext<'_, 'hir> { &mut self, span: Span, components: &[Symbol], - params: Option>>, + 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( @@ -1372,10 +1372,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)], }), )); diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index d4705e9795c87..2fd59c4a1b114 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -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; @@ -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); @@ -323,7 +315,6 @@ impl<'hir> LoweringContext<'_, 'hir> { ) }, ); - let decl = this.arena.alloc(decl.into_inner()); let sig = hir::FnSig { decl, header: this.lower_fn_header(header) }; hir::ItemKind::Fn(sig, generics, body_id) }) @@ -335,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 { @@ -431,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, ) } @@ -637,17 +628,14 @@ impl<'hir> LoweringContext<'_, 'hir> { /// `NodeId`s. (See, e.g., #56128.) 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 } } @@ -658,7 +646,7 @@ impl<'hir> LoweringContext<'_, 'hir> { 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(), } } @@ -686,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"), @@ -752,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, @@ -776,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( @@ -799,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()), @@ -855,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())), @@ -890,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) => { @@ -966,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, } } @@ -1270,7 +1254,6 @@ impl<'hir> LoweringContext<'_, 'hir> { ) }, ); - let decl = self.arena.alloc(decl.into_inner()); (generics, hir::FnSig { header, decl }) } @@ -1315,7 +1298,7 @@ impl<'hir> LoweringContext<'_, 'hir> { pub(super) fn lower_generics( &mut self, generics: &Generics, - itctx: ImplTraitContext<'_>, + 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 @@ -1382,11 +1365,9 @@ impl<'hir> LoweringContext<'_, 'hir> { 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, } }) @@ -1402,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, }) }) diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index a0b45639be9c2..13ae89e77b26c 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -364,22 +364,6 @@ impl<'hir> PathSegment<'hir> { PathSegment { ident, hir_id: None, res: None, infer_args: true, args: None } } - pub fn new( - ident: Ident, - hir_id: Option, - res: Option, - 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<'hir> { if let Some(ref args) = self.args { args diff --git a/src/librustc/hir/ptr.rs b/src/librustc/hir/ptr.rs index b5d0c6b051f8d..b43817c9601b3 100644 --- a/src/librustc/hir/ptr.rs +++ b/src/librustc/hir/ptr.rs @@ -22,14 +22,6 @@ pub fn P(value: T) -> P { P { ptr: box value } } -impl P { - // 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 Deref for P { type Target = T; From 36f95ab3fa654d64c1ba77bc494c5cecf29d7229 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 1 Dec 2019 16:08:58 +0100 Subject: [PATCH 6/7] Fallout in other crates. --- src/librustc_lint/builtin.rs | 14 +-- src/librustc_lint/nonstandard_style.rs | 6 +- src/librustc_lint/types.rs | 4 +- src/librustc_metadata/rmeta/encoder.rs | 6 +- .../borrow_check/diagnostics/region_name.rs | 16 ++-- src/librustc_mir/hair/pattern/check_match.rs | 2 +- src/librustc_mir/hair/pattern/mod.rs | 2 +- src/librustc_mir/transform/mod.rs | 2 +- src/librustc_passes/dead.rs | 8 +- src/librustc_passes/hir_stats.rs | 18 ++-- src/librustc_passes/liveness.rs | 6 +- src/librustc_privacy/lib.rs | 31 +++--- src/librustc_typeck/astconv.rs | 94 ++++++++++--------- src/librustc_typeck/check/closure.rs | 18 ++-- src/librustc_typeck/check/compare_method.rs | 4 +- src/librustc_typeck/check/expr.rs | 10 +- src/librustc_typeck/check/method/confirm.rs | 6 +- src/librustc_typeck/check/method/mod.rs | 2 +- src/librustc_typeck/check/method/suggest.rs | 2 +- src/librustc_typeck/check/mod.rs | 40 ++++---- src/librustc_typeck/check/pat.rs | 10 +- src/librustc_typeck/check/regionck.rs | 2 +- src/librustc_typeck/check/wfcheck.rs | 6 +- src/librustc_typeck/check/writeback.rs | 2 +- src/librustc_typeck/coherence/unsafety.rs | 2 +- src/librustc_typeck/collect.rs | 34 +++---- src/librustc_typeck/impl_wf_check.rs | 4 +- src/librustc_typeck/lib.rs | 9 +- src/librustdoc/clean/mod.rs | 46 ++++----- src/librustdoc/doctree.rs | 68 +++++++------- 30 files changed, 248 insertions(+), 226 deletions(-) diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 2d9e960716f4e..fea01db4d54cc 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -983,7 +983,7 @@ impl UnreachablePub { cx: &LateContext<'_, '_>, what: &str, id: hir::HirId, - vis: &hir::Visibility, + vis: &hir::Visibility<'_>, span: Span, exportable: bool, ) { @@ -1065,7 +1065,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`. @@ -1081,7 +1081,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 `::Assoc`, which does not need a // bound. Let's see if this type does that. @@ -1095,7 +1095,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, @@ -1533,7 +1533,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, @@ -1554,7 +1554,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)> { @@ -1585,7 +1585,7 @@ impl ExplicitOutlivesRequirements { fn consolidate_outlives_bound_spans( &self, lo: Span, - bounds: &hir::GenericBounds, + bounds: &hir::GenericBounds<'_>, bound_spans: Vec<(usize, Span)>, ) -> Vec { if bounds.is_empty() { diff --git a/src/librustc_lint/nonstandard_style.rs b/src/librustc_lint/nonstandard_style.rs index 8cf502b3a7405..12e6730e8919e 100644 --- a/src/librustc_lint/nonstandard_style.rs +++ b/src/librustc_lint/nonstandard_style.rs @@ -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", ¶m.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, @@ -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", ¶m.name.ident()); } diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index ba2087d2f2620..65018194af2d3 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -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); } diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index 84d5d529adf76..0fe53011d4f46 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -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 { diff --git a/src/librustc_mir/borrow_check/diagnostics/region_name.rs b/src/librustc_mir/borrow_check/diagnostics/region_name.rs index e551e2eb59fed..37e2b68692d5e 100644 --- a/src/librustc_mir/borrow_check/diagnostics/region_name.rs +++ b/src/librustc_mir/borrow_check/diagnostics/region_name.rs @@ -410,7 +410,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { ) -> Option { 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 { - 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 { // 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) { diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index 47f2b480850d6..8cf49edd0a276 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -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( diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index 6dd3c0f80da24..c782eda917fe2 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -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 { diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index 06d0b8c72927a..39647b587f56e 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -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, ) { diff --git a/src/librustc_passes/dead.rs b/src/librustc_passes/dead.rs index a13c9aff70a22..09d6d2a1be251 100644 --- a/src/librustc_passes/dead.rs +++ b/src/librustc_passes/dead.rs @@ -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) { diff --git a/src/librustc_passes/hir_stats.rs b/src/librustc_passes/hir_stats.rs index 5ec1d458a96db..49ec8d01d952d 100644 --- a/src/librustc_passes/hir_stats.rs +++ b/src/librustc_passes/hir_stats.rs @@ -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) } diff --git a/src/librustc_passes/liveness.rs b/src/librustc_passes/liveness.rs index ea4479ef5ce7c..4f7db91dcdaa6 100644 --- a/src/librustc_passes/liveness.rs +++ b/src/librustc_passes/liveness.rs @@ -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 { diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index a72b3b74cbbe4..c00f5752e1be0 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -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 . - 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 ¶m.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) { diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 8e0f5d17b9fb8..f3ac159a3aa2a 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -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>, - 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>, ) -> (SubstsRef<'tcx>, Vec>, Option>) { @@ -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> { @@ -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>, Option>) { 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>, potential_assoc_types: Vec, - 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>, 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>( + pub fn prohibit_generics<'a, T: IntoIterator>>( &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>, 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>, - 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> { + pub fn ty_of_arg(&self, ty: &hir::Ty<'_>, expected_ty: Option>) -> 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"); diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs index feb904ee71cae..a94a6929450e6 100644 --- a/src/librustc_typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -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, expected: Expectation<'tcx>, @@ -59,7 +59,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, expr: &hir::Expr<'_>, opt_kind: Option, - decl: &'tcx hir::FnDecl, + decl: &'tcx hir::FnDecl<'tcx>, body: &'tcx hir::Body<'tcx>, gen: Option, expected_sig: Option>, @@ -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>, ) -> 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| { diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index 3643761a9c621..79bad233fd10d 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -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, 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 diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 4da4ce7680bf5..6c4b4ee179806 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -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> { diff --git a/src/librustc_typeck/check/method/confirm.rs b/src/librustc_typeck/check/method/confirm.rs index 98645b3463ef7..4b5963af283a0 100644 --- a/src/librustc_typeck/check/method/confirm.rs +++ b/src/librustc_typeck/check/method/confirm.rs @@ -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. diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index 41fd8d46346fd..877b1a3cc24c6 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -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>, diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index f19e8c9ab1c78..d98a11b879ec6 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -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 */), } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index f8e494a6ccdd6..c6c3ada49e312 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -784,7 +784,7 @@ fn adt_destructor(tcx: TyCtxt<'_>, def_id: DefId) -> Option { 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, @@ -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>, &'b [hir::PathSegment]) { + ) -> (Res, Option>, &'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>, res: Res, span: Span, diff --git a/src/librustc_typeck/check/pat.rs b/src/librustc_typeck/check/pat.rs index 3fb6d5227f77b..156126a748a21 100644 --- a/src/librustc_typeck/check/pat.rs +++ b/src/librustc_typeck/check/pat.rs @@ -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>, &'b [hir::PathSegment]), - qpath: &hir::QPath, + path_resolution: (Res, Option>, &'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, 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>, diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index 1ce7748badbf1..a42b666f11620 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -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, diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 1c8278480aa20..fa829d1b990d0 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -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, + ast_self_ty: &hir::Ty<'_>, + ast_trait_ref: &Option>, ) { debug!("check_impl: {:?}", item); @@ -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); diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index ca9a4763ed0a4..2db6e24be052b 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -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); diff --git a/src/librustc_typeck/coherence/unsafety.rs b/src/librustc_typeck/coherence/unsafety.rs index 639fd1721a236..eee292c55a8a4 100644 --- a/src/librustc_typeck/coherence/unsafety.rs +++ b/src/librustc_typeck/coherence/unsafety.rs @@ -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, ) { diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 01f11f669f75b..9604a9ade929e 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -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) { 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, 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( tcx: TyCtxt<'tcx>, - generics: &'tcx hir::Generics, - decl: &'tcx hir::FnDecl, + generics: &'tcx hir::Generics<'tcx>, + decl: &'tcx hir::FnDecl<'tcx>, ) -> Option { 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 + Captures<'tcx> { + generics: &'a hir::Generics<'a>, +) -> impl Iterator> + 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( diff --git a/src/librustc_typeck/impl_wf_check.rs b/src/librustc_typeck/impl_wf_check.rs index 6e13b75237c1c..55b2ad4446790 100644 --- a/src/librustc_typeck/impl_wf_check.rs +++ b/src/librustc_typeck/impl_wf_check.rs @@ -89,7 +89,7 @@ impl ItemLikeVisitor<'tcx> for ImplWfCheck<'tcx> { fn 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 { diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index ac99a5b4c9fa6..d9b7e98ea75c3 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -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. diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index bf0e3872995b6..db17d23c910e2 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -306,7 +306,7 @@ impl Clean for [ast::Attribute] { } } -impl Clean for hir::GenericBound { +impl Clean 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 for hir::Lifetime { } } -impl Clean for hir::GenericParam { +impl Clean for hir::GenericParam<'_> { fn clean(&self, _: &DocContext<'_>) -> Lifetime { match self.kind { hir::GenericParamKind::Lifetime { .. } => { @@ -469,7 +469,7 @@ impl Clean> for ty::RegionKind { } } -impl Clean for hir::WherePredicate { +impl Clean for hir::WherePredicate<'_> { fn clean(&self, cx: &DocContext<'_>) -> WherePredicate { match *self { hir::WherePredicate::BoundPredicate(ref wbp) => WherePredicate::BoundPredicate { @@ -615,7 +615,7 @@ impl Clean for ty::GenericParamDef { } } -impl Clean for hir::GenericParam { +impl Clean for hir::GenericParam<'_> { fn clean(&self, cx: &DocContext<'_>) -> GenericParamDef { let (name, kind) = match self.kind { hir::GenericParamKind::Lifetime { .. } => { @@ -657,12 +657,12 @@ impl Clean for hir::GenericParam { } } -impl Clean for hir::Generics { +impl Clean 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 for (&'a ty::Generics, ty::GenericPredicates<'tcx } impl<'a> Clean - for (&'a hir::FnSig<'a>, &'a hir::Generics, hir::BodyId, Option) + for (&'a hir::FnSig<'a>, &'a hir::Generics<'a>, hir::BodyId, Option) { fn clean(&self, cx: &DocContext<'_>) -> Method { let (generics, decl) = @@ -933,7 +933,7 @@ impl Clean for doctree::Function<'_> { } } -impl<'a> Clean for (&'a [hir::Ty], &'a [ast::Ident]) { +impl<'a> Clean for (&'a [hir::Ty<'a>], &'a [ast::Ident]) { fn clean(&self, cx: &DocContext<'_>) -> Arguments { Arguments { values: self @@ -953,7 +953,7 @@ impl<'a> Clean for (&'a [hir::Ty], &'a [ast::Ident]) { } } -impl<'a> Clean for (&'a [hir::Ty], hir::BodyId) { +impl<'a> Clean 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 for (&'a [hir::Ty], hir::BodyId) { } } -impl<'a, A: Copy> Clean for (&'a hir::FnDecl, A) +impl<'a, A: Copy> Clean for (&'a hir::FnDecl<'a>, A) where - (&'a [hir::Ty], A): Clean, + (&'a [hir::Ty<'a>], A): Clean, { fn clean(&self, cx: &DocContext<'_>) -> FnDecl { FnDecl { @@ -1013,7 +1013,7 @@ impl<'tcx> Clean for (DefId, ty::PolyFnSig<'tcx>) { } } -impl Clean for hir::FunctionRetTy { +impl Clean 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 for hir::IsAuto { } } -impl Clean for hir::TraitRef { +impl Clean for hir::TraitRef<'_> { fn clean(&self, cx: &DocContext<'_>) -> Type { resolve_type(cx, self.path.clean(cx), self.hir_ref_id) } } -impl Clean for hir::PolyTraitRef { +impl Clean for hir::PolyTraitRef<'_> { fn clean(&self, cx: &DocContext<'_>) -> PolyTrait { PolyTrait { trait_: self.trait_ref.clean(cx), @@ -1324,7 +1324,7 @@ impl Clean for ty::AssocItem { } } -impl Clean for hir::Ty { +impl Clean for hir::Ty<'_> { fn clean(&self, cx: &DocContext<'_>) -> Type { use rustc::hir::*; @@ -1480,7 +1480,7 @@ impl Clean 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 for ty::FieldDef { } } -impl Clean for hir::Visibility { +impl Clean for hir::Visibility<'_> { fn clean(&self, cx: &DocContext<'_>) -> Visibility { match self.node { hir::VisibilityKind::Public => Visibility::Public, @@ -1937,7 +1937,7 @@ impl Clean for syntax_pos::Span { } } -impl Clean for hir::Path { +impl Clean for hir::Path<'_> { fn clean(&self, cx: &DocContext<'_>) -> Path { Path { global: self.is_global(), @@ -1947,7 +1947,7 @@ impl Clean for hir::Path { } } -impl Clean for hir::GenericArgs { +impl Clean 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 for hir::GenericArgs { } } -impl Clean for hir::PathSegment { +impl Clean 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 for doctree::OpaqueTy<'_> { } } -impl Clean for hir::BareFnTy { +impl Clean 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 for attr::Deprecation { } } -impl Clean for hir::TypeBinding { +impl Clean for hir::TypeBinding<'_> { fn clean(&self, cx: &DocContext<'_>) -> TypeBinding { TypeBinding { name: self.ident.name.clean(cx), kind: self.kind.clean(cx) } } } -impl Clean for hir::TypeBindingKind { +impl Clean for hir::TypeBindingKind<'_> { fn clean(&self, cx: &DocContext<'_>) -> TypeBindingKind { match *self { hir::TypeBindingKind::Equality { ref ty } => { diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index 3c621f513b18a..46eddede0d518 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -28,7 +28,7 @@ pub struct Module<'hir> { pub statics: Vec>, pub constants: Vec>, pub traits: Vec>, - pub vis: &'hir hir::Visibility, + pub vis: &'hir hir::Visibility<'hir>, pub impls: Vec>, pub foreigns: Vec>, pub macros: Vec>, @@ -41,7 +41,7 @@ impl Module<'hir> { pub fn new( name: Option, 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>, - 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, - pub for_: &'hir hir::Ty, + pub generics: &'hir hir::Generics<'hir>, + pub trait_: &'hir Option>, + 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, - 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, } From 71f745852a1e22602bf4964a3d8308043ac46171 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 26 Dec 2019 17:36:54 +0100 Subject: [PATCH 7/7] Address review. --- src/librustc/hir/lowering.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 110788c66c759..395ed54d3c6e1 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -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; @@ -897,7 +898,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { }); let mut lowered_params: Vec<_> = - lowered_generics.params.into_iter().chain(in_band_defs.into_iter()).collect(); + lowered_generics.params.into_iter().chain(in_band_defs).collect(); // FIXME(const_generics): the compiler doesn't always cope with // unsorted generic parameters at the moment, so we make sure @@ -2489,9 +2490,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { add_bounds: &NodeMap>, mut itctx: ImplTraitContext<'_, 'hir>, ) -> hir::GenericParam<'hir> { - let mut bounds = self + let mut bounds: Vec<_> = self .with_anonymous_lifetime_mode(AnonymousLifetimeMode::ReportError, |this| { - this.lower_param_bounds_mut(¶m.bounds, itctx.reborrow()) + this.lower_param_bounds_mut(¶m.bounds, itctx.reborrow()).collect() }); let (name, kind) = match param.kind { @@ -2609,12 +2610,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { self.arena.alloc_from_iter(self.lower_param_bounds_mut(bounds, itctx)) } - fn lower_param_bounds_mut( - &mut self, - bounds: &[GenericBound], - mut itctx: ImplTraitContext<'_, 'hir>, - ) -> Vec> { - bounds.iter().map(|bound| self.lower_param_bound(bound, itctx.reborrow())).collect() + fn lower_param_bounds_mut<'s>( + &'s mut self, + bounds: &'s [GenericBound], + mut itctx: ImplTraitContext<'s, 'hir>, + ) -> impl Iterator> + 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> {