Broaden scope of suppressed warnings for listings without a main fn

At present, code listings without a main function will be wrapped in one and
annotated with an allow lint check attribute provided by the following [code][]:

```
format!(
    "\n# #![allow(unused_variables)]\n{}#fn main() {{\n{}#}}",
    attrs, code
)
```

A broader lint check attribute such as `#![allow(unused)]` seems like it might
better fit the apparent intent of this code.

Addresses: https://github.com/rust-lang/mdBook/issues/1192

[code]: 769cc0a7c1/src/renderer/html_handlebars/hbs_renderer.rs (L635-L638)
This commit is contained in:
Mike English 2020-04-18 00:10:08 -04:00
parent 8e673c96c2
commit 1d265fd143
1 changed files with 2 additions and 2 deletions

View File

@ -633,7 +633,7 @@ fn add_playpen_pre(html: &str, playpen_config: &Playpen) -> String {
let (attrs, code) = partition_source(code); let (attrs, code) = partition_source(code);
format!( format!(
"\n# #![allow(unused_variables)]\n{}#fn main() {{\n{}#}}", "\n# #![allow(unused)]\n{}#fn main() {{\n{}#}}",
attrs, code attrs, code
) )
.into() .into()
@ -756,7 +756,7 @@ mod tests {
fn add_playpen() { fn add_playpen() {
let inputs = [ let inputs = [
("<code class=\"language-rust\">x()</code>", ("<code class=\"language-rust\">x()</code>",
"<pre class=\"playpen\"><code class=\"language-rust\">\n<span class=\"boring\">#![allow(unused_variables)]\n</span><span class=\"boring\">fn main() {\n</span>x()\n<span class=\"boring\">}\n</span></code></pre>"), "<pre class=\"playpen\"><code class=\"language-rust\">\n<span class=\"boring\">#![allow(unused)]\n</span><span class=\"boring\">fn main() {\n</span>x()\n<span class=\"boring\">}\n</span></code></pre>"),
("<code class=\"language-rust\">fn main() {}</code>", ("<code class=\"language-rust\">fn main() {}</code>",
"<pre class=\"playpen\"><code class=\"language-rust\">fn main() {}\n</code></pre>"), "<pre class=\"playpen\"><code class=\"language-rust\">fn main() {}\n</code></pre>"),
("<code class=\"language-rust editable\">let s = \"foo\n # bar\n\";</code>", ("<code class=\"language-rust editable\">let s = \"foo\n # bar\n\";</code>",