Skip to content

Commit 30d7279

Browse files
committed
hir::ItemKind::Fn: use hir::MethodSig
1 parent c34472b commit 30d7279

File tree

16 files changed

+77
-81
lines changed

16 files changed

+77
-81
lines changed

src/librustc/hir/intravisit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,13 +481,13 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
481481
visitor.visit_ty(typ);
482482
visitor.visit_nested_body(body);
483483
}
484-
ItemKind::Fn(ref declaration, header, ref generics, body_id) => {
484+
ItemKind::Fn(ref sig, ref generics, body_id) => {
485485
visitor.visit_fn(FnKind::ItemFn(item.ident,
486486
generics,
487-
header,
487+
sig.header,
488488
&item.vis,
489489
&item.attrs),
490-
declaration,
490+
&sig.decl,
491491
body_id,
492492
item.span,
493493
item.hir_id)

src/librustc/hir/lowering/item.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ impl LoweringContext<'_> {
317317
// declaration (decl), not the return types.
318318
let body_id = this.lower_maybe_async_body(&decl, header.asyncness.node, body);
319319

320-
let (generics, fn_decl) = this.add_in_band_defs(
320+
let (generics, decl) = this.add_in_band_defs(
321321
generics,
322322
fn_def_id,
323323
AnonymousLifetimeMode::PassThrough,
@@ -328,13 +328,8 @@ impl LoweringContext<'_> {
328328
header.asyncness.node.opt_return_id()
329329
),
330330
);
331-
332-
hir::ItemKind::Fn(
333-
fn_decl,
334-
this.lower_fn_header(header),
335-
generics,
336-
body_id,
337-
)
331+
let sig = hir::MethodSig { decl, header: this.lower_fn_header(header) };
332+
hir::ItemKind::Fn(sig, generics, body_id)
338333
})
339334
}
340335
ItemKind::Mod(ref m) => hir::ItemKind::Mod(self.lower_mod(m)),

