Kyuuhachi/syn_derive

avoid parsing of expression in closure expecting attributes

Closed this issue · 8 comments

These require syn.features = ["full"] but AFAICT it would be possible to just accept any tokens?

Maybe I'm overlooking something thought.

It only has full as a dev-dependency; when compiling as a library only parsing and derive are used. If that's not what you're referring to, would you mind clarifying the question?

Well, syn doesn't support, e.g., #[parse(peek_func = |p| ...)] without the full feature.

I still don't know what you're talking about. syn::Expr requires full or derive. Could you explain what the actual issue is here?

#[derive(syn_derive::Parse)]
enum Test {
    #[parse(peek_func = |ps| ps.peek(syn::Token![for]) && ps.peek2(syn::Token![if]))]
    Test(syn::Ident),
}

Yields this error when compiling:

❯ cargo check
    Checking syn_derive_test v0.1.0
error: unsupported expression; enable syn's features=["full"]
 --> src/main.rs:7:25
  |
7 |     #[parse(peek_func = |ps| ps.peek(syn::Token![for]) && ps.peek2(syn::Token![if]))]
  |                         ^

(It is also not enought to add syn with full oneself):

[package]
name = "syn_derive_test"
version = "0.1.0"
edition = "2021"

[dependencies]
syn = { version = "2.0.38", features = ["full"] }
syn_derive = "0.1.7"

still yields the same error

Huh, seems you're right. Unfortunately it's not as simple as parsing until the next comma, since that could be inside a || or <>. I'd have to either reimplement a sizeable part of the expr parsing, which I'd rather not, or enable full.

As a compromise, I could add a full feature flag to syn_derive to enable it.

Huh, seems you're right. Unfortunately it's not as simple as parsing until the next comma, since that could be inside a || or <>. I'd have to either reimplement a sizeable part of the expr parsing, which I'd rather not, or enable full.

Right, I only now noticed that you also have attributes where a value can follow a function.

As a compromise, I could add a full feature flag to syn_derive to enable it.

I'm not sure how bad the overhead of full really is, so it might be fine to have it on by default as well.

Added an enabled-by-default full feature in v0.1.8. Thanks for reporting.