Skip to content

Commit a9edea0

Browse files
authored
Revert "Add support for Rust edition 2018 in playpens (#1086)"
This reverts commit a7b3aa0.
1 parent a7b3aa0 commit a9edea0

File tree

6 files changed

+22
-106
lines changed

6 files changed

+22
-106
lines changed

book-example/book.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ mathjax-support = true
1010
[output.html.playpen]
1111
editable = true
1212
line-numbers = true
13-
edition = "2018"
1413

1514
[output.html.search]
1615
limit-results = 20

book-example/src/format/config.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ The following configuration options are available:
178178
an icon link will be output in the menu bar of the book.
179179
- **git-repository-icon:** The FontAwesome icon class to use for the git
180180
repository link. Defaults to `fa-github`.
181-
181+
182182
Available configuration options for the `[output.html.fold]` table:
183183

184184
- **enable:** Enable section-folding. When off, all folds are open.
@@ -193,7 +193,6 @@ Available configuration options for the `[output.html.playpen]` table:
193193
- **copy-js:** Copy JavaScript files for the editor to the output directory.
194194
Defaults to `true`.
195195
- **line-numbers** Display line numbers on editable sections of code. Requires both `editable` and `copy-js` to be `true`. Defaults to `false`.
196-
- **edition**: Rust edition to use by default for the code snippets. Defaults to `2015`.
197196

198197
[Ace]: https://ace.c9.io/
199198

