Skip to content

Commit a524f0c

Browse files
authored
Unrolled build for #141517
Rollup merge of #141517 - lolbinarycat:rustdoc-doctest-tooltip-ignore-141092, r=notriddle rustdoc: use descriptive tooltip if doctest is conditionally ignored fixes #141092 here's what it looks like now: ![screenshot](https://github.com/user-attachments/assets/71e679fe-8828-439d-a2ce-b9187ad3aeea)
2 parents be42293 + f9931d1 commit a524f0c

File tree

3 files changed

+53
-21
lines changed

3 files changed

+53
-21
lines changed

src/librustdoc/html/highlight.rs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! Use the `render_with_highlighting` to highlight some rust code.
77
88
use std::collections::VecDeque;
9-
use std::fmt::{Display, Write};
9+
use std::fmt::{self, Display, Write};
1010

1111
use rustc_data_structures::fx::FxIndexMap;
1212
use rustc_lexer::{Cursor, FrontmatterAllowed, LiteralKind, TokenKind};
@@ -36,9 +36,10 @@ pub(crate) struct HrefContext<'a, 'tcx> {
3636
#[derive(Default)]
3737
pub(crate) struct DecorationInfo(pub(crate) FxIndexMap<&'static str, Vec<(u32, u32)>>);
3838

39-
#[derive(Eq, PartialEq, Clone, Copy)]
39+
#[derive(Eq, PartialEq, Clone)]
4040
pub(crate) enum Tooltip {
41-
Ignore,
41+
IgnoreAll,
42+
IgnoreSome(Vec<String>),
4243
CompileFail,
4344
ShouldPanic,
4445
Edition(Edition),
@@ -70,7 +71,7 @@ fn write_header(
7071
format_args!(
7172
"<div class=\"example-wrap{}\">",
7273
match tooltip {
73-
Tooltip::Ignore => " ignore",
74+
Tooltip::IgnoreAll | Tooltip::IgnoreSome(_) => " ignore",
7475
Tooltip::CompileFail => " compile_fail",
7576
Tooltip::ShouldPanic => " should_panic",
7677
Tooltip::Edition(_) => " edition",
@@ -80,23 +81,29 @@ fn write_header(
8081
);
8182

8283
if tooltip != Tooltip::None {
83-
let edition_code;
84-
write_str(
85-
out,
86-
format_args!(
87-
"<a href=\"#\" class=\"tooltip\" title=\"{}\">ⓘ</a>",
88-
match tooltip {
89-
Tooltip::Ignore => "This example is not tested",
90-
Tooltip::CompileFail => "This example deliberately fails to compile",
91-
Tooltip::ShouldPanic => "This example panics",
92-
Tooltip::Edition(edition) => {
93-
edition_code = format!("This example runs with edition {edition}");
94-
&edition_code
84+
let tooltip = fmt::from_fn(|f| match &tooltip {
85+
Tooltip::IgnoreAll => f.write_str("This example is not tested"),
86+
Tooltip::IgnoreSome(platforms) => {
87+
f.write_str("This example is not tested on ")?;
88+
match &platforms[..] {
89+
[] => unreachable!(),
90+
[platform] => f.write_str(platform)?,
91+
[first, second] => write!(f, "{first} or {second}")?,
92+
[platforms @ .., last] => {
93+
for platform in platforms {
94+
write!(f, "{platform}, ")?;
95+
}
96+
write!(f, "or {last}")?;
9597
}
96-
Tooltip::None => unreachable!(),
9798
}
98-
),
99-
);
99+
Ok(())
100+
}
101+
Tooltip::CompileFail => f.write_str("This example deliberately fails to compile"),
102+
Tooltip::ShouldPanic => f.write_str("This example panics"),
103+
Tooltip::Edition(edition) => write!(f, "This example runs with edition {edition}"),
104+
Tooltip::None => unreachable!(),
105+
});
106+
write_str(out, format_args!("<a href=\"#\" class=\"tooltip\" title=\"{tooltip}\">ⓘ</a>"));
100107
}
101108

102109
if let Some(extra) = extra_content {

src/librustdoc/html/markdown.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,10 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
320320
))
321321
});
322322

323-
let tooltip = if ignore != Ignore::None {
324-
highlight::Tooltip::Ignore
323+
let tooltip = if ignore == Ignore::All {
324+
highlight::Tooltip::IgnoreAll
325+
} else if let Ignore::Some(platforms) = ignore {
326+
highlight::Tooltip::IgnoreSome(platforms)
325327
} else if compile_fail {
326328
highlight::Tooltip::CompileFail
327329
} else if should_panic {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#![crate_name = "foo"]
2+
3+
// test for https://github.com/rust-lang/rust/issues/141092
4+
5+
//@ has 'foo/fn.f.html' '//a[@title="This example is not tested on wasm"]' 'ⓘ'
6+
/// Example
7+
///
8+
/// ```ignore-wasm
9+
/// let x = 1;
10+
/// ```
11+
pub fn f() {}
12+
13+
//@ has 'foo/fn.g.html' '//a[@title="This example is not tested on wasm or windows"]' 'ⓘ'
14+
/// ```ignore-wasm,ignore-windows
15+
/// let x = 1;
16+
/// ```
17+
pub fn g() {}
18+
19+
//@ has 'foo/fn.h.html' '//a[@title="This example is not tested on wasm, windows, or unix"]' 'ⓘ'
20+
/// ```ignore-wasm,ignore-windows,ignore-unix
21+
/// let x = 1;
22+
/// ```
23+
pub fn h() {}

0 commit comments

Comments
 (0)