diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 659bfc4e63c6..519c1fe4cc8e 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 0157e89c96b0..4f1769dfd245 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 7701c33f9162..6d8fd9d2f011 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 cc5cb58173fd..d933f1e49e4a 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 8a450cf167a3..f54bc51baf1f 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 11a596a83177..9e2702a0ff25 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 4c349a27c215..1c8278480aa2 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 e5c0a6aadce4..bf0e3872995b 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) =