summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2019-11-11 13:24:13 +0100
committerGitHub <noreply@github.com>2019-11-11 13:24:13 +0100
commit1f505c2b2eecac73751b57496ee6dc33c91ffa6b (patch)
tree461228d1e0bc34618566efd205829b4d1ecf5b31 /src
parenta7b3aa0444c8b4020e68d009180068b1c1b4fd92 (diff)
Revert "Add support for Rust edition 2018 in playpens (#1086)" (#1093)
Diffstat (limited to 'src')
-rw-r--r--src/book/mod.rs18
-rw-r--r--src/config.rs60
-rw-r--r--src/renderer/html_handlebars/hbs_renderer.rs31
3 files changed, 15 insertions, 94 deletions
diff --git a/src/book/mod.rs b/src/book/mod.rs
index 29d2dc3d..8d69eea2 100644
--- a/src/book/mod.rs
+++ b/src/book/mod.rs
@@ -27,7 +27,7 @@ use crate::preprocess::{
use crate::renderer::{CmdRenderer, HtmlHandlebars, MarkdownRenderer, RenderContext, Renderer};
use crate::utils;
-use crate::config::{Config, RustEdition};
+use crate::config::Config;
/// The object used to manage and build a book.
pub struct MDBook {
@@ -262,17 +262,11 @@ impl MDBook {
let mut tmpf = utils::fs::create_file(&path)?;
tmpf.write_all(ch.content.as_bytes())?;
- let mut cmd = Command::new("rustdoc");
-
- cmd.arg(&path).arg("--test").args(&library_args);
-
- if let Some(html_cfg) = self.config.html_config() {
- if html_cfg.playpen.edition == RustEdition::E2018 {
- cmd.args(&["--edition", "2018"]);
- }
- }
-
- let output = cmd.output()?;
+ let output = Command::new("rustdoc")
+ .arg(&path)
+ .arg("--test")
+ .args(&library_args)
+ .output()?;
if !output.status.success() {
bail!(ErrorKind::Subprocess(
diff --git a/src/config.rs b/src/config.rs
index 4c8624a6..fae3da84 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -513,8 +513,6 @@ pub struct Playpen {
pub copy_js: bool,
/// Display line numbers on playpen snippets. Default: `false`.
pub line_numbers: bool,
- /// Rust edition to use for the code. Default: `2015`.
- pub edition: RustEdition,
}
impl Default for Playpen {
@@ -524,66 +522,10 @@ impl Default for Playpen {
copyable: true,
copy_js: true,
line_numbers: false,
- edition: RustEdition::E2015,
}
}
}
-#[derive(Debug, Clone, PartialEq)]
-/// The edition of Rust used in a playpen code snippet
-pub enum RustEdition {
- /// The 2018 edition of Rust
- E2018,
- /// The 2015 edition of Rust
- E2015,
-}
-
-impl Default for RustEdition {
- fn default() -> Self {
- RustEdition::E2015
- }
-}
-
-impl Serialize for RustEdition {
- fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
- where
- S: Serializer,
- {
- match self {
- RustEdition::E2015 => serializer.serialize_str("2015"),
- RustEdition::E2018 => serializer.serialize_str("2018"),
- }
- }
-}
-
-impl<'de> Deserialize<'de> for RustEdition {
- fn deserialize<D>(de: D) -> std::result::Result<Self, D::Error>
- where
- D: Deserializer<'de>,
- {
- use serde::de::Error;
-
- let raw = Value::deserialize(de)?;
-
- let edition = match raw {
- Value::String(s) => s,
- _ => {
- return Err(D::Error::custom("Rust edition should be a string"));
- }
- };
-
- let edition = match edition.as_str() {
- "2018" => RustEdition::E2018,
- "2015" => RustEdition::E2015,
- _ => {
- return Err(D::Error::custom("Unknown Rust edition"));
- }
- };
-
- Ok(edition)
- }
-}
-
/// Configuration of the search functionality of the HTML renderer.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(default, rename_all = "kebab-case")]
@@ -688,7 +630,6 @@ mod tests {
[output.html.playpen]
editable = true
editor = "ace"
- edition = "2018"
[preprocessor.first]
@@ -717,7 +658,6 @@ mod tests {
copyable: true,
copy_js: true,
line_numbers: false,
- edition: RustEdition::E2018,
};
let html_should_be = HtmlConfig {
curly_quotes: true,
diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs
index aa2bdcc9..0be92562 100644
--- a/src/renderer/html_handlebars/hbs_renderer.rs
+++ b/src/renderer/html_handlebars/hbs_renderer.rs
@@ -1,5 +1,5 @@
use crate::book::{Book, BookItem};
-use crate::config::{Config, HtmlConfig, Playpen, RustEdition};
+use crate::config::{Config, HtmlConfig, Playpen};
use crate::errors::*;
use crate::renderer::html_handlebars::helpers;
use crate::renderer::{RenderContext, Renderer};
@@ -608,27 +608,14 @@ fn add_playpen_pre(html: &str, playpen_config: &Playpen) -> String {
let classes = &caps[2];
let code = &caps[3];
-
- if (classes.contains("language-rust")
- && !classes.contains("ignore")
- && !classes.contains("noplaypen"))
- || classes.contains("mdbook-runnable")
- {
- let mut classes = classes.to_string();
- match playpen_config.edition {
- RustEdition::E2018 => classes += " edition2018",
- _ => (),
- }
-
- // wrap the contents in an external pre block
- format!(
- "<pre class=\"playpen\"><code class=\"{}\">{}</code></pre>",
- classes,
- {
- let content: Cow<'_, str> = if playpen_config.editable
- && classes.contains("editable")
- || text.contains("fn main")
- || text.contains("quick_main!")
+ if classes.contains("language-rust") {
+ if (!classes.contains("ignore") && !classes.contains("noplaypen"))
+ || classes.contains("mdbook-runnable")
+ {
+ // wrap the contents in an external pre block
+ format!(
+ "<pre class=\"playpen\"><code class=\"{}\">{}</code></pre>",
+ classes,
{
let content: Cow<'_, str> = if playpen_config.editable
&& classes.contains("editable")