summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/lib.rs b/src/lib.rs
index d3aafa9..8a9561b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -148,7 +148,7 @@ impl VisitMut for Scrub<'_> {
syn::Expr::ForLoop(expr) => {
syn::visit_mut::visit_expr_for_loop_mut(self, expr);
// TODO: Should we allow other attributes?
- if expr.attrs.len() != 1 || !expr.attrs[0].path().is_ident("await_") {
+ if expr.attrs.len() != 1 || !expr.attrs[0].meta.path().is_ident(AWAIT_ATTR_NAME) {
return;
}
let syn::ExprForLoop {
@@ -160,11 +160,7 @@ impl VisitMut for Scrub<'_> {
..
} = expr;
- let attr = attrs.pop().unwrap();
- if let Err(e) = attr.meta.require_path_only() {
- *i = syn::parse2(e.to_compile_error()).unwrap();
- return;
- }
+ attrs.pop().unwrap();
let crate_path = self.crate_path;
*i = syn::parse_quote! {{
@@ -271,6 +267,10 @@ pub fn try_stream_inner(input: TokenStream) -> TokenStream {
.into()
}
+// syn 2.0 wont parse `#[await] for x in xs {}`
+// because `await` is a keyword, use `await_` instead
+const AWAIT_ATTR_NAME: &str = "await_";
+
/// Replace `for await` with `#[await] for`, which will be later transformed into a `next` loop.
fn replace_for_await(input: impl IntoIterator<Item = TokenTree>) -> TokenStream2 {
let mut input = input.into_iter().peekable();
@@ -281,7 +281,9 @@ fn replace_for_await(input: impl IntoIterator<Item = TokenTree>) -> TokenStream2
TokenTree::Ident(ident) => {
match input.peek() {
Some(TokenTree::Ident(next)) if ident == "for" && next == "await" => {
- tokens.extend(quote!(#[await_]));
+ let next_span = next.span();
+ let next = syn::Ident::new(AWAIT_ATTR_NAME, next_span);
+ tokens.extend(quote!(#[#next]));
let _ = input.next();
}
_ => {}