about summary refs log tree commit diff
path: root/src/librustdoc/html
diff options
context:
space:
mode:
authorWill Crichton <wcrichto@cs.stanford.edu>2021-09-21 15:49:36 -0700
committerWill Crichton <wcrichto@cs.stanford.edu>2021-10-06 19:45:25 -0700
commitdf5e3a6e40b5e70f3e869f97a7ce800385913c28 (patch)
treeb7d16a97452cf2e35ccac68cd369d952fa304a28 /src/librustdoc/html
parent5c05b3c03da5d37e544589e42fe9738728b27b40 (diff)
downloadrust-df5e3a6e40b5e70f3e869f97a7ce800385913c28.tar.gz
rust-df5e3a6e40b5e70f3e869f97a7ce800385913c28.zip
Change serialized format to use DefPathHash instead of custom String
Move test to rustdoc-ui

Fix test writing to wrong directory

Formatting

Fix test

Add FIXME

Remove raw multiline strings
Diffstat (limited to 'src/librustdoc/html')
-rw-r--r--src/librustdoc/html/highlight.rs6
-rw-r--r--src/librustdoc/html/highlight/tests.rs2
-rw-r--r--src/librustdoc/html/render/mod.rs41
3 files changed, 21 insertions, 28 deletions
diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs
index a97dd95dcb6..8ef5fabb901 100644
--- a/src/librustdoc/html/highlight.rs
+++ b/src/librustdoc/html/highlight.rs
@@ -258,11 +258,7 @@ impl Iterator for PeekIter<'a> {
     type Item = (TokenKind, &'a str);
     fn next(&mut self) -> Option<Self::Item> {
         self.peek_pos = 0;
-        if let Some(first) = self.stored.pop_front() {
-            Some(first)
-        } else {
-            self.iter.next()
-        }
+        if let Some(first) = self.stored.pop_front() { Some(first) } else { self.iter.next() }
     }
 }
 
diff --git a/src/librustdoc/html/highlight/tests.rs b/src/librustdoc/html/highlight/tests.rs
index 405bdf0d810..3fa386dded9 100644
--- a/src/librustdoc/html/highlight/tests.rs
+++ b/src/librustdoc/html/highlight/tests.rs
@@ -60,7 +60,7 @@ fn test_union_highlighting() {
     create_default_session_globals_then(|| {
         let src = include_str!("fixtures/union.rs");
         let mut html = Buffer::new();
-        write_code(&mut html, src, Edition::Edition2018, None);
+        write_code(&mut html, src, Edition::Edition2018, None, None);
         expect_file!["fixtures/union.html"].assert_eq(&html.into_inner());
     });
 }
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs
index cd5316240d0..2454ae492b2 100644
--- a/src/librustdoc/html/render/mod.rs
+++ b/src/librustdoc/html/render/mod.rs
@@ -2465,7 +2465,7 @@ const MAX_FULL_EXAMPLES: usize = 5;
 /// Generates the HTML for example call locations generated via the --scrape-examples flag.
 fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, def_id: DefId, item: &clean::Item) {
     let tcx = cx.tcx();
-    let key = crate::scrape_examples::def_id_call_key(tcx, def_id);
+    let key = tcx.def_path_hash(def_id);
     let call_locations = match cx.shared.call_locations.get(&key) {
         Some(call_locations) => call_locations,
         _ => {
@@ -2474,13 +2474,14 @@ fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, def_id: DefId, item:
     };
 
     // Generate a unique ID so users can link to this section for a given method
+    // FIXME: this should use init_id_map instead of derive
     let id = cx.id_map.borrow_mut().derive("scraped-examples");
     write!(
         w,
-        r##"<div class="docblock scraped-example-list">
-          <h1 id="scraped-examples" class="small-section-header">
-             <a href="#{}">Examples found in repository</a>
-          </h1>"##,
+        "<div class=\"docblock scraped-example-list\">\
+          <h1 id=\"scraped-examples\" class=\"small-section-header\">\
+             <a href=\"#{}\">Examples found in repository</a>\
+          </h1>",
         id
     );
 
@@ -2533,11 +2534,11 @@ fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, def_id: DefId, item:
 
         write!(
             w,
-            r#"<div class="scraped-example" data-locs="{locations}" data-offset="{offset}">
-                <div class="scraped-example-title">
-                   {name} (<a href="{root}{url}" target="_blank">{line_range}</a>)
-                </div>
-                <div class="code-wrapper">"#,
+            "<div class=\"scraped-example\" data-locs=\"{locations}\" data-offset=\"{offset}\">\
+                <div class=\"scraped-example-title\">\
+                   {name} (<a href=\"{root}{url}\" target=\"_blank\">{line_range}</a>)\
+                </div>\
+                <div class=\"code-wrapper\">",
             root = cx.root_path(),
             url = call_data.url,
             name = call_data.display_name,
@@ -2625,14 +2626,13 @@ fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, def_id: DefId, item:
     if it.peek().is_some() {
         write!(
             w,
-            r#"<details class="rustdoc-toggle more-examples-toggle">
-                  <summary class="hideme">
-                     <span>More examples</span>
-                  </summary>
-                  <div class="more-scraped-examples">
-                    <div class="toggle-line"><div class="toggle-line-inner"></div></div>
-                    <div class="more-scraped-examples-inner">
-"#
+            "<details class=\"rustdoc-toggle more-examples-toggle\">\
+                  <summary class=\"hideme\">\
+                     <span>More examples</span>\
+                  </summary>\
+                  <div class=\"more-scraped-examples\">\
+                    <div class=\"toggle-line\"><div class=\"toggle-line-inner\"></div></div>\
+                    <div class=\"more-scraped-examples-inner\">"
         );
 
         // Only generate inline code for MAX_FULL_EXAMPLES number of examples. Otherwise we could
@@ -2643,10 +2643,7 @@ fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, def_id: DefId, item:
 
         // For the remaining examples, generate a <ul> containing links to the source files.
         if it.peek().is_some() {
-            write!(
-                w,
-                r#"<div class="example-links">Additional examples can be found in:<br /><ul>"#
-            );
+            write!(w, r#"<div class="example-links">Additional examples can be found in:<br><ul>"#);
             it.for_each(|(_, call_data)| {
                 write!(
                     w,