Skip to content

Commit

Permalink
Auto merge of rust-lang#103119 - matthiaskrgr:rollup-2vb8hif, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 4 pull requests

Successful merges:

 - rust-lang#102857 (Add a regression test for rust-lang#39137)
 - rust-lang#102953 (Improve docs for `struct_lint_level` function.)
 - rust-lang#103060 (rustdoc: make the help button a link to a page)
 - rust-lang#103115 (Clean up anchors.goml rustdoc GUI test)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Oct 16, 2022
2 parents 8be3ce9 + ae717c7 commit bf286a8
Show file tree
Hide file tree
Showing 17 changed files with 360 additions and 198 deletions.
19 changes: 19 additions & 0 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,11 @@ pub trait LintContext: Sized {
fn sess(&self) -> &Session;
fn lints(&self) -> &LintStore;

/// Emit a lint at the appropriate level, with an optional associated span and an existing diagnostic.
///
/// Return value of the `decorate` closure is ignored, see [`struct_lint_level`] for a detailed explanation.
///
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
fn lookup_with_diagnostics(
&self,
lint: &'static Lint,
Expand Down Expand Up @@ -872,6 +877,11 @@ pub trait LintContext: Sized {

// FIXME: These methods should not take an Into<MultiSpan> -- instead, callers should need to
// set the span in their `decorate` function (preferably using set_span).
/// Emit a lint at the appropriate level, with an optional associated span.
///
/// Return value of the `decorate` closure is ignored, see [`struct_lint_level`] for a detailed explanation.
///
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
fn lookup<S: Into<MultiSpan>>(
&self,
lint: &'static Lint,
Expand All @@ -893,6 +903,11 @@ pub trait LintContext: Sized {
self.lookup(lint, Some(span), decorator.msg(), |diag| decorator.decorate_lint(diag));
}

/// Emit a lint at the appropriate level, with an associated span.
///
/// Return value of the `decorate` closure is ignored, see [`struct_lint_level`] for a detailed explanation.
///
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
fn struct_span_lint<S: Into<MultiSpan>>(
&self,
lint: &'static Lint,
Expand All @@ -914,6 +929,10 @@ pub trait LintContext: Sized {
}

/// Emit a lint at the appropriate level, with no associated span.
///
/// Return value of the `decorate` closure is ignored, see [`struct_lint_level`] for a detailed explanation.
///
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
fn lint(
&self,
lint: &'static Lint,
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_lint/src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,10 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {

/// Used to emit a lint-related diagnostic based on the current state of
/// this lint context.
///
/// Return value of the `decorate` closure is ignored, see [`struct_lint_level`] for a detailed explanation.
///
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
pub(crate) fn struct_lint(
&self,
lint: &'static Lint,
Expand Down
33 changes: 33 additions & 0 deletions compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,39 @@ pub fn explain_lint_level_source(
}
}

/// The innermost function for emitting lints.
///
/// If you are loocking to implement a lint, look for higher level functions,
/// for example:
/// - [`TyCtxt::emit_spanned_lint`]
/// - [`TyCtxt::struct_span_lint_hir`]
/// - [`TyCtxt::emit_lint`]
/// - [`TyCtxt::struct_lint_node`]
/// - `LintContext::lookup`
///
/// ## `decorate` signature
///
/// The return value of `decorate` is ignored by this function. So what is the
/// point of returning `&'b mut DiagnosticBuilder<'a, ()>`?
///
/// There are 2 reasons for this signature.
///
/// First of all, it prevents accidental use of `.emit()` -- it's clear that the
/// builder will be later used and shouldn't be emitted right away (this is
/// especially important because the old API expected you to call `.emit()` in
/// the closure).
///
/// Second of all, it makes the most common case of adding just a single label
/// /suggestion much nicer, since [`DiagnosticBuilder`] methods return
/// `&mut DiagnosticBuilder`, you can just chain methods, without needed
/// awkward `{ ...; }`:
/// ```ignore pseudo-code
/// struct_lint_level(
/// ...,
/// |lint| lint.span_label(sp, "lbl")
/// // ^^^^^^^^^^^^^^^^^^^^^ returns `&mut DiagnosticBuilder` by default
/// )
/// ```
pub fn struct_lint_level(
sess: &Session,
lint: &'static Lint,
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2823,6 +2823,11 @@ impl<'tcx> TyCtxt<'tcx> {
})
}

/// Emit a lint at the appropriate level for a hir node, with an associated span.
///
/// Return value of the `decorate` closure is ignored, see [`struct_lint_level`] for a detailed explanation.
///
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
pub fn struct_span_lint_hir(
self,
lint: &'static Lint,
Expand All @@ -2848,6 +2853,11 @@ impl<'tcx> TyCtxt<'tcx> {
self.struct_lint_node(lint, id, decorator.msg(), |diag| decorator.decorate_lint(diag))
}

/// Emit a lint at the appropriate level for a hir node.
///
/// Return value of the `decorate` closure is ignored, see [`struct_lint_level`] for a detailed explanation.
///
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
pub fn struct_lint_node(
self,
lint: &'static Lint,
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.12.4
0.12.5
1 change: 1 addition & 0 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,7 @@ static DEFAULT_ID_MAP: Lazy<FxHashMap<Cow<'static, str>, usize>> = Lazy::new(||
fn init_id_map() -> FxHashMap<Cow<'static, str>, usize> {
let mut map = FxHashMap::default();
// This is the list of IDs used in Javascript.
map.insert("help".into(), 1);
map.insert("settings".into(), 1);
map.insert("not-displayed".into(), 1);
map.insert("alternative-display".into(), 1);
Expand Down
34 changes: 34 additions & 0 deletions src/librustdoc/html/render/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
let crate_name = self.tcx().crate_name(LOCAL_CRATE);
let final_file = self.dst.join(crate_name.as_str()).join("all.html");
let settings_file = self.dst.join("settings.html");
let help_file = self.dst.join("help.html");
let scrape_examples_help_file = self.dst.join("scrape-examples-help.html");

let mut root_path = self.dst.to_str().expect("invalid path").to_owned();
Expand Down Expand Up @@ -657,6 +658,39 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
);
shared.fs.write(settings_file, v)?;

// Generating help page.
page.title = "Rustdoc help";
page.description = "Documentation for Rustdoc";
page.root_path = "./";

let sidebar = "<h2 class=\"location\">Help</h2><div class=\"sidebar-elems\"></div>";
let v = layout::render(
&shared.layout,
&page,
sidebar,
|buf: &mut Buffer| {
write!(
buf,
"<div class=\"main-heading\">\
<h1 class=\"fqn\">Rustdoc help</h1>\
<span class=\"out-of-band\">\
<a id=\"back\" href=\"javascript:void(0)\" onclick=\"history.back();\">\
Back\
</a>\
</span>\
</div>\
<noscript>\
<section>\
<p>You need to enable Javascript to use keyboard commands or search.</p>\
<p>For more information, browse the <a href=\"https://doc.rust-lang.org/rustdoc/\">rustdoc handbook</a>.</p>\
</section>\
</noscript>",
)
},
&shared.style_files,
);
shared.fs.write(help_file, v)?;

if shared.layout.scrape_examples_extension {
page.title = "About scraped examples";
page.description = "How the scraped examples feature works in Rustdoc";
Expand Down
21 changes: 11 additions & 10 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ h1, h2, h3, h4, h5, h6,
.out-of-band,
span.since,
a.srclink,
#help-button > button,
#help-button > a,
details.rustdoc-toggle.top-doc > summary,
details.rustdoc-toggle.non-exhaustive > summary,
.scraped-example-title,
Expand Down Expand Up @@ -974,32 +974,33 @@ so that we can apply CSS-filters to change the arrow color in themes */
color: var(--main-color);
}

#help-button .popover {
/* use larger max-width for help popover, but not for help.html */
#help.popover {
max-width: 600px;
}

#help-button .popover::before {
#help.popover::before {
right: 48px;
}

#help-button dt {
#help dt {
float: left;
clear: left;
display: block;
margin-right: 0.5rem;
}
#help-button span.top, #help-button span.bottom {
#help span.top, #help span.bottom {
text-align: center;
display: block;
font-size: 1.125rem;
}
#help-button span.top {
#help span.top {
margin: 10px 0;
border-bottom: 1px solid var(--border-color);
padding-bottom: 4px;
margin-bottom: 6px;
}
#help-button span.bottom {
#help span.bottom {
clear: both;
border-top: 1px solid var(--border-color);
}
Expand Down Expand Up @@ -1433,7 +1434,7 @@ h3.variant {
outline: none;
}

#settings-menu > a, #help-button > button, #copy-path {
#settings-menu > a, #help-button > a, #copy-path {
padding: 5px;
width: 33px;
border: 1px solid var(--border-color);
Expand All @@ -1442,7 +1443,7 @@ h3.variant {
line-height: 1.5;
}

#settings-menu > a, #help-button > button {
#settings-menu > a, #help-button > a {
padding: 5px;
height: 100%;
display: block;
Expand Down Expand Up @@ -1490,7 +1491,7 @@ input:checked + .slider {
background-color: var(--settings-input-color);
}

#help-button > button {
#help-button > a {
text-align: center;
/* Rare exception to specifying font sizes in rem. Since this is acting
as an icon, it's okay to specify their sizes in pixels. */
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/static/css/themes/ayu.css
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ kbd {
box-shadow: inset 0 -1px 0 #5c6773;
}

#settings-menu > a, #help-button > button {
#settings-menu > a, #help-button > a {
color: #fff;
}

Expand All @@ -257,7 +257,7 @@ kbd {
}

#settings-menu > a:hover, #settings-menu > a:focus,
#help-button > button:hover, #help-button > button:focus {
#help-button > a:hover, #help-button > a:focus {
border-color: #e0e0e0;
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/static/css/themes/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ kbd {
box-shadow: inset 0 -1px 0 #c6cbd1;
}

#settings-menu > a, #help-button > button {
#settings-menu > a, #help-button > a {
color: #000;
}

#settings-menu > a:hover, #settings-menu > a:focus,
#help-button > button:hover, #help-button > button:focus {
#help-button > a:hover, #help-button > a:focus {
border-color: #ffb900;
}

Expand Down
6 changes: 5 additions & 1 deletion src/librustdoc/html/static/css/themes/light.css
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,12 @@ kbd {
box-shadow: inset 0 -1px 0 #c6cbd1;
}

#settings-menu > a, #help-button > a {
color: #000;
}

#settings-menu > a:hover, #settings-menu > a:focus,
#help-button > button:hover, #help-button > button:focus {
#help-button > a:hover, #help-button > a:focus {
border-color: #717171;
}

Expand Down
Loading

0 comments on commit bf286a8

Please sign in to comment.