src/book/mod.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::preprocess::{
2727
use crate::renderer::{CmdRenderer, HtmlHandlebars, MarkdownRenderer, RenderContext, Renderer};
2828
use crate::utils;
2929

30-
use crate::config::{Config, RustEdition};
30+
use crate::config::Config;
3131

3232
/// The object used to manage and build a book.
3333
pub struct MDBook {
@@ -262,17 +262,11 @@ impl MDBook {
262262
let mut tmpf = utils::fs::create_file(&path)?;
263263
tmpf.write_all(ch.content.as_bytes())?;
264264

265-
let mut cmd = Command::new("rustdoc");
266-
267-
cmd.arg(&path).arg("--test").args(&library_args);
268-
269-
if let Some(html_cfg) = self.config.html_config() {
270-
if html_cfg.playpen.edition == RustEdition::E2018 {
271-
cmd.args(&["--edition", "2018"]);
272-
}
273-
}
274-
275-
let output = cmd.output()?;
265+
let output = Command::new("rustdoc")
266+
.arg(&path)
267+
.arg("--test")
268+
.args(&library_args)
269+
.output()?;
276270

277271
if !output.status.success() {
278272
bail!(ErrorKind::Subprocess(

src/config.rs

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,6 @@ pub struct Playpen {
513513
pub copy_js: bool,
514514
/// Display line numbers on playpen snippets. Default: `false`.
515515
pub line_numbers: bool,
516-
/// Rust edition to use for the code. Default: `2015`.
517-
pub edition: RustEdition,
518516
}
519517

520518
impl Default for Playpen {
@@ -524,66 +522,10 @@ impl Default for Playpen {
524522
copyable: true,
525523
copy_js: true,
526524
line_numbers: false,
527-
edition: RustEdition::E2015,
528525
}
529526
}
530527
}
531528

532-
#[derive(Debug, Clone, PartialEq)]
533-
/// The edition of Rust used in a playpen code snippet
534-
pub enum RustEdition {
535-
/// The 2018 edition of Rust
536-
E2018,
537-
/// The 2015 edition of Rust
538-
E2015,
539-
}
540-
541-
impl Default for RustEdition {
542-
fn default() -> Self {
543-
RustEdition::E2015
544-
}
545-
}
546-
547-
impl Serialize for RustEdition {
548-
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
549-
where
550-
S: Serializer,
551-
{
552-
match self {
553-
RustEdition::E2015 => serializer.serialize_str("2015"),
554-
RustEdition::E2018 => serializer.serialize_str("2018"),
555-
}
556-
}
557-
}
558-
559-
impl<'de> Deserialize<'de> for RustEdition {
560-
fn deserialize<D>(de: D) -> std::result::Result<Self, D::Error>
561-
where
562-
D: Deserializer<'de>,
563-
{
564-
use serde::de::Error;
565-
566-
let raw = Value::deserialize(de)?;
567-
568-
let edition = match raw {
569-
Value::String(s) => s,
570-
_ => {
571-
return Err(D::Error::custom("Rust edition should be a string"));
572-
}
573-
};
574-
575-
let edition = match edition.as_str() {
576-
"2018" => RustEdition::E2018,
577-
"2015" => RustEdition::E2015,
578-
_ => {
579-
return Err(D::Error::custom("Unknown Rust edition"));
580-
}
581-
};
582-
583-
Ok(edition)
584-
}
585-
}
586-
587529
/// Configuration of the search functionality of the HTML renderer.
588530
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
589531
#[serde(default, rename_all = "kebab-case")]
@@ -688,7 +630,6 @@ mod tests {
688630
[output.html.playpen]
689631
editable = true
690632
editor = "ace"
691-
edition = "2018"
692633
693634
[preprocessor.first]
694635
@@ -717,7 +658,6 @@ mod tests {
717658
copyable: true,
718659
copy_js: true,
719660
line_numbers: false,
720-
edition: RustEdition::E2018,
721661
};
722662
let html_should_be = HtmlConfig {
723663
curly_quotes: true,

src/renderer/html_handlebars/hbs_renderer.rs

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::book::{Book, BookItem};
2-
use crate::config::{Config, HtmlConfig, Playpen, RustEdition};
2+
use crate::config::{Config, HtmlConfig, Playpen};
33
use crate::errors::*;
44
use crate::renderer::html_handlebars::helpers;
55
use crate::renderer::{RenderContext, Renderer};
@@ -608,27 +608,14 @@ fn add_playpen_pre(html: &str, playpen_config: &Playpen) -> String {
608608
let classes = &caps[2];
609609
let code = &caps[3];
610610

611-
612-
if (classes.contains("language-rust")
613-
&& !classes.contains("ignore")
614-
&& !classes.contains("noplaypen"))
615-
|| classes.contains("mdbook-runnable")
616-
{
617-
let mut classes = classes.to_string();
618-
match playpen_config.edition {
619-
RustEdition::E2018 => classes += " edition2018",
620-
_ => (),
621-
}
622-
623-
// wrap the contents in an external pre block
624-
format!(
625-
"<pre class=\"playpen\"><code class=\"{}\">{}</code></pre>",
626-
classes,
627-
{
628-
let content: Cow<'_, str> = if playpen_config.editable
629-
&& classes.contains("editable")
630-
|| text.contains("fn main")
631-
|| text.contains("quick_main!")
611+
if classes.contains("language-rust") {
612+
if (!classes.contains("ignore") && !classes.contains("noplaypen"))
613+
|| classes.contains("mdbook-runnable")
614+
{
615+
// wrap the contents in an external pre block
616+
format!(
617+
"<pre class=\"playpen\"><code class=\"{}\">{}</code></pre>",
618+
classes,
632619
{
633620
let content: Cow<'_, str> = if playpen_config.editable
634621
&& classes.contains("editable")

tests/rendered_output.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -490,15 +490,12 @@ fn markdown_options() {
490490
"<td>bim</td>",
491491
],
492492
);
493-
assert_contains_strings(
494-
&path,
495-
&[
496-
r##"<sup class="footnote-reference"><a href="#1">1</a></sup>"##,
497-
r##"<sup class="footnote-reference"><a href="#word">2</a></sup>"##,
498-
r##"<div class="footnote-definition" id="1"><sup class="footnote-definition-label">1</sup>"##,
499-
r##"<div class="footnote-definition" id="word"><sup class="footnote-definition-label">2</sup>"##,
500-
],
501-
);
493+
assert_contains_strings(&path, &[
494+
r##"<sup class="footnote-reference"><a href="#1">1</a></sup>"##,
495+
r##"<sup class="footnote-reference"><a href="#word">2</a></sup>"##,
496+
r##"<div class="footnote-definition" id="1"><sup class="footnote-definition-label">1</sup>"##,
497+
r##"<div class="footnote-definition" id="word"><sup class="footnote-definition-label">2</sup>"##,
498+
]);
502499
assert_contains_strings(&path, &["<del>strikethrough example</del>"]);
503500
assert_contains_strings(
504501
&path,

0 commit comments

Comments
 (0)