未验证 提交 6c53a0c2 编写于 作者: M Manish Goregaokar 提交者: GitHub

Rollup merge of #73476 - JakobDegen:should_panic_rustdoc, r=GuillaumeGomez

Added tooltip for should_panic code examples

This change adds a tooltip to the documentation for `should_panic` examples. It currently displays identically to `compile_fail` examples, save for the changed text. It may be helpful to change the color that this displays in to make it visually more clear what is going on, but I'm unsure if additional colors wouldn't just be distracting.

I brought this [up on internals](https://internals.rust-lang.org/t/indicating-that-an-example-is-should-panic-in-docs/12544) a few days ago, and there seemed to be a mild positive response to it.
......@@ -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 {
......
......@@ -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;
}
......
......@@ -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);
}
......
......@@ -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);
}
......
......@@ -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
///
......@@ -15,6 +16,10 @@
/// goo();
/// ```
///
/// ```should_panic
/// hoo();
/// ```
///
/// ```
/// let x = 0;
/// ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册