Skip to content

Commit

Permalink
Add #[rustfmt::skip] to disable rustfmt on generated code. (#1088)
Browse files Browse the repository at this point in the history
Add `#[rustfmt::skip]` to generated Rust code when we're using
prettyplease, so that users don't see spurious diffs when running
`cargo fmt` over their projects.
  • Loading branch information
sunfishcode authored Nov 16, 2024
1 parent 14ff1c8 commit dd15b0e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,14 @@ impl RustWasm {
}
cur.contents.push(module);
}

// Disable rustfmt. By default we already format the code
// using prettyplease, so we don't want `cargo fmt` to create
// extra diffs for users to deal with.
if self.opts.format {
uwriteln!(self.src, "#[rustfmt::skip]");
}

emit(&mut self.src, map);
fn emit(me: &mut Source, module: Module) {
for (name, submodule) in module.submodules {
Expand Down Expand Up @@ -366,6 +374,12 @@ impl RustWasm {
if self.rt_module.is_empty() {
return;
}

// As above, disable rustfmt, as we use prettyplease.
if self.opts.format {
uwriteln!(self.src, "#[rustfmt::skip]");
}

self.src.push_str("mod _rt {\n");
let mut emitted = IndexSet::new();
while !self.rt_module.is_empty() {
Expand Down

0 comments on commit dd15b0e

Please sign in to comment.