Skip to content

Commit 0640625

Browse files
authored
Avoid emitting redundant #[allow(dead_code)] directives. (bytecodealliance#1089)
Only emit `#[allow(dead_code)]` on top-level modules, and emit `#[rustfmt::skip]` on all top-level modules.
1 parent dd15b0e commit 0640625

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

crates/rust/src/interface.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,6 @@ macro_rules! {macro_name} {{
439439
};
440440
let module = format!(
441441
"\
442-
#[allow(dead_code, clippy::all)]
443442
pub mod {snake} {{
444443
{used_static}
445444
{module}

crates/rust/src/lib.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -293,23 +293,25 @@ impl RustWasm {
293293
cur.contents.push(module);
294294
}
295295

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-
303-
emit(&mut self.src, map);
304-
fn emit(me: &mut Source, module: Module) {
296+
emit(&mut self.src, map, &self.opts, true);
297+
fn emit(me: &mut Source, module: Module, opts: &Opts, toplevel: bool) {
305298
for (name, submodule) in module.submodules {
306-
// Ignore dead-code warnings. If the bindings are only used
307-
// within a crate, and not exported to a different crate, some
308-
// parts may be unused, and that's ok.
309-
uwriteln!(me, "#[allow(dead_code)]");
299+
if toplevel {
300+
// Disable rustfmt. By default we already format the code
301+
// using prettyplease, so we don't want `cargo fmt` to create
302+
// extra diffs for users to deal with.
303+
if opts.format {
304+
uwriteln!(me, "#[rustfmt::skip]");
305+
}
306+
307+
// Ignore dead-code and clippy warnings. If the bindings are
308+
// only used within a crate, and not exported to a different
309+
// crate, some parts may be unused, and that's ok.
310+
uwriteln!(me, "#[allow(dead_code, clippy::all)]");
311+
}
310312

311313
uwriteln!(me, "pub mod {name} {{");
312-
emit(me, submodule);
314+
emit(me, submodule, opts, false);
313315
uwriteln!(me, "}}");
314316
}
315317
for submodule in module.contents {

0 commit comments

Comments
 (0)