Skip to content

Commit aaff372

Browse files
committed
Remove Tooltip::None variant, use Option::None
1 parent 58c7505 commit aaff372

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

src/librustdoc/html/highlight.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,12 @@ pub(crate) enum Tooltip {
4747
CompileFail,
4848
ShouldPanic,
4949
Edition(Edition),
50-
None,
5150
}
5251

5352
/// Highlights `src` as an inline example, returning the HTML output.
5453
pub(crate) fn render_example_with_highlighting(
5554
src: &str,
56-
tooltip: &Tooltip,
55+
tooltip: Option<&Tooltip>,
5756
playground_button: Option<&str>,
5857
extra_classes: &[String],
5958
) -> impl Display {
@@ -67,23 +66,24 @@ pub(crate) fn render_example_with_highlighting(
6766
fn write_header(
6867
class: &str,
6968
extra_content: Option<&str>,
70-
tooltip: &Tooltip,
69+
tooltip: Option<&Tooltip>,
7170
extra_classes: &[String],
7271
) -> impl Display {
7372
fmt::from_fn(move |f| {
7473
write!(
7574
f,
7675
"<div class=\"example-wrap{}\">",
77-
match tooltip {
78-
Tooltip::IgnoreAll | Tooltip::IgnoreSome(_) => " ignore",
79-
Tooltip::CompileFail => " compile_fail",
80-
Tooltip::ShouldPanic => " should_panic",
81-
Tooltip::Edition(_) => " edition",
82-
Tooltip::None => "",
83-
}
76+
tooltip
77+
.map(|tooltip| match tooltip {
78+
Tooltip::IgnoreAll | Tooltip::IgnoreSome(_) => " ignore",
79+
Tooltip::CompileFail => " compile_fail",
80+
Tooltip::ShouldPanic => " should_panic",
81+
Tooltip::Edition(_) => " edition",
82+
})
83+
.unwrap_or_default()
8484
)?;
8585

86-
if *tooltip != Tooltip::None {
86+
if let Some(tooltip) = tooltip {
8787
let tooltip = fmt::from_fn(|f| match tooltip {
8888
Tooltip::IgnoreAll => f.write_str("This example is not tested"),
8989
Tooltip::IgnoreSome(platforms) => {
@@ -104,7 +104,6 @@ fn write_header(
104104
Tooltip::CompileFail => f.write_str("This example deliberately fails to compile"),
105105
Tooltip::ShouldPanic => f.write_str("This example panics"),
106106
Tooltip::Edition(edition) => write!(f, "This example runs with edition {edition}"),
107-
Tooltip::None => unreachable!(),
108107
});
109108

110109
write!(f, "<a href=\"#\" class=\"tooltip\" title=\"{tooltip}\">ⓘ</a>")?;

src/librustdoc/html/markdown.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -321,18 +321,22 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
321321
))
322322
});
323323

324-
let tooltip = if ignore == Ignore::All {
325-
highlight::Tooltip::IgnoreAll
326-
} else if let Ignore::Some(platforms) = ignore {
327-
highlight::Tooltip::IgnoreSome(platforms)
328-
} else if compile_fail {
329-
highlight::Tooltip::CompileFail
330-
} else if should_panic {
331-
highlight::Tooltip::ShouldPanic
332-
} else if explicit_edition {
333-
highlight::Tooltip::Edition(edition)
334-
} else {
335-
highlight::Tooltip::None
324+
let tooltip = {
325+
use highlight::Tooltip::*;
326+
327+
if ignore == Ignore::All {
328+
Some(IgnoreAll)
329+
} else if let Ignore::Some(platforms) = ignore {
330+
Some(IgnoreSome(platforms))
331+
} else if compile_fail {
332+
Some(CompileFail)
333+
} else if should_panic {
334+
Some(ShouldPanic)
335+
} else if explicit_edition {
336+
Some(Edition(edition))
337+
} else {
338+
None
339+
}
336340
};
337341

338342
// insert newline to clearly separate it from the
@@ -341,7 +345,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
341345
"\n{}",
342346
highlight::render_example_with_highlighting(
343347
&text,
344-
&tooltip,
348+
tooltip.as_ref(),
345349
playground_button.as_deref(),
346350
&added_classes,
347351
)

0 commit comments

Comments
 (0)