",
match tooltip {
- Tooltip::Ignore => " ignore",
+ Tooltip::IgnoreAll | Tooltip::IgnoreSome(_) => " ignore",
Tooltip::CompileFail => " compile_fail",
Tooltip::ShouldPanic => " should_panic",
Tooltip::Edition(_) => " edition",
@@ -80,23 +81,29 @@ fn write_header(
);
if tooltip != Tooltip::None {
- let edition_code;
- write_str(
- out,
- format_args!(
- "
ⓘ",
- match tooltip {
- Tooltip::Ignore => "This example is not tested",
- Tooltip::CompileFail => "This example deliberately fails to compile",
- Tooltip::ShouldPanic => "This example panics",
- Tooltip::Edition(edition) => {
- edition_code = format!("This example runs with edition {edition}");
- &edition_code
+ let tooltip = fmt::from_fn(|f| match &tooltip {
+ Tooltip::IgnoreAll => f.write_str("This example is not tested"),
+ Tooltip::IgnoreSome(platforms) => {
+ f.write_str("This example is not tested on ")?;
+ match &platforms[..] {
+ [] => unreachable!(),
+ [platform] => f.write_str(platform)?,
+ [first, second] => write!(f, "{first} or {second}")?,
+ [platforms @ .., last] => {
+ for platform in platforms {
+ write!(f, "{platform}, ")?;
+ }
+ write!(f, "or {last}")?;
}
- Tooltip::None => unreachable!(),
}
- ),
- );
+ Ok(())
+ }
+ Tooltip::CompileFail => f.write_str("This example deliberately fails to compile"),
+ Tooltip::ShouldPanic => f.write_str("This example panics"),
+ Tooltip::Edition(edition) => write!(f, "This example runs with edition {edition}"),
+ Tooltip::None => unreachable!(),
+ });
+ write_str(out, format_args!("
ⓘ"));
}
if let Some(extra) = extra_content {
diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs
index ad7dfafd90c7d..987b92fa4e231 100644
--- a/src/librustdoc/html/markdown.rs
+++ b/src/librustdoc/html/markdown.rs
@@ -320,8 +320,10 @@ impl<'a, I: Iterator
- >> Iterator for CodeBlocks<'_, 'a, I> {
))
});
- let tooltip = if ignore != Ignore::None {
- highlight::Tooltip::Ignore
+ let tooltip = if ignore == Ignore::All {
+ highlight::Tooltip::IgnoreAll
+ } else if let Ignore::Some(platforms) = ignore {
+ highlight::Tooltip::IgnoreSome(platforms)
} else if compile_fail {
highlight::Tooltip::CompileFail
} else if should_panic {
diff --git a/tests/rustdoc/doctest/ignore-sometimes.rs b/tests/rustdoc/doctest/ignore-sometimes.rs
new file mode 100644
index 0000000000000..0f8586d221c15
--- /dev/null
+++ b/tests/rustdoc/doctest/ignore-sometimes.rs
@@ -0,0 +1,23 @@
+#![crate_name = "foo"]
+
+// test for https://github.com/rust-lang/rust/issues/141092
+
+//@ has 'foo/fn.f.html' '//a[@title="This example is not tested on wasm"]' 'ⓘ'
+/// Example
+///
+/// ```ignore-wasm
+/// let x = 1;
+/// ```
+pub fn f() {}
+
+//@ has 'foo/fn.g.html' '//a[@title="This example is not tested on wasm or windows"]' 'ⓘ'
+/// ```ignore-wasm,ignore-windows
+/// let x = 1;
+/// ```
+pub fn g() {}
+
+//@ has 'foo/fn.h.html' '//a[@title="This example is not tested on wasm, windows, or unix"]' 'ⓘ'
+/// ```ignore-wasm,ignore-windows,ignore-unix
+/// let x = 1;
+/// ```
+pub fn h() {}