Skip to content

Commit 71a1182

Browse files
Expand the proc-macro composability test vector (#1600)
### What Add parse_item_impl attribute macro that parses impl blocks and apply it to contractimpl to test macro composition. ### Why The existing tests only validated function-level macro composition. This verifies that soroban-sdk macros compose correctly with impl-level attribute macros. What's under test is pretty minor but easy to test to include so why not. For #1544
1 parent 434b9a8 commit 71a1182

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

tests-expanded/test_macros_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
extern crate core;
55
#[prelude_import]
66
use core::prelude::rust_2021::*;
7-
use proc_macros::parse_item_fn;
7+
use proc_macros::{parse_item_fn, parse_item_impl};
88
use soroban_sdk::{contract, contractimpl};
99
pub struct Contract;
1010
///ContractArgs is a type for building arg lists for functions defined in "Contract".
@@ -313,9 +313,9 @@ mod test {
313313
ignore: false,
314314
ignore_message: ::core::option::Option::None,
315315
source_file: "tests/macros/src/lib.rs",
316-
start_line: 25usize,
316+
start_line: 26usize,
317317
start_col: 8usize,
318-
end_line: 25usize,
318+
end_line: 26usize,
319319
end_col: 18usize,
320320
compile_fail: false,
321321
no_run: false,

tests-expanded/test_macros_wasm32v1-none.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
extern crate core;
55
#[prelude_import]
66
use core::prelude::rust_2021::*;
7-
use proc_macros::parse_item_fn;
7+
use proc_macros::{parse_item_fn, parse_item_impl};
88
use soroban_sdk::{contract, contractimpl};
99
pub struct Contract;
1010
///ContractArgs is a type for building arg lists for functions defined in "Contract".

tests/macros/proc_macros/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
/// soroban-sdk macros are composable and compatible with a variety of other macros.
33
use proc_macro::TokenStream;
44
use quote::quote;
5-
use syn::{parse_macro_input, ItemFn};
5+
use syn::{parse_macro_input, ItemFn, ItemImpl};
6+
7+
/// An attribute macro that expects to be used on an impl.
8+
#[proc_macro_attribute]
9+
pub fn parse_item_impl(_metadata: TokenStream, input: TokenStream) -> TokenStream {
10+
let item = parse_macro_input!(input as ItemImpl);
11+
quote! { #item }.into()
12+
}
613

714
/// An attribute macro that expects to be used on a function.
815
#[proc_macro_attribute]

tests/macros/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
// validating that they are composable and compatible.
33

44
#![no_std]
5-
use proc_macros::parse_item_fn;
5+
use proc_macros::{parse_item_fn, parse_item_impl};
66
use soroban_sdk::{contract, contractimpl};
77

88
#[contract]
99
pub struct Contract;
1010

1111
#[contractimpl]
12+
#[parse_item_impl]
1213
impl Contract {
1314
// Test that attribute macros that expect to be used on fns are composable with contractimpl.
1415
#[parse_item_fn]

0 commit comments

Comments
 (0)