src/librustc/hir/map/blocks.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,16 +219,16 @@ impl<'a> FnLikeNode<'a> {
219219
{
220220
match self.node {
221221
map::Node::Item(i) => match i.kind {
222-
ast::ItemKind::Fn(ref decl, header, ref generics, block) =>
222+
ast::ItemKind::Fn(ref sig, ref generics, block) =>
223223
item_fn(ItemFnParts {
224224
id: i.hir_id,
225225
ident: i.ident,
226-
decl: &decl,
226+
decl: &sig.decl,
227227
body: block,
228228
vis: &i.vis,
229229
span: i.span,
230230
attrs: &i.attrs,
231-
header,
231+
header: sig.header,
232232
generics,
233233
}),
234234
_ => bug!("item FnLikeNode that is not fn-like"),

src/librustc/hir/map/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,21 @@ impl<'hir> Entry<'hir> {
4949
match self.node {
5050
Node::Item(ref item) => {
5151
match item.kind {
52-
ItemKind::Fn(ref fn_decl, _, _, _) => Some(fn_decl),
52+
ItemKind::Fn(ref sig, _, _) => Some(&sig.decl),
5353
_ => None,
5454
}
5555
}
5656

5757
Node::TraitItem(ref item) => {
5858
match item.kind {
59-
TraitItemKind::Method(ref method_sig, _) => Some(&method_sig.decl),
59+
TraitItemKind::Method(ref sig, _) => Some(&sig.decl),
6060
_ => None
6161
}
6262
}
6363

6464
Node::ImplItem(ref item) => {
6565
match item.kind {
66-
ImplItemKind::Method(ref method_sig, _) => Some(&method_sig.decl),
66+
ImplItemKind::Method(ref sig, _) => Some(&sig.decl),
6767
_ => None,
6868
}
6969
}
@@ -85,7 +85,7 @@ impl<'hir> Entry<'hir> {
8585
match item.kind {
8686
ItemKind::Const(_, body) |
8787
ItemKind::Static(.., body) |
88-
ItemKind::Fn(_, _, _, body) => Some(body),
88+
ItemKind::Fn(.., body) => Some(body),
8989
_ => None,
9090
}
9191
}
@@ -605,7 +605,7 @@ impl<'hir> Map<'hir> {
605605
Node::TraitItem(ref trait_item) => Some(&trait_item.generics),
606606
Node::Item(ref item) => {
607607
match item.kind {
608-
ItemKind::Fn(_, _, ref generics, _) |
608+
ItemKind::Fn(_, ref generics, _) |
609609
ItemKind::TyAlias(_, ref generics) |
610610
ItemKind::Enum(_, ref generics) |
611611
ItemKind::Struct(_, ref generics) |
@@ -702,9 +702,9 @@ impl<'hir> Map<'hir> {
702702
..
703703
}) => true,
704704
Node::Item(&Item {
705-
kind: ItemKind::Fn(_, header, ..),
705+
kind: ItemKind::Fn(ref sig, ..),
706706
..
707-
}) => header.constness == Constness::Const,
707+
}) => sig.header.constness == Constness::Const,
708708
_ => false,
709709
}
710710
}

src/librustc/hir/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2534,7 +2534,7 @@ pub enum ItemKind {
25342534
/// A `const` item.
25352535
Const(P<Ty>, BodyId),
25362536
/// A function declaration.
2537-
Fn(P<FnDecl>, FnHeader, Generics, BodyId),
2537+
Fn(MethodSig, Generics, BodyId),
25382538
/// A module.
25392539
Mod(Mod),
25402540
/// An external module, e.g. `extern { .. }`.
@@ -2599,7 +2599,7 @@ impl ItemKind {
25992599

26002600
pub fn generics(&self) -> Option<&Generics> {
26012601
Some(match *self {
2602-
ItemKind::Fn(_, _, ref generics, _) |
2602+
ItemKind::Fn(_, ref generics, _) |
26032603
ItemKind::TyAlias(_, ref generics) |
26042604
ItemKind::OpaqueTy(OpaqueTy { ref generics, impl_trait_fn: None, .. }) |
26052605
ItemKind::Enum(_, ref generics) |

src/librustc/hir/print.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,10 @@ impl<'a> State<'a> {
533533
self.s.word(";");
534534
self.end(); // end the outer cbox
535535
}
536-
hir::ItemKind::Fn(ref decl, header, ref param_names, body) => {
536+
hir::ItemKind::Fn(ref sig, ref param_names, body) => {
537537
self.head("");
538-
self.print_fn(decl,
539-
header,
538+
self.print_fn(&sig.decl,
539+
sig.header,
540540
Some(item.ident.name),
541541
param_names,
542542
&item.vis,

src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
3131
if let Some(hir_id) = self.tcx().hir().as_local_hir_id(def_id) {
3232
let fndecl = match self.tcx().hir().get(hir_id) {
3333
Node::Item(&hir::Item {
34-
kind: hir::ItemKind::Fn(ref fndecl, ..),
34+
kind: hir::ItemKind::Fn(ref m, ..),
3535
..
36-
}) => &fndecl,
37-
Node::TraitItem(&hir::TraitItem {
36+
})
37+
| Node::TraitItem(&hir::TraitItem {
3838
kind: hir::TraitItemKind::Method(ref m, ..),
3939
..
4040
})

src/librustc/middle/reachable.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn item_might_be_inlined(tcx: TyCtxt<'tcx>, item: &hir::Item, attrs: CodegenFnAt
3333
}
3434

3535
match item.kind {
36-
hir::ItemKind::Fn(_, header, ..) if header.is_const() => {
36+
hir::ItemKind::Fn(ref sig, ..) if sig.header.is_const() => {
3737
return true;
3838
}
3939
hir::ItemKind::Impl(..) |
@@ -225,8 +225,8 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
225225
// If we are building an executable, only explicitly extern
226226
// types need to be exported.
227227
if let Node::Item(item) = *node {
228-
let reachable = if let hir::ItemKind::Fn(_, header, ..) = item.kind {
229-
header.abi != Abi::Rust
228+
let reachable = if let hir::ItemKind::Fn(ref sig, ..) = item.kind {
229+
sig.header.abi != Abi::Rust
230230
} else {
231231
false
232232
};

src/librustc/middle/resolve_lifetime.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
460460

461461
fn visit_item(&mut self, item: &'tcx hir::Item) {
462462
match item.kind {
463-
hir::ItemKind::Fn(ref decl, _, ref generics, _) => {
464-
self.visit_early_late(None, decl, generics, |this| {
463+
hir::ItemKind::Fn(ref sig, ref generics, _) => {
464+
self.visit_early_late(None, &sig.decl, generics, |this| {
465465
intravisit::walk_item(this, item);
466466
});
467467
}
@@ -1524,8 +1524,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
15241524
{
15251525
match parent {
15261526
Node::Item(item) => {
1527-
if let hir::ItemKind::Fn(decl, _, _, _) = &item.kind {
1528-
find_arg_use_span(&decl.inputs);
1527+
if let hir::ItemKind::Fn(sig, _, _) = &item.kind {
1528+
find_arg_use_span(&sig.decl.inputs);
15291529
}
15301530
},
15311531
Node::ImplItem(impl_item) => {

src/librustc/traits/error_reporting.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
383383
let hir = &self.tcx.hir();
384384
let node = hir.find(hir_id)?;
385385
if let hir::Node::Item(
386-
hir::Item{kind: hir::ItemKind::Fn(_ ,fn_header ,_ , body_id), .. }) = &node {
386+
hir::Item{kind: hir::ItemKind::Fn(sig, _, body_id), .. }) = &node {
387387
self.describe_generator(*body_id).or_else(||
388-
Some(if let hir::FnHeader{ asyncness: hir::IsAsync::Async, .. } = fn_header {
388+
Some(if let hir::FnHeader{ asyncness: hir::IsAsync::Async, .. } = sig.header {
389389
"an async function"
390390
} else {
391391
"a function"
@@ -1081,7 +1081,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10811081
}
10821082

10831083
hir::Node::Item(hir::Item {
1084-
kind: hir::ItemKind::Fn(_, _, generics, _), ..
1084+
kind: hir::ItemKind::Fn(_, generics, _), ..
10851085
}) |
10861086
hir::Node::TraitItem(hir::TraitItem {
10871087
generics,
@@ -1112,7 +1112,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
11121112
kind: hir::ItemKind::Impl(_, _, _, generics, ..), span, ..
11131113
}) |
11141114
hir::Node::Item(hir::Item {
1115-
kind: hir::ItemKind::Fn(_, _, generics, _), span, ..
1115+
kind: hir::ItemKind::Fn(_, generics, _), span, ..
11161116
}) |
11171117
hir::Node::Item(hir::Item {
11181118
kind: hir::ItemKind::TyAlias(_, generics), span, ..
@@ -1436,12 +1436,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14361436
let parent_node = hir.get_parent_node(obligation.cause.body_id);
14371437
let node = hir.find(parent_node);
14381438
if let Some(hir::Node::Item(hir::Item {
1439-
kind: hir::ItemKind::Fn(decl, _, _, body_id),
1439+
kind: hir::ItemKind::Fn(sig, _, body_id),
14401440
..
14411441
})) = node {
14421442
let body = hir.body(*body_id);
14431443
if let hir::ExprKind::Block(blk, _) = &body.value.kind {
1444-
if decl.output.span().overlaps(span) && blk.expr.is_none() &&
1444+
if sig.decl.output.span().overlaps(span) && blk.expr.is_none() &&
14451445
"()" == &trait_ref.self_ty().to_string()
14461446
{
14471447
// FIXME(estebank): When encountering a method with a trait
@@ -1493,20 +1493,20 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14931493
}
14941494
Node::Item(&hir::Item {
14951495
span,
1496-
kind: hir::ItemKind::Fn(ref decl, ..),
1496+
kind: hir::ItemKind::Fn(ref sig, ..),
14971497
..
14981498
}) |
14991499
Node::ImplItem(&hir::ImplItem {
15001500
span,
1501-
kind: hir::ImplItemKind::Method(hir::MethodSig { ref decl, .. }, _),
1501+
kind: hir::ImplItemKind::Method(ref sig, _),
15021502
..
15031503
}) |
15041504
Node::TraitItem(&hir::TraitItem {
15051505
span,
1506-
kind: hir::TraitItemKind::Method(hir::MethodSig { ref decl, .. }, _),
1506+
kind: hir::TraitItemKind::Method(ref sig, _),
15071507
..
15081508
}) => {
1509-
(self.tcx.sess.source_map().def_span(span), decl.inputs.iter()
1509+
(self.tcx.sess.source_map().def_span(span), sig.decl.inputs.iter()
15101510
.map(|arg| match arg.clone().kind {
15111511
hir::TyKind::Tup(ref tys) => ArgKind::Tuple(
15121512
Some(arg.span),
@@ -2040,11 +2040,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
20402040
.and_then(|parent_did| self.tcx.hir().get_if_local(parent_did));
20412041
debug!("note_obligation_cause_for_async_await: parent_node={:?}", parent_node);
20422042
if let Some(hir::Node::Item(hir::Item {
2043-
kind: hir::ItemKind::Fn(_, header, _, _),
2043+
kind: hir::ItemKind::Fn(sig, _, _),
20442044
..
20452045
})) = parent_node {
2046-
debug!("note_obligation_cause_for_async_await: header={:?}", header);
2047-
if header.asyncness != hir::IsAsync::Async {
2046+
debug!("note_obligation_cause_for_async_await: header={:?}", sig.header);
2047+
if sig.header.asyncness != hir::IsAsync::Async {
20482048
return false;
20492049
}
20502050
}

src/librustc_metadata/rmeta/encoder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,10 +1095,10 @@ impl EncodeContext<'tcx> {
10951095
self.encode_rendered_const_for_body(body_id)
10961096
)
10971097
}
1098-
hir::ItemKind::Fn(_, header, .., body) => {
1098+
hir::ItemKind::Fn(ref sig, .., body) => {
10991099
let data = FnData {
1100-
asyncness: header.asyncness,
1101-
constness: header.constness,
1100+
asyncness: sig.header.asyncness,
1101+
constness: sig.header.constness,
11021102
param_names: self.encode_fn_param_names_for_body(body),
11031103
};
11041104

@@ -1284,14 +1284,14 @@ impl EncodeContext<'tcx> {
12841284

12851285
let mir = match item.kind {
12861286
hir::ItemKind::Static(..) | hir::ItemKind::Const(..) => true,
1287-
hir::ItemKind::Fn(_, header, ..) => {
1287+
hir::ItemKind::Fn(ref sig, ..) => {
12881288
let generics = tcx.generics_of(def_id);
12891289
let needs_inline =
12901290
(generics.requires_monomorphization(tcx) ||
12911291
tcx.codegen_fn_attrs(def_id).requests_inline()) &&
12921292
!self.metadata_output_only();
12931293
let always_encode_mir = self.tcx.sess.opts.debugging_opts.always_encode_mir;
1294-
needs_inline || header.constness == hir::Constness::Const || always_encode_mir
1294+
needs_inline || sig.header.constness == hir::Constness::Const || always_encode_mir
12951295
}
12961296
_ => false,
12971297
};

src/librustc_mir/build/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ pub fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> Body<'_> {
3030
// Figure out what primary body this item has.
3131
let (body_id, return_ty_span) = match tcx.hir().get(id) {
3232
Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(_, decl, body_id, _, _), .. })
33-
| Node::Item(hir::Item { kind: hir::ItemKind::Fn(decl, _, _, body_id), .. })
33+
| Node::Item(
34+
hir::Item {
35+
kind: hir::ItemKind::Fn(hir::MethodSig { decl, .. }, _, body_id),
36+
..
37+
}
38+
)
3439
| Node::ImplItem(
3540
hir::ImplItem {
3641
kind: hir::ImplItemKind::Method(hir::MethodSig { decl, .. }, body_id),

src/librustc_mir/transform/check_unsafety.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,10 +576,10 @@ fn is_enclosed(
576576
if used_unsafe.contains(&parent_id) {
577577
Some(("block".to_string(), parent_id))
578578
} else if let Some(Node::Item(&hir::Item {
579-
kind: hir::ItemKind::Fn(_, header, _, _),
579+
kind: hir::ItemKind::Fn(ref sig, _, _),
580580
..
581581
})) = tcx.hir().find(parent_id) {
582-
match header.unsafety {
582+
match sig.header.unsafety {
583583
hir::Unsafety::Unsafe => Some(("fn".to_string(), parent_id)),
584584
hir::Unsafety::Normal => None,
585585
}

0 commit comments

Comments
 (0)