Skip to content

Commit 65c77bc

Browse files
authored
Rollup merge of #66188 - Centril:fnsig, r=davidtwco
`MethodSig` -> `FnSig` & Use it in `ItemKind::Fn` In both AST & HIR, rename `MethodSig` to `FnSig` and then proceed to use it in `ItemKind::Fn` so that the overall structure is more regular. r? @davidtwco
2 parents 76db11c + b4c6abc commit 65c77bc

File tree

35 files changed

+167
-182
lines changed

35 files changed

+167
-182
lines changed

Diff for: src/librustc/hir/intravisit.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub enum FnKind<'a> {
4545
ItemFn(Ident, &'a Generics, FnHeader, &'a Visibility, &'a [Attribute]),
4646

4747
/// `fn foo(&self)`
48-
Method(Ident, &'a MethodSig, Option<&'a Visibility>, &'a [Attribute]),
48+
Method(Ident, &'a FnSig, Option<&'a Visibility>, &'a [Attribute]),
4949

5050
/// `|x, y| {}`
5151
Closure(&'a [Attribute]),
@@ -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)

Diff for: src/librustc/hir/lowering/item.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ impl LoweringContext<'_> {
306306
self.lower_const_body(e)
307307
)
308308
}
309-
ItemKind::Fn(ref decl, header, ref generics, ref body) => {
309+
ItemKind::Fn(FnSig { ref decl, header }, ref generics, ref body) => {
310310
let fn_def_id = self.resolver.definitions().local_def_id(id);
311311
self.with_new_scopes(|this| {
312312
this.current_item = Some(ident.span);
@@ -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::FnSig { 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)),
@@ -1260,11 +1255,11 @@ impl LoweringContext<'_> {
12601255
fn lower_method_sig(
12611256
&mut self,
12621257
generics: &Generics,
1263-
sig: &MethodSig,
1258+
sig: &FnSig,
12641259
fn_def_id: DefId,
12651260
impl_trait_return_allow: bool,
12661261
is_async: Option<NodeId>,
1267-
) -> (hir::Generics, hir::MethodSig) {
1262+
) -> (hir::Generics, hir::FnSig) {
12681263
let header = self.lower_fn_header(sig.header);
12691264
let (generics, decl) = self.add_in_band_defs(
12701265
generics,
@@ -1277,7 +1272,7 @@ impl LoweringContext<'_> {
12771272
is_async,
12781273
),
12791274
);
1280-
(generics, hir::MethodSig { header, decl })
1275+
(generics, hir::FnSig { header, decl })
12811276
}
12821277

12831278
fn lower_is_auto(&mut self, a: IsAuto) -> hir::IsAuto {

Diff for: src/librustc/hir/map/blocks.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -158,25 +158,25 @@ impl<'a> FnLikeNode<'a> {
158158

159159
pub fn body(self) -> ast::BodyId {
160160
self.handle(|i: ItemFnParts<'a>| i.body,
161-
|_, _, _: &'a ast::MethodSig, _, body: ast::BodyId, _, _| body,
161+
|_, _, _: &'a ast::FnSig, _, body: ast::BodyId, _, _| body,
162162
|c: ClosureParts<'a>| c.body)
163163
}
164164

165165
pub fn decl(self) -> &'a FnDecl {
166166
self.handle(|i: ItemFnParts<'a>| &*i.decl,
167-
|_, _, sig: &'a ast::MethodSig, _, _, _, _| &sig.decl,
167+
|_, _, sig: &'a ast::FnSig, _, _, _, _| &sig.decl,
168168
|c: ClosureParts<'a>| c.decl)
169169
}
170170

171171
pub fn span(self) -> Span {
172172
self.handle(|i: ItemFnParts<'_>| i.span,
173-
|_, _, _: &'a ast::MethodSig, _, _, span, _| span,
173+
|_, _, _: &'a ast::FnSig, _, _, span, _| span,
174174
|c: ClosureParts<'_>| c.span)
175175
}
176176

177177
pub fn id(self) -> ast::HirId {
178178
self.handle(|i: ItemFnParts<'_>| i.id,
179-
|id, _, _: &'a ast::MethodSig, _, _, _, _| id,
179+
|id, _, _: &'a ast::FnSig, _, _, _, _| id,
180180
|c: ClosureParts<'_>| c.id)
181181
}
182182

@@ -199,7 +199,7 @@ impl<'a> FnLikeNode<'a> {
199199
let closure = |c: ClosureParts<'a>| {
200200
FnKind::Closure(c.attrs)
201201
};
202-
let method = |_, ident: Ident, sig: &'a ast::MethodSig, vis, _, _, attrs| {
202+
let method = |_, ident: Ident, sig: &'a ast::FnSig, vis, _, _, attrs| {
203203
FnKind::Method(ident, sig, vis, attrs)
204204
};
205205
self.handle(item, method, closure)
@@ -209,7 +209,7 @@ impl<'a> FnLikeNode<'a> {
209209
I: FnOnce(ItemFnParts<'a>) -> A,
210210
M: FnOnce(ast::HirId,
211211
Ident,
212-
&'a ast::MethodSig,
212+
&'a ast::FnSig,
213213
Option<&'a ast::Visibility>,
214214
ast::BodyId,
215215
Span,
@@ -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"),

Diff for: src/librustc/hir/map/def_collector.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
100100

101101
// Pick the def data. This need not be unique, but the more
102102
// information we encapsulate into, the better
103-
let def_data = match i.kind {
103+
let def_data = match &i.kind {
104104
ItemKind::Impl(..) => DefPathData::Impl,
105105
ItemKind::Mod(..) if i.ident.name == kw::Invalid => {
106106
return visit::walk_item(self, i);
@@ -109,19 +109,14 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
109109
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) |
110110
ItemKind::OpaqueTy(..) | ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) |
111111
ItemKind::TyAlias(..) => DefPathData::TypeNs(i.ident.name),
112-
ItemKind::Fn(
113-
ref decl,
114-
ref header,
115-
ref generics,
116-
ref body,
117-
) if header.asyncness.node.is_async() => {
112+
ItemKind::Fn(sig, generics, body) if sig.header.asyncness.node.is_async() => {
118113
return self.visit_async_fn(
119114
i.id,
120115
i.ident.name,
121116
i.span,
122-
header,
117+
&sig.header,
123118
generics,
124-
decl,
119+
&sig.decl,
125120
body,
126121
)
127122
}
@@ -228,7 +223,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
228223

229224
fn visit_impl_item(&mut self, ii: &'a ImplItem) {
230225
let def_data = match ii.kind {
231-
ImplItemKind::Method(MethodSig {
226+
ImplItemKind::Method(FnSig {
232227
ref header,
233228
ref decl,
234229
}, ref body) if header.asyncness.node.is_async() => {

Diff for: src/librustc/hir/map/mod.rs

+7-7
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
}

Diff for: src/librustc/hir/mod.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1876,9 +1876,10 @@ pub struct MutTy {
18761876
pub mutbl: Mutability,
18771877
}
18781878

1879-
/// Represents a method's signature in a trait declaration or implementation.
1879+
/// Represents a function's signature in a trait declaration,
1880+
/// trait implementation, or a free function.
18801881
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
1881-
pub struct MethodSig {
1882+
pub struct FnSig {
18821883
pub header: FnHeader,
18831884
pub decl: P<FnDecl>,
18841885
}
@@ -1921,7 +1922,7 @@ pub enum TraitItemKind {
19211922
/// An associated constant with an optional value (otherwise `impl`s must contain a value).
19221923
Const(P<Ty>, Option<BodyId>),
19231924
/// A method with an optional body.
1924-
Method(MethodSig, TraitMethod),
1925+
Method(FnSig, TraitMethod),
19251926
/// An associated type with (possibly empty) bounds and optional concrete
19261927
/// type.
19271928
Type(GenericBounds, Option<P<Ty>>),
@@ -1955,7 +1956,7 @@ pub enum ImplItemKind {
19551956
/// of the expression.
19561957
Const(P<Ty>, BodyId),
19571958
/// A method implementation with the given signature and body.
1958-
Method(MethodSig, BodyId),
1959+
Method(FnSig, BodyId),
19591960
/// An associated type.
19601961
TyAlias(P<Ty>),
19611962
/// An associated `type = impl Trait`.
@@ -2534,7 +2535,7 @@ pub enum ItemKind {
25342535
/// A `const` item.
25352536
Const(P<Ty>, BodyId),
25362537
/// A function declaration.
2537-
Fn(P<FnDecl>, FnHeader, Generics, BodyId),
2538+
Fn(FnSig, Generics, BodyId),
25382539
/// A module.
25392540
Mod(Mod),
25402541
/// An external module, e.g. `extern { .. }`.
@@ -2599,7 +2600,7 @@ impl ItemKind {
25992600

26002601
pub fn generics(&self) -> Option<&Generics> {
26012602
Some(match *self {
2602-
ItemKind::Fn(_, _, ref generics, _) |
2603+
ItemKind::Fn(_, ref generics, _) |
26032604
ItemKind::TyAlias(_, ref generics) |
26042605
ItemKind::OpaqueTy(OpaqueTy { ref generics, impl_trait_fn: None, .. }) |
26052606
ItemKind::Enum(_, ref generics) |

Diff for: src/librustc/hir/print.rs

+4-4
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,
@@ -835,7 +835,7 @@ impl<'a> State<'a> {
835835
}
836836
pub fn print_method_sig(&mut self,
837837
ident: ast::Ident,
838-
m: &hir::MethodSig,
838+
m: &hir::FnSig,
839839
generics: &hir::Generics,
840840
vis: &hir::Visibility,
841841
arg_names: &[ast::Ident],

Diff for: src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs

+3-3
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
})

Diff for: src/librustc/middle/reachable.rs

+3-3
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
};

Diff for: src/librustc/middle/resolve_lifetime.rs

+4-4
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) => {

0 commit comments

Comments
 (0)