diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 920635d838738..72de8ccd952d3 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -481,13 +481,13 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { visitor.visit_ty(typ); visitor.visit_nested_body(body); } - ItemKind::Fn(ref declaration, header, ref generics, body_id) => { + ItemKind::Fn(ref sig, ref generics, body_id) => { visitor.visit_fn(FnKind::ItemFn(item.ident, generics, - header, + sig.header, &item.vis, &item.attrs), - declaration, + &sig.decl, body_id, item.span, item.hir_id) diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index 5fe463d783f4b..5bc9fcb12f178 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -317,7 +317,7 @@ impl LoweringContext<'_> { // declaration (decl), not the return types. let body_id = this.lower_maybe_async_body(&decl, header.asyncness.node, body); - let (generics, fn_decl) = this.add_in_band_defs( + let (generics, decl) = this.add_in_band_defs( generics, fn_def_id, AnonymousLifetimeMode::PassThrough, @@ -328,13 +328,8 @@ impl LoweringContext<'_> { header.asyncness.node.opt_return_id() ), ); - - hir::ItemKind::Fn( - fn_decl, - this.lower_fn_header(header), - generics, - body_id, - ) + let sig = hir::MethodSig { decl, header: this.lower_fn_header(header) }; + hir::ItemKind::Fn(sig, generics, body_id) }) } ItemKind::Mod(ref m) => hir::ItemKind::Mod(self.lower_mod(m)), diff --git a/src/librustc/hir/map/blocks.rs b/src/librustc/hir/map/blocks.rs index f670d5abe85e4..b2f4a015711db 100644 --- a/src/librustc/hir/map/blocks.rs +++ b/src/librustc/hir/map/blocks.rs @@ -219,16 +219,16 @@ impl<'a> FnLikeNode<'a> { { match self.node { map::Node::Item(i) => match i.kind { - ast::ItemKind::Fn(ref decl, header, ref generics, block) => + ast::ItemKind::Fn(ref sig, ref generics, block) => item_fn(ItemFnParts { id: i.hir_id, ident: i.ident, - decl: &decl, + decl: &sig.decl, body: block, vis: &i.vis, span: i.span, attrs: &i.attrs, - header, + header: sig.header, generics, }), _ => bug!("item FnLikeNode that is not fn-like"), diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index acadd77cc36c0..d7b1676c1d4d3 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -49,21 +49,21 @@ impl<'hir> Entry<'hir> { match self.node { Node::Item(ref item) => { match item.kind { - ItemKind::Fn(ref fn_decl, _, _, _) => Some(fn_decl), + ItemKind::Fn(ref sig, _, _) => Some(&sig.decl), _ => None, } } Node::TraitItem(ref item) => { match item.kind { - TraitItemKind::Method(ref method_sig, _) => Some(&method_sig.decl), + TraitItemKind::Method(ref sig, _) => Some(&sig.decl), _ => None } } Node::ImplItem(ref item) => { match item.kind { - ImplItemKind::Method(ref method_sig, _) => Some(&method_sig.decl), + ImplItemKind::Method(ref sig, _) => Some(&sig.decl), _ => None, } } @@ -85,7 +85,7 @@ impl<'hir> Entry<'hir> { match item.kind { ItemKind::Const(_, body) | ItemKind::Static(.., body) | - ItemKind::Fn(_, _, _, body) => Some(body), + ItemKind::Fn(.., body) => Some(body), _ => None, } } @@ -605,7 +605,7 @@ impl<'hir> Map<'hir> { Node::TraitItem(ref trait_item) => Some(&trait_item.generics), Node::Item(ref item) => { match item.kind { - ItemKind::Fn(_, _, ref generics, _) | + ItemKind::Fn(_, ref generics, _) | ItemKind::TyAlias(_, ref generics) | ItemKind::Enum(_, ref generics) | ItemKind::Struct(_, ref generics) | @@ -702,9 +702,9 @@ impl<'hir> Map<'hir> { .. }) => true, Node::Item(&Item { - kind: ItemKind::Fn(_, header, ..), + kind: ItemKind::Fn(ref sig, ..), .. - }) => header.constness == Constness::Const, + }) => sig.header.constness == Constness::Const, _ => false, } } diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index d409ca6f3c5f5..93503c1509448 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -2534,7 +2534,7 @@ pub enum ItemKind { /// A `const` item. Const(P, BodyId), /// A function declaration. - Fn(P, FnHeader, Generics, BodyId), + Fn(MethodSig, Generics, BodyId), /// A module. Mod(Mod), /// An external module, e.g. `extern { .. }`. @@ -2599,7 +2599,7 @@ impl ItemKind { pub fn generics(&self) -> Option<&Generics> { Some(match *self { - ItemKind::Fn(_, _, ref generics, _) | + ItemKind::Fn(_, ref generics, _) | ItemKind::TyAlias(_, ref generics) | ItemKind::OpaqueTy(OpaqueTy { ref generics, impl_trait_fn: None, .. }) | ItemKind::Enum(_, ref generics) | diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index a25c111b59871..69d2a9ad2810d 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -533,10 +533,10 @@ impl<'a> State<'a> { self.s.word(";"); self.end(); // end the outer cbox } - hir::ItemKind::Fn(ref decl, header, ref param_names, body) => { + hir::ItemKind::Fn(ref sig, ref param_names, body) => { self.head(""); - self.print_fn(decl, - header, + self.print_fn(&sig.decl, + sig.header, Some(item.ident.name), param_names, &item.vis, 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 f4751e591bf3c..db5557204e4da 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 @@ -31,10 +31,10 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { if let Some(hir_id) = self.tcx().hir().as_local_hir_id(def_id) { let fndecl = match self.tcx().hir().get(hir_id) { Node::Item(&hir::Item { - kind: hir::ItemKind::Fn(ref fndecl, ..), + kind: hir::ItemKind::Fn(ref m, ..), .. - }) => &fndecl, - Node::TraitItem(&hir::TraitItem { + }) + | Node::TraitItem(&hir::TraitItem { kind: hir::TraitItemKind::Method(ref m, ..), .. }) diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 8be64bf64b5e9..f77f5a72e60ce 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -33,7 +33,7 @@ fn item_might_be_inlined(tcx: TyCtxt<'tcx>, item: &hir::Item, attrs: CodegenFnAt } match item.kind { - hir::ItemKind::Fn(_, header, ..) if header.is_const() => { + hir::ItemKind::Fn(ref sig, ..) if sig.header.is_const() => { return true; } hir::ItemKind::Impl(..) | @@ -225,8 +225,8 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { // If we are building an executable, only explicitly extern // types need to be exported. if let Node::Item(item) = *node { - let reachable = if let hir::ItemKind::Fn(_, header, ..) = item.kind { - header.abi != Abi::Rust + let reachable = if let hir::ItemKind::Fn(ref sig, ..) = item.kind { + sig.header.abi != Abi::Rust } else { false }; diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 488d6332f7e39..f37d9b2827be0 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -460,8 +460,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { fn visit_item(&mut self, item: &'tcx hir::Item) { match item.kind { - hir::ItemKind::Fn(ref decl, _, ref generics, _) => { - self.visit_early_late(None, decl, generics, |this| { + hir::ItemKind::Fn(ref sig, ref generics, _) => { + self.visit_early_late(None, &sig.decl, generics, |this| { intravisit::walk_item(this, item); }); } @@ -1524,8 +1524,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { { match parent { Node::Item(item) => { - if let hir::ItemKind::Fn(decl, _, _, _) = &item.kind { - find_arg_use_span(&decl.inputs); + if let hir::ItemKind::Fn(sig, _, _) = &item.kind { + find_arg_use_span(&sig.decl.inputs); } }, Node::ImplItem(impl_item) => { diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index fe18a14d89058..54c0103422173 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -383,9 +383,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { let hir = &self.tcx.hir(); let node = hir.find(hir_id)?; if let hir::Node::Item( - hir::Item{kind: hir::ItemKind::Fn(_ ,fn_header ,_ , body_id), .. }) = &node { + hir::Item{kind: hir::ItemKind::Fn(sig, _, body_id), .. }) = &node { self.describe_generator(*body_id).or_else(|| - Some(if let hir::FnHeader{ asyncness: hir::IsAsync::Async, .. } = fn_header { + Some(if let hir::FnHeader{ asyncness: hir::IsAsync::Async, .. } = sig.header { "an async function" } else { "a function" @@ -1081,7 +1081,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } hir::Node::Item(hir::Item { - kind: hir::ItemKind::Fn(_, _, generics, _), .. + kind: hir::ItemKind::Fn(_, generics, _), .. }) | hir::Node::TraitItem(hir::TraitItem { generics, @@ -1112,7 +1112,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { kind: hir::ItemKind::Impl(_, _, _, generics, ..), span, .. }) | hir::Node::Item(hir::Item { - kind: hir::ItemKind::Fn(_, _, generics, _), span, .. + kind: hir::ItemKind::Fn(_, generics, _), span, .. }) | hir::Node::Item(hir::Item { kind: hir::ItemKind::TyAlias(_, generics), span, .. @@ -1436,12 +1436,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { let parent_node = hir.get_parent_node(obligation.cause.body_id); let node = hir.find(parent_node); if let Some(hir::Node::Item(hir::Item { - kind: hir::ItemKind::Fn(decl, _, _, body_id), + kind: hir::ItemKind::Fn(sig, _, body_id), .. })) = node { let body = hir.body(*body_id); if let hir::ExprKind::Block(blk, _) = &body.value.kind { - if decl.output.span().overlaps(span) && blk.expr.is_none() && + if sig.decl.output.span().overlaps(span) && blk.expr.is_none() && "()" == &trait_ref.self_ty().to_string() { // FIXME(estebank): When encountering a method with a trait @@ -1493,20 +1493,20 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } Node::Item(&hir::Item { span, - kind: hir::ItemKind::Fn(ref decl, ..), + kind: hir::ItemKind::Fn(ref sig, ..), .. }) | Node::ImplItem(&hir::ImplItem { span, - kind: hir::ImplItemKind::Method(hir::MethodSig { ref decl, .. }, _), + kind: hir::ImplItemKind::Method(ref sig, _), .. }) | Node::TraitItem(&hir::TraitItem { span, - kind: hir::TraitItemKind::Method(hir::MethodSig { ref decl, .. }, _), + kind: hir::TraitItemKind::Method(ref sig, _), .. }) => { - (self.tcx.sess.source_map().def_span(span), decl.inputs.iter() + (self.tcx.sess.source_map().def_span(span), sig.decl.inputs.iter() .map(|arg| match arg.clone().kind { hir::TyKind::Tup(ref tys) => ArgKind::Tuple( Some(arg.span), @@ -2040,11 +2040,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { .and_then(|parent_did| self.tcx.hir().get_if_local(parent_did)); debug!("note_obligation_cause_for_async_await: parent_node={:?}", parent_node); if let Some(hir::Node::Item(hir::Item { - kind: hir::ItemKind::Fn(_, header, _, _), + kind: hir::ItemKind::Fn(sig, _, _), .. })) = parent_node { - debug!("note_obligation_cause_for_async_await: header={:?}", header); - if header.asyncness != hir::IsAsync::Async { + debug!("note_obligation_cause_for_async_await: header={:?}", sig.header); + if sig.header.asyncness != hir::IsAsync::Async { return false; } } diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index afc81649e3719..c6677ea3534d0 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -1095,10 +1095,10 @@ impl EncodeContext<'tcx> { self.encode_rendered_const_for_body(body_id) ) } - hir::ItemKind::Fn(_, header, .., body) => { + hir::ItemKind::Fn(ref sig, .., body) => { let data = FnData { - asyncness: header.asyncness, - constness: header.constness, + asyncness: sig.header.asyncness, + constness: sig.header.constness, param_names: self.encode_fn_param_names_for_body(body), }; @@ -1284,14 +1284,14 @@ impl EncodeContext<'tcx> { let mir = match item.kind { hir::ItemKind::Static(..) | hir::ItemKind::Const(..) => true, - hir::ItemKind::Fn(_, header, ..) => { + hir::ItemKind::Fn(ref sig, ..) => { let generics = tcx.generics_of(def_id); let needs_inline = (generics.requires_monomorphization(tcx) || tcx.codegen_fn_attrs(def_id).requests_inline()) && !self.metadata_output_only(); let always_encode_mir = self.tcx.sess.opts.debugging_opts.always_encode_mir; - needs_inline || header.constness == hir::Constness::Const || always_encode_mir + needs_inline || sig.header.constness == hir::Constness::Const || always_encode_mir } _ => false, }; diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index ffb70180bbb4b..59301619b4bdd 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -30,7 +30,12 @@ pub fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> Body<'_> { // Figure out what primary body this item has. let (body_id, return_ty_span) = match tcx.hir().get(id) { Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(_, decl, body_id, _, _), .. }) - | Node::Item(hir::Item { kind: hir::ItemKind::Fn(decl, _, _, body_id), .. }) + | Node::Item( + hir::Item { + kind: hir::ItemKind::Fn(hir::MethodSig { decl, .. }, _, body_id), + .. + } + ) | Node::ImplItem( hir::ImplItem { kind: hir::ImplItemKind::Method(hir::MethodSig { decl, .. }, body_id), diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 7d5507168587b..4b57cb75cea48 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -576,10 +576,10 @@ fn is_enclosed( if used_unsafe.contains(&parent_id) { Some(("block".to_string(), parent_id)) } else if let Some(Node::Item(&hir::Item { - kind: hir::ItemKind::Fn(_, header, _, _), + kind: hir::ItemKind::Fn(ref sig, _, _), .. })) = tcx.hir().find(parent_id) { - match header.unsafety { + match sig.header.unsafety { hir::Unsafety::Unsafe => Some(("fn".to_string(), parent_id)), hir::Unsafety::Normal => None, } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index fe2c7a200d202..39a7996df0cdc 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -815,8 +815,8 @@ fn primary_body_of( hir::ItemKind::Const(ref ty, body) | hir::ItemKind::Static(ref ty, _, body) => Some((body, Some(ty), None, None)), - hir::ItemKind::Fn(ref decl, ref header, .., body) => - Some((body, None, Some(header), Some(decl))), + hir::ItemKind::Fn(ref sig, .., body) => + Some((body, None, Some(&sig.header), Some(&sig.decl))), _ => None, } @@ -1297,7 +1297,7 @@ fn check_fn<'a, 'tcx>( } if let Node::Item(item) = fcx.tcx.hir().get(fn_id) { - if let ItemKind::Fn(_, _, ref generics, _) = item.kind { + if let ItemKind::Fn(_, ref generics, _) = item.kind { if !generics.params.is_empty() { fcx.tcx.sess.span_err( span, @@ -1345,7 +1345,7 @@ fn check_fn<'a, 'tcx>( } if let Node::Item(item) = fcx.tcx.hir().get(fn_id) { - if let ItemKind::Fn(_, _, ref generics, _) = item.kind { + if let ItemKind::Fn(_, ref generics, _) = item.kind { if !generics.params.is_empty() { fcx.tcx.sess.span_err( span, @@ -4278,7 +4278,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let node = self.tcx.hir().get(self.tcx.hir().get_parent_item(id)); match node { Node::Item(&hir::Item { - kind: hir::ItemKind::Fn(_, _, _, body_id), .. + kind: hir::ItemKind::Fn(_, _, body_id), .. }) | Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Method(_, body_id), .. @@ -4303,23 +4303,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn get_node_fn_decl(&self, node: Node<'tcx>) -> Option<(&'tcx hir::FnDecl, ast::Ident, bool)> { match node { Node::Item(&hir::Item { - ident, kind: hir::ItemKind::Fn(ref decl, ..), .. + ident, kind: hir::ItemKind::Fn(ref sig, ..), .. }) => { // This is less than ideal, it will not suggest a return type span on any // method called `main`, regardless of whether it is actually the entry point, // but it will still present it as the reason for the expected type. - Some((decl, ident, ident.name != sym::main)) + Some((&sig.decl, ident, ident.name != sym::main)) } Node::TraitItem(&hir::TraitItem { - ident, kind: hir::TraitItemKind::Method(hir::MethodSig { - ref decl, .. - }, ..), .. - }) => Some((decl, ident, true)), + ident, kind: hir::TraitItemKind::Method(ref sig, ..), .. + }) => Some((&sig.decl, ident, true)), Node::ImplItem(&hir::ImplItem { - ident, kind: hir::ImplItemKind::Method(hir::MethodSig { - ref decl, .. - }, ..), .. - }) => Some((decl, ident, false)), + ident, kind: hir::ImplItemKind::Method(ref sig, ..), .. + }) => Some((&sig.decl, ident, false)), _ => None, } } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index ef84f1cb20f51..68fd29d04e33f 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -885,8 +885,8 @@ fn has_late_bound_regions<'tcx>(tcx: TyCtxt<'tcx>, node: Node<'tcx>) -> Option None, }, Node::Item(item) => match item.kind { - hir::ItemKind::Fn(ref fn_decl, .., ref generics, _) => { - has_late_bound_regions(tcx, generics, fn_decl) + hir::ItemKind::Fn(ref sig, .., ref generics, _) => { + has_late_bound_regions(tcx, generics, &sig.decl) } _ => None, }, @@ -1779,17 +1779,17 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> { match tcx.hir().get(hir_id) { TraitItem(hir::TraitItem { - kind: TraitItemKind::Method(MethodSig { header, decl }, TraitMethod::Provided(_)), + kind: TraitItemKind::Method(sig, TraitMethod::Provided(_)), .. }) | ImplItem(hir::ImplItem { - kind: ImplItemKind::Method(MethodSig { header, decl }, _), + kind: ImplItemKind::Method(sig, _), .. }) | Item(hir::Item { - kind: ItemKind::Fn(decl, header, _, _), + kind: ItemKind::Fn(sig, _, _), .. - }) => match get_infer_ret_ty(&decl.output) { + }) => match get_infer_ret_ty(&sig.decl.output) { Some(ty) => { let fn_sig = tcx.typeck_tables_of(def_id).liberated_fn_sigs()[hir_id]; let mut diag = bad_placeholder_type(tcx, ty.span); @@ -1805,7 +1805,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> { diag.emit(); ty::Binder::bind(fn_sig) }, - None => AstConv::ty_of_fn(&icx, header.unsafety, header.abi, decl) + None => AstConv::ty_of_fn(&icx, sig.header.unsafety, sig.header.abi, &sig.decl) }, TraitItem(hir::TraitItem { diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 5a83569f02a5c..aea9b7c38efba 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -438,8 +438,8 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { om.structs.push(self.visit_variant_data(item, ident.name, sd, gen)), hir::ItemKind::Union(ref sd, ref gen) => om.unions.push(self.visit_union_data(item, ident.name, sd, gen)), - hir::ItemKind::Fn(ref fd, header, ref gen, body) => - self.visit_fn(om, item, ident.name, &**fd, header, gen, body), + hir::ItemKind::Fn(ref sig, ref gen, body) => + self.visit_fn(om, item, ident.name, &sig.decl, sig.header, gen, body), hir::ItemKind::TyAlias(ref ty, ref gen) => { let t = Typedef { ty,