Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider depending on syn.features=["full"] #301

Closed
ModProg opened this issue Sep 1, 2023 · 9 comments · Fixed by #341
Closed

Consider depending on syn.features=["full"] #301

ModProg opened this issue Sep 1, 2023 · 9 comments · Fixed by #341

Comments

@ModProg
Copy link
Contributor

ModProg commented Sep 1, 2023

Otherwise this would not work:

#[derive(derive_more::Debug)]
enum Enum {
    A = if cfg!(unix) { 2 } else { 3 },
}
error: proc-macro derive panicked
 --> src/main.rs:1:10
  |
1 | #[derive(derive_more::Debug)]
  |          ^^^^^^^^^^^^^^^^^^
  |
  = help: message: called `Result::unwrap()` on an `Err` value: Error("unsupported expression; enable syn's features=[\"full\"]")
@tyranron
Copy link
Collaborator

tyranron commented Sep 1, 2023

@ModProg that code is gross 😄

I would expect rather something like this:

#[derive(derive_more::Debug)]
enum Enum {
    #[cfg(unix)]
    A = 2,
    #[cfg(not(unix))]
    A = 3,
}

But yes, good catch. I guess we may provide a syn-full feature which enables "full" for syn for cases when someone requires it.

@JelteF
Copy link
Owner

JelteF commented Sep 1, 2023

I think assuming that we want the derive_more Debug derive to work for everything that the std Debug derive works for, then the debug feature of derive_more should depend on syn its full feature.

@JelteF
Copy link
Owner

JelteF commented Sep 1, 2023

How bad is compile time for syn its full feature, relative to what we have now?

@ModProg
Copy link
Contributor Author

ModProg commented Sep 1, 2023

Well any of our derives that support enums have this problem. Because it happens when syn tries to parse the enum.

@JelteF
Copy link
Owner

JelteF commented Sep 1, 2023

Maybe this could be considered a bug in syn then?

@ModProg
Copy link
Contributor Author

ModProg commented Sep 1, 2023

Maybe this could be considered a bug in syn then?

I guess, but I don't see how they could do it differently than adding a Expr::Unknown(TokenStream) and employing a lossy expr parser such as (https://docs.rs/proc-macro-utils/latest/proc_macro_utils/struct.TokenParser.html#method.next_expression).

Probably not in line with syns general approach to parsing.

Or they need to include all expressions in derive. But I guess they decided that some expressions are just highly unlikely to happen in this position.

@JelteF
Copy link
Owner

JelteF commented Sep 15, 2023

Do we need a dedicated feature for this in derive_more? Or does it work if the crate that contains the struct enables syn its "full" feature itself?

@tyranron
Copy link
Collaborator

tyranron commented Sep 18, 2023

@JelteF

Or does it work if the crate that contains the struct enables syn its "full" feature itself?

Yes, that works, of course. However, given that the derive_more is a proc-macro crate, library users unlikely will add syn to their dependencies just to enable full feature, if it's not there already due to other dependencies.

@JelteF
Copy link
Owner

JelteF commented Mar 15, 2024

This is fixed by syn upstream so closing this

@JelteF JelteF closed this as completed Mar 15, 2024
@tyranron tyranron linked a pull request Mar 15, 2024 that will close this issue
3 tasks
tyranron added a commit that referenced this issue Mar 15, 2024
Upgrade minimal version of `syn` up to 2.0.45 version to fix the extended
enum syntax, and cover the use case with tests for future regressions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants