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

fix(forge bind): prefix keyword mod names with r# #9761

Merged
merged 3 commits into from
Jan 27, 2025
Merged

Conversation

yash-atreya
Copy link
Member

Motivation

Closes #5847

Solution

Prefix keyword module names with r#.

E.g.

pub mod r#enum;

@yash-atreya yash-atreya changed the title fix(forge bind): prefix keyword mod names with r# fix(forge bind): prefix keyword mod names with r# Jan 27, 2025

fn write_mod_name(contents: &mut String, name: &str) -> Result<()> {
if syn::parse_str::<syn::File>(&format!("pub mod {name};"))
.is_err_and(|e| e.to_string().contains("expected identifier, found keyword"))
Copy link
Member

Choose a reason for hiding this comment

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

this should do it, alternatively we could try to parse name as Ident perhaps?

Copy link
Member

Choose a reason for hiding this comment

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

should be syn::parse_str::<Ident>().is_ok()

Copy link
Member Author

Choose a reason for hiding this comment

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


fn write_mod_name(contents: &mut String, name: &str) -> Result<()> {
if syn::parse_str::<syn::File>(&format!("pub mod {name};"))
.is_err_and(|e| e.to_string().contains("expected identifier, found keyword"))
Copy link
Member

Choose a reason for hiding this comment

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

should be syn::parse_str::<Ident>().is_ok()

@yash-atreya yash-atreya enabled auto-merge (squash) January 27, 2025 13:01
@yash-atreya yash-atreya requested a review from DaniPopes January 27, 2025 13:01
@yash-atreya yash-atreya added T-bug Type: bug C-forge Command: forge labels Jan 27, 2025
Copy link
Member

@zerosnacks zerosnacks left a comment

Choose a reason for hiding this comment

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

makes sense!

@yash-atreya yash-atreya merged commit b081d66 into master Jan 27, 2025
22 checks passed
@yash-atreya yash-atreya deleted the yash/fix-5847 branch January 27, 2025 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge T-bug Type: bug
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Bug: forge bind fails to compile on keyword enum (alloy)
4 participants