Skip to content

Commit

Permalink
Broaden scope of suppressed warnings for listings without a main fn
Browse files Browse the repository at this point in the history
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: #1192

[code]: https://github.com/rust-lang/mdBook/blob/769cc0a7c14fe133fc5eb223f435473730d0086e/src/renderer/html_handlebars/hbs_renderer.rs#L635-L638
  • Loading branch information
englishm committed Apr 18, 2020
1 parent 8e673c9 commit 1d265fd
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/renderer/html_handlebars/hbs_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ fn add_playpen_pre(html: &str, playpen_config: &Playpen) -> String {
let (attrs, code) = partition_source(code);

format!(
"\n# #![allow(unused_variables)]\n{}#fn main() {{\n{}#}}",
"\n# #![allow(unused)]\n{}#fn main() {{\n{}#}}",
attrs, code
)
.into()
Expand Down Expand Up @@ -756,7 +756,7 @@ mod tests {
fn add_playpen() {
let inputs = [
("<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>",
"<pre class=\"playpen\"><code class=\"language-rust\">fn main() {}\n</code></pre>"),
("<code class=\"language-rust editable\">let s = \"foo\n # bar\n\";</code>",
Expand Down

0 comments on commit 1d265fd

Please sign in to comment.