Skip to content

Conversation

@a4n1
Copy link

@a4n1 a4n1 commented Jan 8, 2026

PR Info

Bug Fixes

  • Fixes enum variants that start with a digit and then have characters which are not valid in Rust identifiers

@Huliiiiii Huliiiiii requested review from Expurple and tyt2y3 January 8, 2026 16:48
"__EmptyString".to_string()
} else if v.chars().next().map(char::is_numeric).unwrap_or(false) {
if v.chars().any(|c| !c.is_numeric() && !c.is_alphabetic() && c != '_' && c != '-' && c != ' ') {
"".to_string()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be moved to __EmptyString and update the warning message.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! Yeah this is a confusing case. to_upper_camel_case removes invalid chars, so a field like "/" is remapped to "". In order to preserve existing behavior for variants starting with a digit, we have to strip chars manually if they are not valid.

Empty strings are then converted to UTF-8 encoding in the next block. So, "0/" is remapped to "U0030U002F". I agree that the flow is pretty hard to follow now though.

We could replace this check with format!("_{}", v.to_upper_camel_case()). However, this would map 0A-B-C to _0aBC instead of _0ABC.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's really confusing. Could you refactor this to make the control flow clearer?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or add a comment explaining that Unicode characters will be handled below.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've refactored the control flow, hopefully it's easier to follow now

Signed-off-by: Agni <a@a4n1.com>
@a4n1 a4n1 force-pushed the push-utssrpnwlyox branch from 6181288 to a9cb7c8 Compare January 8, 2026 17:13
Signed-off-by: Agni <a@a4n1.com>
@a4n1 a4n1 force-pushed the push-utssrpnwlyox branch from f73d402 to 7cbf791 Compare January 9, 2026 12:00

if v
.chars()
.any(|c| !c.is_alphanumeric() && c != '_' && c != '-' && c != ' ') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use matches macro

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 this pull request may close these issues.

Enum variant is not a valid Rust identifier

2 participants