Skip to content

Commit 1f2db88

Browse files
committed
[update] 文脈 Ctx を明示的に用意しなくても良いようにした
1 parent 8395412 commit 1f2db88

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

crates/macros/src/impl/modifier.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ pub fn proc_macro_impl(_args: TokenStream, ast: ItemTrait) -> TokenStream {
1515
// 文脈マクロ
1616
#[macro_export]
1717
macro_rules! #macro_ident {
18+
({ $($body:tt)* }) => {
19+
// 文脈を用意
20+
struct Ctx;
21+
22+
// 文脈付き呼び出しへの変換 (関数定義ではなくブロックに変換される)
23+
#[modifier_caller(#trait_name)]
24+
fn __mymodifier_caller() {
25+
$($body)*
26+
}
27+
};
28+
1829
($($body:tt)*) => {{
1930
// 文脈付き呼び出しへの変換 (関数定義ではなくブロックに変換される)
2031
#[modifier_caller(#trait_name)]

crates/macros/tests/modifier_callee.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@ impl Object {
2525

2626
#[test]
2727
fn check_compile() {
28-
struct Ctx;
29-
a! {
28+
a! {{
3029
b! {
3130
c! {
3231
Object{}.method();
3332
fn_a();
3433
fn_b_c();
3534
}
3635
}
37-
}
36+
}}
3837
}

0 commit comments

Comments
 (0)