Skip to content

Commit b4c6abc

Browse files
committed
ast::ItemKind::Fn: use ast::FnSig
1 parent 2cd48e8 commit b4c6abc

File tree

16 files changed

+51
-63
lines changed

16 files changed

+51
-63
lines changed

src/librustc/hir/lowering/item.rs

Lines changed: 1 addition & 1 deletion
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);

src/librustc/hir/map/def_collector.rs

Lines changed: 4 additions & 9 deletions
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
}

src/librustc_interface/util.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -786,14 +786,17 @@ impl<'a> ReplaceBodyWithLoop<'a> {
786786
false
787787
}
788788
}
789+
790+
fn is_sig_const(sig: &ast::FnSig) -> bool {
791+
sig.header.constness.node == ast::Constness::Const || Self::should_ignore_fn(&sig.decl)
792+
}
789793
}
790794

791795
impl<'a> MutVisitor for ReplaceBodyWithLoop<'a> {
792796
fn visit_item_kind(&mut self, i: &mut ast::ItemKind) {
793797
let is_const = match i {
794798
ast::ItemKind::Static(..) | ast::ItemKind::Const(..) => true,
795-
ast::ItemKind::Fn(ref decl, ref header, _, _) =>
796-
header.constness.node == ast::Constness::Const || Self::should_ignore_fn(decl),
799+
ast::ItemKind::Fn(ref sig, _, _) => Self::is_sig_const(sig),
797800
_ => false,
798801
};
799802
self.run(is_const, |s| noop_visit_item_kind(i, s))
@@ -802,8 +805,7 @@ impl<'a> MutVisitor for ReplaceBodyWithLoop<'a> {
802805
fn flat_map_trait_item(&mut self, i: ast::TraitItem) -> SmallVec<[ast::TraitItem; 1]> {
803806
let is_const = match i.kind {
804807
ast::TraitItemKind::Const(..) => true,
805-
ast::TraitItemKind::Method(ast::FnSig { ref decl, ref header, .. }, _) =>
806-
header.constness.node == ast::Constness::Const || Self::should_ignore_fn(decl),
808+
ast::TraitItemKind::Method(ref sig, _) => Self::is_sig_const(sig),
807809
_ => false,
808810
};
809811
self.run(is_const, |s| noop_flat_map_trait_item(i, s))
@@ -812,8 +814,7 @@ impl<'a> MutVisitor for ReplaceBodyWithLoop<'a> {
812814
fn flat_map_impl_item(&mut self, i: ast::ImplItem) -> SmallVec<[ast::ImplItem; 1]> {
813815
let is_const = match i.kind {
814816
ast::ImplItemKind::Const(..) => true,
815-
ast::ImplItemKind::Method(ast::FnSig { ref decl, ref header, .. }, _) =>
816-
header.constness.node == ast::Constness::Const || Self::should_ignore_fn(decl),
817+
ast::ImplItemKind::Method(ref sig, _) => Self::is_sig_const(sig),
817818
_ => false,
818819
};
819820
self.run(is_const, |s| noop_flat_map_impl_item(i, s))

src/librustc_passes/ast_validation.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,12 +575,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
575575
.note("only trait implementations may be annotated with default").emit();
576576
}
577577
}
578-
ItemKind::Fn(ref decl, ref header, ref generics, _) => {
579-
self.visit_fn_header(header);
580-
self.check_fn_decl(decl);
578+
ItemKind::Fn(ref sig, ref generics, _) => {
579+
self.visit_fn_header(&sig.header);
580+
self.check_fn_decl(&sig.decl);
581581
// We currently do not permit const generics in `const fn`, as
582582
// this is tantamount to allowing compile-time dependent typing.
583-
if header.constness.node == Constness::Const {
583+
if sig.header.constness.node == Constness::Const {
584584
// Look for const generics and error if we find any.
585585
for param in &generics.params {
586586
match param.kind {

src/librustc_resolve/late.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> {
731731
match item.kind {
732732
ItemKind::TyAlias(_, ref generics) |
733733
ItemKind::OpaqueTy(_, ref generics) |
734-
ItemKind::Fn(_, _, ref generics, _) => {
734+
ItemKind::Fn(_, ref generics, _) => {
735735
self.with_generic_param_rib(generics, ItemRibKind(HasGenericParams::Yes),
736736
|this| visit::walk_item(this, item));
737737
}

src/librustc_save_analysis/dump_visitor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,8 +1334,8 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
13341334
);
13351335
}
13361336
}
1337-
Fn(ref decl, ref header, ref ty_params, ref body) => {
1338-
self.process_fn(item, &decl, &header, ty_params, &body)
1337+
Fn(ref sig, ref ty_params, ref body) => {
1338+
self.process_fn(item, &sig.decl, &sig.header, ty_params, &body)
13391339
}
13401340
Static(ref typ, _, ref expr) => self.process_static_or_const_item(item, typ, expr),
13411341
Const(ref typ, ref expr) => self.process_static_or_const_item(item, &typ, &expr),

src/librustc_save_analysis/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
180180

181181
pub fn get_item_data(&self, item: &ast::Item) -> Option<Data> {
182182
match item.kind {
183-
ast::ItemKind::Fn(ref decl, .., ref generics, _) => {
183+
ast::ItemKind::Fn(ref sig, .., ref generics, _) => {
184184
let qualname = format!("::{}",
185185
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id)));
186186
filter!(self.span_utils, item.ident.span);
@@ -190,7 +190,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
190190
span: self.span_from_span(item.ident.span),
191191
name: item.ident.to_string(),
192192
qualname,
193-
value: make_signature(decl, generics),
193+
value: make_signature(&sig.decl, generics),
194194
parent: None,
195195
children: vec![],
196196
decl_id: None,

src/librustc_save_analysis/sig.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ impl Sig for ast::Item {
376376

377377
Ok(extend_sig(ty, text, defs, vec![]))
378378
}
379-
ast::ItemKind::Fn(ref decl, header, ref generics, _) => {
379+
ast::ItemKind::Fn(ast::FnSig { ref decl, header }, ref generics, _) => {
380380
let mut text = String::new();
381381
if header.constness.node == ast::Constness::Const {
382382
text.push_str("const ");

src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2433,7 +2433,7 @@ pub enum ItemKind {
24332433
/// A function declaration (`fn`).
24342434
///
24352435
/// E.g., `fn foo(bar: usize) -> usize { .. }`.
2436-
Fn(P<FnDecl>, FnHeader, Generics, P<Block>),
2436+
Fn(FnSig, Generics, P<Block>),
24372437
/// A module declaration (`mod`).
24382438
///
24392439
/// E.g., `mod foo;` or `mod foo { .. }`.

src/libsyntax/mut_visit.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ pub fn visit_bounds<T: MutVisitor>(bounds: &mut GenericBounds, vis: &mut T) {
357357
}
358358

359359
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
360-
pub fn visit_method_sig<T: MutVisitor>(FnSig { header, decl }: &mut FnSig, vis: &mut T) {
360+
pub fn visit_fn_sig<T: MutVisitor>(FnSig { header, decl }: &mut FnSig, vis: &mut T) {
361361
vis.visit_fn_header(header);
362362
vis.visit_fn_decl(decl);
363363
}
@@ -878,9 +878,8 @@ pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) {
878878
vis.visit_ty(ty);
879879
vis.visit_expr(expr);
880880
}
881-
ItemKind::Fn(decl, header, generics, body) => {
882-
vis.visit_fn_decl(decl);
883-
vis.visit_fn_header(header);
881+
ItemKind::Fn(sig, generics, body) => {
882+
visit_fn_sig(sig, vis);
884883
vis.visit_generics(generics);
885884
vis.visit_block(body);
886885
}
@@ -938,7 +937,7 @@ pub fn noop_flat_map_trait_item<T: MutVisitor>(mut item: TraitItem, vis: &mut T)
938937
visit_opt(default, |default| vis.visit_expr(default));
939938
}
940939
TraitItemKind::Method(sig, body) => {
941-
visit_method_sig(sig, vis);
940+
visit_fn_sig(sig, vis);
942941
visit_opt(body, |body| vis.visit_block(body));
943942
}
944943
TraitItemKind::Type(bounds, default) => {
@@ -970,7 +969,7 @@ pub fn noop_flat_map_impl_item<T: MutVisitor>(mut item: ImplItem, visitor: &mut
970969
visitor.visit_expr(expr);
971970
}
972971
ImplItemKind::Method(sig, body) => {
973-
visit_method_sig(sig, visitor);
972+
visit_fn_sig(sig, visitor);
974973
visitor.visit_block(body);
975974
}
976975
ImplItemKind::TyAlias(ty) => visitor.visit_ty(ty),

0 commit comments

Comments
 (0)