Skip to content

Commit dd15b0e

Browse files
authored
Add #[rustfmt::skip] to disable rustfmt on generated code. (#1088)
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.
1 parent 14ff1c8 commit dd15b0e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

crates/rust/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,14 @@ impl RustWasm {
292292
}
293293
cur.contents.push(module);
294294
}
295+
296+
// Disable rustfmt. By default we already format the code
297+
// using prettyplease, so we don't want `cargo fmt` to create
298+
// extra diffs for users to deal with.
299+
if self.opts.format {
300+
uwriteln!(self.src, "#[rustfmt::skip]");
301+
}
302+
295303
emit(&mut self.src, map);
296304
fn emit(me: &mut Source, module: Module) {
297305
for (name, submodule) in module.submodules {
@@ -366,6 +374,12 @@ impl RustWasm {
366374
if self.rt_module.is_empty() {
367375
return;
368376
}
377+
378+
// As above, disable rustfmt, as we use prettyplease.
379+
if self.opts.format {
380+
uwriteln!(self.src, "#[rustfmt::skip]");
381+
}
382+
369383
self.src.push_str("mod _rt {\n");
370384
let mut emitted = IndexSet::new();
371385
while !self.rt_module.is_empty() {

0 commit comments

Comments
 (0)