Skip to content

Conversation

@Rua
Copy link
Contributor

@Rua Rua commented Nov 11, 2025

Rather than running cargo fmt, this runs the rustfmt binary directly so that it can be used on individual files, and also when there are no build files.

@Rua Rua force-pushed the rustfmt branch 3 times, most recently from cc8a44b to f519f02 Compare November 11, 2025 18:00
Comment on lines +680 to +684
if !status.map_or(false, |status| status.success()) {
warn!("rustfmt failed, code may not be well-formatted");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we handle these errors differently? The command will fail if rustc isn't found or something, and the status will fail if rustc exits with an error. That said, they shouldn't really fail, so I think we can just panic here, maybe with an .expect.

Also, if we're calling rustfmt here, we can remove the rustfmt run in snapshots.rs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think a panic is appropriate, as this is just an extra convenience for the user and not a hard requirement of the transpilation process. The transpilation should still succeed if rustfmt is not installed or doesn't complete for whatever reason. Though unlikely, rustfmt may not be installed even if cargo and rustc are.

@Rua Rua force-pushed the rustfmt branch 2 times, most recently from 3c732f2 to 9e83e14 Compare November 12, 2025 09:28
let output_path = build_dir.join(file_name);
let output = reg.render("lib.rs", &json).unwrap();
let path = maybe_write_to_file(&output_path, output, tcfg.overwrite_existing)?;
rustfmt(&output_path, build_dir);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we make this optional (with a command line argument)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Why would we not do it, though?

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.

Use rustfmt when translating

3 participants