about summary refs log tree commit diff
diff options
context:
space:
mode:
authormitaa <mitaa.ceb@gmail.com>2016-03-26 16:42:38 +0100
committermitaa <mitaa.ceb@gmail.com>2016-03-27 00:21:01 +0100
commit8779e7baa495b8dc46008c8f7d2badcb0ea3b1ab (patch)
tree9ee43840b3e9606adfb9a46be588d4dbc45bdfb2
parent6a76872d7165f901e3ec127a25be1a6303d137b3 (diff)
downloadrust-8779e7baa495b8dc46008c8f7d2badcb0ea3b1ab.tar.gz
rust-8779e7baa495b8dc46008c8f7d2badcb0ea3b1ab.zip
Don't initialize id-map when rendering md files
Adding these "known" values to the table of used ids is only required
when embedding markdown into a rustdoc  html page and may yield
unexpected results when rendering a standalone `*.md` file.
-rw-r--r--src/librustdoc/html/markdown.rs6
-rw-r--r--src/librustdoc/html/render.rs14
-rw-r--r--src/librustdoc/markdown.rs2
3 files changed, 14 insertions, 8 deletions
diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs
index 9fd476bfbab..e7304b69510 100644
--- a/src/librustdoc/html/markdown.rs
+++ b/src/librustdoc/html/markdown.rs
@@ -607,7 +607,7 @@ mod tests {
     fn issue_17736() {
         let markdown = "# title";
         format!("{}", Markdown(markdown));
-        reset_ids();
+        reset_ids(true);
     }
 
     #[test]
@@ -615,7 +615,7 @@ mod tests {
         fn t(input: &str, expect: &str) {
             let output = format!("{}", Markdown(input));
             assert_eq!(output, expect);
-            reset_ids();
+            reset_ids(true);
         }
 
         t("# Foo bar", "\n<h1 id='foo-bar' class='section-header'>\
@@ -654,7 +654,7 @@ mod tests {
               <a href='#panics-1'>Panics</a></h1>");
         };
         test();
-        reset_ids();
+        reset_ids(true);
         test();
     }
 
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 462cef2e0e3..0f436efd70b 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -378,8 +378,14 @@ fn init_ids() -> HashMap<String, usize> {
 /// This method resets the local table of used ID attributes. This is typically
 /// used at the beginning of rendering an entire HTML page to reset from the
 /// previous state (if any).
-pub fn reset_ids() {
-    USED_ID_MAP.with(|s| *s.borrow_mut() = init_ids());
+pub fn reset_ids(embedded: bool) {
+    USED_ID_MAP.with(|s| {
+        *s.borrow_mut() = if embedded {
+            init_ids()
+        } else {
+            HashMap::new()
+        };
+    });
 }
 
 pub fn derive_id(candidate: String) -> String {
@@ -1280,7 +1286,7 @@ impl Context {
                 keywords: &keywords,
             };
 
-            reset_ids();
+            reset_ids(true);
 
             // We have a huge number of calls to write, so try to alleviate some
             // of the pain by using a buffered writer instead of invoking the
@@ -2748,6 +2754,6 @@ fn test_unique_id() {
         assert_eq!(&actual[..], expected);
     };
     test();
-    reset_ids();
+    reset_ids(true);
     test();
 }
diff --git a/src/librustdoc/markdown.rs b/src/librustdoc/markdown.rs
index 03d2c1a1b4d..d21726dd40f 100644
--- a/src/librustdoc/markdown.rs
+++ b/src/librustdoc/markdown.rs
@@ -83,7 +83,7 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
     }
     let title = metadata[0];
 
-    reset_ids();
+    reset_ids(false);
 
     let rendered = if include_toc {
         format!("{}", MarkdownWithToc(text))