Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tooltip for should_panic code examples #73476

Merged
merged 2 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -205,6 +206,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
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 {
Expand Down Expand Up @@ -280,6 +282,8 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
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 {
Expand All @@ -295,6 +299,8 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
" ignore"
} else if compile_fail {
" compile_fail"
} else if should_panic {
" should_panic"
} else if explicit_edition {
" edition "
} else {
Expand All @@ -314,6 +320,8 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
" ignore"
} else if compile_fail {
" compile_fail"
} else if should_panic {
" should_panic"
} else if explicit_edition {
" edition "
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
16 changes: 16 additions & 0 deletions src/librustdoc/html/static/themes/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
16 changes: 16 additions & 0 deletions src/librustdoc/html/static/themes/light.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions src/test/rustdoc/codeblock-title.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand All @@ -15,6 +16,10 @@
/// goo();
/// ```
///
/// ```should_panic
/// hoo();
/// ```
///
/// ```
/// let x = 0;
/// ```
Expand Down