]> git.lizzy.rs Git - rust.git/commitdiff
Added tooltip for should_panic code examples.
authorJake Degen <jakob@degen.com>
Thu, 18 Jun 2020 12:48:37 +0000 (08:48 -0400)
committerJake Degen <jakob@degen.com>
Thu, 18 Jun 2020 15:12:36 +0000 (11:12 -0400)
Previously, compile_fail and ignore code examples displayed a tooltip
indicating this in the documentation. This tooltip has now also been
added to should_panic examples.

src/librustdoc/html/markdown.rs
src/librustdoc/html/static/rustdoc.css
src/librustdoc/html/static/themes/dark.css
src/librustdoc/html/static/themes/light.css
src/test/rustdoc/codeblock-title.rs

index c129e54c0f28ae3e92f5748c073ce6aa569fc9fe..7a6626766d38830c27283ad336f69ee03aae2435 100644 (file)
@@ -192,6 +192,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
     fn next(&mut self) -> Option<Self::Item> {
         let event = self.inner.next();
         let compile_fail;
+        let should_panic;
         let ignore;
         let edition;
         if let Some(Event::Start(Tag::CodeBlock(kind))) = event {
@@ -205,6 +206,7 @@ fn next(&mut self) -> Option<Self::Item> {
                 return Some(Event::Start(Tag::CodeBlock(kind)));
             }
             compile_fail = parse_result.compile_fail;
+            should_panic = parse_result.should_panic;
             ignore = parse_result.ignore;
             edition = parse_result.edition;
         } else {
@@ -280,6 +282,8 @@ fn dont_escape(c: u8) -> bool {
             Some(("This example is not tested".to_owned(), "ignore"))
         } else if compile_fail {
             Some(("This example deliberately fails to compile".to_owned(), "compile_fail"))
+        } else if should_panic {
+            Some(("This example panics".to_owned(), "should_panic"))
         } else if explicit_edition {
             Some((format!("This code runs with edition {}", edition), "edition"))
         } else {
@@ -295,6 +299,8 @@ fn dont_escape(c: u8) -> bool {
                         " ignore"
                     } else if compile_fail {
                         " compile_fail"
+                    } else if should_panic {
+                        " should_panic"
                     } else if explicit_edition {
                         " edition "
                     } else {
@@ -314,6 +320,8 @@ fn dont_escape(c: u8) -> bool {
                         " ignore"
                     } else if compile_fail {
                         " compile_fail"
+                    } else if should_panic {
+                        " should_panic"
                     } else if explicit_edition {
                         " edition "
                     } else {
index 2cb3347135c1b4de185c3a1e84bd1d0f14419229..9c6dd25394db0e8ed4d1c1c0beffbf9cd36eaa3e 100644 (file)
@@ -1089,7 +1089,7 @@ h3 > .collapse-toggle, h4 > .collapse-toggle {
        border-style: solid;
 }
 
-.tooltip.compile_fail, .tooltip.ignore {
+.tooltip.compile_fail, .tooltip.should_panic, .tooltip.ignore {
        font-weight: bold;
        font-size: 20px;
 }
index a2986c7b927e24fc5da504050259d85a57c30691..41dcb5c24507c6c38dfe99a66bd3f84ac20cde81 100644 (file)
@@ -283,6 +283,14 @@ pre.compile_fail:hover, .information:hover + pre.compile_fail {
        border-left: 2px solid #f00;
 }
 
+pre.should_panic {
+       border-left: 2px solid rgba(255,0,0,.8);
+}
+
+pre.should_panic:hover, .information:hover + pre.should_panic {
+       border-left: 2px solid #f00;
+}
+
 pre.ignore {
        border-left: 2px solid rgba(255,142,0,.6);
 }
@@ -299,6 +307,14 @@ pre.ignore:hover, .information:hover + pre.ignore {
        color: #f00;
 }
 
+.tooltip.should_panic {
+       color: rgba(255,0,0,.8);
+}
+
+.information > .should_panic:hover {
+       color: #f00;
+}
+
 .tooltip.ignore {
        color: rgba(255,142,0,.6);
 }
index be173d8eb46d3bd6c0d0c4497732b6c771148a3e..386fe2398e63aec931bb665ea82dea7db5c0f0ef 100644 (file)
@@ -278,6 +278,14 @@ pre.compile_fail:hover, .information:hover + pre.compile_fail {
        border-left: 2px solid #f00;
 }
 
+pre.should_panic {
+       border-left: 2px solid rgba(255,0,0,.5);
+}
+
+pre.should_panic:hover, .information:hover + pre.should_panic {
+       border-left: 2px solid #f00;
+}
+
 pre.ignore {
        border-left: 2px solid rgba(255,142,0,.6);
 }
@@ -294,6 +302,14 @@ pre.ignore:hover, .information:hover + pre.ignore {
        color: #f00;
 }
 
+.tooltip.should_panic {
+       color: rgba(255,0,0,.5);
+}
+
+.information > .should_panic:hover {
+       color: #f00;
+}
+
 .tooltip.ignore {
        color: rgba(255,142,0,.6);
 }
index 2f77929c74e379a4d59edc798cee4acbdca72ec4..2157a4d5389466aa006d99d83d4734e623e951e5 100644 (file)
@@ -4,6 +4,7 @@
 
 // @has foo/fn.bar.html '//*[@class="tooltip compile_fail"]/span' "This example deliberately fails to compile"
 // @has foo/fn.bar.html '//*[@class="tooltip ignore"]/span' "This example is not tested"
+// @has foo/fn.bar.html '//*[@class="tooltip should_panic"]/span' "This example panics"
 
 /// foo
 ///
 /// goo();
 /// ```
 ///
+/// ```should_panic
+/// hoo();
+/// ```
+/// 
 /// ```
 /// let x = 0;
 /// ```