Skip to content

Commit

Permalink
Avoid emitting redundant #[allow(dead_code)] directives. (#1089)
Browse files Browse the repository at this point in the history
Only emit `#[allow(dead_code)]` on top-level modules, and emit
`#[rustfmt::skip]` on all top-level modules.
  • Loading branch information
sunfishcode authored Nov 18, 2024
1 parent dd15b0e commit 0640625
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
1 change: 0 additions & 1 deletion crates/rust/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,6 @@ macro_rules! {macro_name} {{
};
let module = format!(
"\
#[allow(dead_code, clippy::all)]
pub mod {snake} {{
{used_static}
{module}
Expand Down
30 changes: 16 additions & 14 deletions crates/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,23 +293,25 @@ 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) {
emit(&mut self.src, map, &self.opts, true);
fn emit(me: &mut Source, module: Module, opts: &Opts, toplevel: bool) {
for (name, submodule) in module.submodules {
// Ignore dead-code warnings. If the bindings are only used
// within a crate, and not exported to a different crate, some
// parts may be unused, and that's ok.
uwriteln!(me, "#[allow(dead_code)]");
if toplevel {
// 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 opts.format {
uwriteln!(me, "#[rustfmt::skip]");
}

// Ignore dead-code and clippy warnings. If the bindings are
// only used within a crate, and not exported to a different
// crate, some parts may be unused, and that's ok.
uwriteln!(me, "#[allow(dead_code, clippy::all)]");
}

uwriteln!(me, "pub mod {name} {{");
emit(me, submodule);
emit(me, submodule, opts, false);
uwriteln!(me, "}}");
}
for submodule in module.contents {
Expand Down

0 comments on commit 0640625

Please sign in to comment.