Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid emitting redundant #[allow(dead_code)] directives. #1089

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading