Skip to content

Commit f412269

Browse files
m-ou-sede-vri-es
authored andcommitted
Work around Rust hygiene bug.
See: rust-lang/rust#74036 Fixes #14.
1 parent 13953e9 commit f412269

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

assert2-macros/src/hygiene_bug.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use proc_macro::{Delimiter, Group, TokenStream, TokenTree};
2+
3+
pub fn fix(ts: TokenStream) -> TokenStream {
4+
ts.into_iter()
5+
.map(|t| match t {
6+
TokenTree::Group(g) => {
7+
let mut fixed = Group::new(
8+
match g.delimiter() {
9+
Delimiter::None => Delimiter::Parenthesis,
10+
d => d,
11+
},
12+
fix(g.stream()),
13+
);
14+
fixed.set_span(g.span());
15+
TokenTree::Group(fixed)
16+
}
17+
t => t,
18+
})
19+
.collect()
20+
}

assert2-macros/src/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@ type FormatArgs = Punctuated<syn::Expr, syn::token::Comma>;
1515
#[proc_macro_hack]
1616
#[doc(hidden)]
1717
pub fn check_impl(tokens: TokenStream) -> TokenStream {
18-
check_or_assert_impl(syn::parse_macro_input!(tokens)).into()
18+
hygiene_bug::fix(check_or_assert_impl(syn::parse_macro_input!(tokens)).into())
1919
}
2020

21+
mod hygiene_bug;
22+
2123
#[cfg(feature = "let-assert")]
2224
mod let_assert;
2325

2426
#[cfg(feature = "let-assert")]
2527
#[proc_macro]
2628
#[doc(hidden)]
2729
pub fn let_assert_impl(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
28-
let_assert::let_assert_impl(syn::parse_macro_input!(tokens)).into()
30+
hygiene_bug::fix(let_assert::let_assert_impl(syn::parse_macro_input!(tokens)).into())
2931
}
3032

3133
/// Real implementation for assert!() and check!().

0 commit comments

Comments
 (0)