about summary refs log tree commit diff
path: root/src/libsyntax_ext
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-11-07 13:33:37 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2019-11-08 09:32:20 +0100
commitb4c6abcf9e6c1d2710e7ad6a9ce44b3ca6b10d52 (patch)
treecc97d122086c2cd6efd91a6d05583baf59c555fa /src/libsyntax_ext
parent2cd48e8a3b71256d7db1ac61e8994c06620238b6 (diff)
downloadrust-b4c6abcf9e6c1d2710e7ad6a9ce44b3ca6b10d52.tar.gz
rust-b4c6abcf9e6c1d2710e7ad6a9ce44b3ca6b10d52.zip
ast::ItemKind::Fn: use ast::FnSig
Diffstat (limited to 'src/libsyntax_ext')
-rw-r--r--src/libsyntax_ext/global_allocator.rs15
-rw-r--r--src/libsyntax_ext/test.rs14
-rw-r--r--src/libsyntax_ext/test_harness.rs7
3 files changed, 15 insertions, 21 deletions
diff --git a/src/libsyntax_ext/global_allocator.rs b/src/libsyntax_ext/global_allocator.rs
index 90d2ea38bc3..dc29e057455 100644
--- a/src/libsyntax_ext/global_allocator.rs
+++ b/src/libsyntax_ext/global_allocator.rs
@@ -1,7 +1,7 @@
 use crate::util::check_builtin_macro_attribute;
 
 use syntax::ast::{ItemKind, Mutability, Stmt, Ty, TyKind, Unsafety};
-use syntax::ast::{self, Param, Attribute, Expr, FnHeader, Generics, Ident};
+use syntax::ast::{self, Param, Attribute, Expr, FnSig, FnHeader, Generics, Ident};
 use syntax::expand::allocator::{AllocatorKind, AllocatorMethod, AllocatorTy, ALLOCATOR_METHODS};
 use syntax::ptr::P;
 use syntax::symbol::{kw, sym, Symbol};
@@ -73,15 +73,10 @@ impl AllocFnFactory<'_, '_> {
             .collect();
         let result = self.call_allocator(method.name, args);
         let (output_ty, output_expr) = self.ret_ty(&method.output, result);
-        let kind = ItemKind::Fn(
-            self.cx.fn_decl(abi_args, ast::FunctionRetTy::Ty(output_ty)),
-            FnHeader {
-                unsafety: Unsafety::Unsafe,
-                ..FnHeader::default()
-            },
-            Generics::default(),
-            self.cx.block_expr(output_expr),
-        );
+        let decl = self.cx.fn_decl(abi_args, ast::FunctionRetTy::Ty(output_ty));
+        let header = FnHeader { unsafety: Unsafety::Unsafe, ..FnHeader::default() };
+        let sig = FnSig { decl, header };
+        let kind = ItemKind::Fn(sig, Generics::default(), self.cx.block_expr(output_expr));
         let item = self.cx.item(
             self.span,
             self.cx.ident_of(&self.kind.fn_name(method.name), self.span),
diff --git a/src/libsyntax_ext/test.rs b/src/libsyntax_ext/test.rs
index b0da413d63a..8656100c921 100644
--- a/src/libsyntax_ext/test.rs
+++ b/src/libsyntax_ext/test.rs
@@ -310,15 +310,15 @@ fn test_type(cx: &ExtCtxt<'_>) -> TestType {
 fn has_test_signature(cx: &ExtCtxt<'_>, i: &ast::Item) -> bool {
     let has_should_panic_attr = attr::contains_name(&i.attrs, sym::should_panic);
     let ref sd = cx.parse_sess.span_diagnostic;
-    if let ast::ItemKind::Fn(ref decl, ref header, ref generics, _) = i.kind {
-        if header.unsafety == ast::Unsafety::Unsafe {
+    if let ast::ItemKind::Fn(ref sig, ref generics, _) = i.kind {
+        if sig.header.unsafety == ast::Unsafety::Unsafe {
             sd.span_err(
                 i.span,
                 "unsafe functions cannot be used for tests"
             );
             return false
         }
-        if header.asyncness.node.is_async() {
+        if sig.header.asyncness.node.is_async() {
             sd.span_err(
                 i.span,
                 "async functions cannot be used for tests"
@@ -329,13 +329,13 @@ fn has_test_signature(cx: &ExtCtxt<'_>, i: &ast::Item) -> bool {
 
         // If the termination trait is active, the compiler will check that the output
         // type implements the `Termination` trait as `libtest` enforces that.
-        let has_output = match decl.output {
+        let has_output = match sig.decl.output {
             ast::FunctionRetTy::Default(..) => false,
             ast::FunctionRetTy::Ty(ref t) if t.kind.is_unit() => false,
             _ => true
         };
 
-        if !decl.inputs.is_empty() {
+        if !sig.decl.inputs.is_empty() {
             sd.span_err(i.span, "functions used as tests can not have any arguments");
             return false;
         }
@@ -361,10 +361,10 @@ fn has_test_signature(cx: &ExtCtxt<'_>, i: &ast::Item) -> bool {
 }
 
 fn has_bench_signature(cx: &ExtCtxt<'_>, i: &ast::Item) -> bool {
-    let has_sig = if let ast::ItemKind::Fn(ref decl, _, _, _) = i.kind {
+    let has_sig = if let ast::ItemKind::Fn(ref sig, _, _) = i.kind {
         // N.B., inadequate check, but we're running
         // well before resolve, can't get too deep.
-        decl.inputs.len() == 1
+        sig.decl.inputs.len() == 1
     } else {
         false
     };
diff --git a/src/libsyntax_ext/test_harness.rs b/src/libsyntax_ext/test_harness.rs
index 33d41a7f53e..1492f6f575f 100644
--- a/src/libsyntax_ext/test_harness.rs
+++ b/src/libsyntax_ext/test_harness.rs
@@ -306,10 +306,9 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
         ecx.block(sp, vec![call_test_main])
     };
 
-    let main = ast::ItemKind::Fn(ecx.fn_decl(vec![], ast::FunctionRetTy::Ty(main_ret_ty)),
-                           ast::FnHeader::default(),
-                           ast::Generics::default(),
-                           main_body);
+    let decl = ecx.fn_decl(vec![], ast::FunctionRetTy::Ty(main_ret_ty));
+    let sig = ast::FnSig { decl, header: ast::FnHeader::default() };
+    let main = ast::ItemKind::Fn(sig, ast::Generics::default(), main_body);
 
     // Honor the reexport_test_harness_main attribute
     let main_id = match cx.reexport_test_harness_main {