Skip to content

Commit

Permalink
hir::ItemKind::Fn: use hir::MethodSig
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Nov 8, 2019
1 parent c34472b commit 30d7279
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 81 deletions.
6 changes: 3 additions & 3 deletions src/librustc/hir/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 3 additions & 8 deletions src/librustc/hir/lowering/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)),
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/hir/map/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand All @@ -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,
}
}
Expand Down Expand Up @@ -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) |
Expand Down Expand Up @@ -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,
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2534,7 +2534,7 @@ pub enum ItemKind {
/// A `const` item.
Const(P<Ty>, BodyId),
/// A function declaration.
Fn(P<FnDecl>, FnHeader, Generics, BodyId),
Fn(MethodSig, Generics, BodyId),
/// A module.
Mod(Mod),
/// An external module, e.g. `extern { .. }`.
Expand Down Expand Up @@ -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) |
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/hir/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, ..),
..
})
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/reachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..) |
Expand Down Expand Up @@ -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
};
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down Expand Up @@ -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) => {
Expand Down
26 changes: 13 additions & 13 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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, ..
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_metadata/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};

Expand Down Expand Up @@ -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,
};
Expand Down
7 changes: 6 additions & 1 deletion src/librustc_mir/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
Loading

0 comments on commit 30d7279

Please sign in to comment.