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

Using #[strum(to_string = "}")] results in macro error #363

Open
Somfic opened this issue Jun 8, 2024 · 2 comments
Open

Using #[strum(to_string = "}")] results in macro error #363

Somfic opened this issue Jun 8, 2024 · 2 comments

Comments

@Somfic
Copy link

Somfic commented Jun 8, 2024

Hi!

I’m tinkering with writing a transpiler and am currently in the lexing stage. In my Token enum I have the following variant: CurlyClose. I’d like to implement the Display trait for Token using strum.

What I currently have:

#[derive(Debug, Clone, strum_macros::Display)]
pub enum Token {
	
	// Other tokens …

	/// An opening curly brace; `{`.
    #[strum(to_string = "{")]
    CurlyOpen,

    /// A closing curly brace; `}`.
    #[strum(to_string = "}")] 		// <—- “Bracket closed without previous opened bracket”
    CurlyClose,

	// Other tokens …

}

The #[strum(to_string = "}")] macro is throwing a Bracket closed without previous opened bracket compiler error. When I try to escape the closing curly brace the macro panics with proc-macro panicked: unexpected byte '}' after \ character in string literal.

Am I doing something wrong? Other braces such as { [ ] ( and ) work fine.

@Somfic Somfic changed the title Bracket closed without previous opened bracket Using #[strum(to_string = "}")] results in macro error Jun 8, 2024
@Edgeworth
Copy link

I'm also hitting this recently (same code worked before). It doesn't occur in strum 0.25

@gmryuuko
Copy link

After #360, the use of }} for escaping is also not possible.

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

No branches or pull requests

3 participants