Skip to content

Commit bf286a8

Browse files
committed
Auto merge of #103119 - matthiaskrgr:rollup-2vb8hif, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #102857 (Add a regression test for #39137) - #102953 (Improve docs for `struct_lint_level` function.) - #103060 (rustdoc: make the help button a link to a page) - #103115 (Clean up anchors.goml rustdoc GUI test) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8be3ce9 + ae717c7 commit bf286a8

File tree

17 files changed

+360
-198
lines changed

17 files changed

+360
-198
lines changed

Diff for: compiler/rustc_lint/src/context.rs

+19
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,11 @@ pub trait LintContext: Sized {
574574
fn sess(&self) -> &Session;
575575
fn lints(&self) -> &LintStore;
576576

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

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

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

916931
/// Emit a lint at the appropriate level, with no associated span.
932+
///
933+
/// Return value of the `decorate` closure is ignored, see [`struct_lint_level`] for a detailed explanation.
934+
///
935+
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
917936
fn lint(
918937
&self,
919938
lint: &'static Lint,

Diff for: compiler/rustc_lint/src/levels.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,10 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
10691069

10701070
/// Used to emit a lint-related diagnostic based on the current state of
10711071
/// this lint context.
1072+
///
1073+
/// Return value of the `decorate` closure is ignored, see [`struct_lint_level`] for a detailed explanation.
1074+
///
1075+
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
10721076
pub(crate) fn struct_lint(
10731077
&self,
10741078
lint: &'static Lint,

Diff for: compiler/rustc_middle/src/lint.rs

+33
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,39 @@ pub fn explain_lint_level_source(
274274
}
275275
}
276276

277+
/// The innermost function for emitting lints.
278+
///
279+
/// If you are loocking to implement a lint, look for higher level functions,
280+
/// for example:
281+
/// - [`TyCtxt::emit_spanned_lint`]
282+
/// - [`TyCtxt::struct_span_lint_hir`]
283+
/// - [`TyCtxt::emit_lint`]
284+
/// - [`TyCtxt::struct_lint_node`]
285+
/// - `LintContext::lookup`
286+
///
287+
/// ## `decorate` signature
288+
///
289+
/// The return value of `decorate` is ignored by this function. So what is the
290+
/// point of returning `&'b mut DiagnosticBuilder<'a, ()>`?
291+
///
292+
/// There are 2 reasons for this signature.
293+
///
294+
/// First of all, it prevents accidental use of `.emit()` -- it's clear that the
295+
/// builder will be later used and shouldn't be emitted right away (this is
296+
/// especially important because the old API expected you to call `.emit()` in
297+
/// the closure).
298+
///
299+
/// Second of all, it makes the most common case of adding just a single label
300+
/// /suggestion much nicer, since [`DiagnosticBuilder`] methods return
301+
/// `&mut DiagnosticBuilder`, you can just chain methods, without needed
302+
/// awkward `{ ...; }`:
303+
/// ```ignore pseudo-code
304+
/// struct_lint_level(
305+
/// ...,
306+
/// |lint| lint.span_label(sp, "lbl")
307+
/// // ^^^^^^^^^^^^^^^^^^^^^ returns `&mut DiagnosticBuilder` by default
308+
/// )
309+
/// ```
277310
pub fn struct_lint_level(
278311
sess: &Session,
279312
lint: &'static Lint,

Diff for: compiler/rustc_middle/src/ty/context.rs

+10
Original file line numberDiff line numberDiff line change
@@ -2823,6 +2823,11 @@ impl<'tcx> TyCtxt<'tcx> {
28232823
})
28242824
}
28252825

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

2856+
/// Emit a lint at the appropriate level for a hir node.
2857+
///
2858+
/// Return value of the `decorate` closure is ignored, see [`struct_lint_level`] for a detailed explanation.
2859+
///
2860+
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
28512861
pub fn struct_lint_node(
28522862
self,
28532863
lint: &'static Lint,
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.12.4
1+
0.12.5

Diff for: src/librustdoc/html/markdown.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,7 @@ static DEFAULT_ID_MAP: Lazy<FxHashMap<Cow<'static, str>, usize>> = Lazy::new(||
14331433
fn init_id_map() -> FxHashMap<Cow<'static, str>, usize> {
14341434
let mut map = FxHashMap::default();
14351435
// This is the list of IDs used in Javascript.
1436+
map.insert("help".into(), 1);
14361437
map.insert("settings".into(), 1);
14371438
map.insert("not-displayed".into(), 1);
14381439
map.insert("alternative-display".into(), 1);

Diff for: src/librustdoc/html/render/context.rs

+34
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
581581
let crate_name = self.tcx().crate_name(LOCAL_CRATE);
582582
let final_file = self.dst.join(crate_name.as_str()).join("all.html");
583583
let settings_file = self.dst.join("settings.html");
584+
let help_file = self.dst.join("help.html");
584585
let scrape_examples_help_file = self.dst.join("scrape-examples-help.html");
585586

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

661+
// Generating help page.
662+
page.title = "Rustdoc help";
663+
page.description = "Documentation for Rustdoc";
664+
page.root_path = "./";
665+
666+
let sidebar = "<h2 class=\"location\">Help</h2><div class=\"sidebar-elems\"></div>";
667+
let v = layout::render(
668+
&shared.layout,
669+
&page,
670+
sidebar,
671+
|buf: &mut Buffer| {
672+
write!(
673+
buf,
674+
"<div class=\"main-heading\">\
675+
<h1 class=\"fqn\">Rustdoc help</h1>\
676+
<span class=\"out-of-band\">\
677+
<a id=\"back\" href=\"javascript:void(0)\" onclick=\"history.back();\">\
678+
Back\
679+
</a>\
680+
</span>\
681+
</div>\
682+
<noscript>\
683+
<section>\
684+
<p>You need to enable Javascript to use keyboard commands or search.</p>\
685+
<p>For more information, browse the <a href=\"https://doc.rust-lang.org/rustdoc/\">rustdoc handbook</a>.</p>\
686+
</section>\
687+
</noscript>",
688+
)
689+
},
690+
&shared.style_files,
691+
);
692+
shared.fs.write(help_file, v)?;
693+
660694
if shared.layout.scrape_examples_extension {
661695
page.title = "About scraped examples";
662696
page.description = "How the scraped examples feature works in Rustdoc";

Diff for: src/librustdoc/html/static/css/rustdoc.css

+11-10
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ h1, h2, h3, h4, h5, h6,
199199
.out-of-band,
200200
span.since,
201201
a.srclink,
202-
#help-button > button,
202+
#help-button > a,
203203
details.rustdoc-toggle.top-doc > summary,
204204
details.rustdoc-toggle.non-exhaustive > summary,
205205
.scraped-example-title,
@@ -974,32 +974,33 @@ so that we can apply CSS-filters to change the arrow color in themes */
974974
color: var(--main-color);
975975
}
976976

977-
#help-button .popover {
977+
/* use larger max-width for help popover, but not for help.html */
978+
#help.popover {
978979
max-width: 600px;
979980
}
980981

981-
#help-button .popover::before {
982+
#help.popover::before {
982983
right: 48px;
983984
}
984985

985-
#help-button dt {
986+
#help dt {
986987
float: left;
987988
clear: left;
988989
display: block;
989990
margin-right: 0.5rem;
990991
}
991-
#help-button span.top, #help-button span.bottom {
992+
#help span.top, #help span.bottom {
992993
text-align: center;
993994
display: block;
994995
font-size: 1.125rem;
995996
}
996-
#help-button span.top {
997+
#help span.top {
997998
margin: 10px 0;
998999
border-bottom: 1px solid var(--border-color);
9991000
padding-bottom: 4px;
10001001
margin-bottom: 6px;
10011002
}
1002-
#help-button span.bottom {
1003+
#help span.bottom {
10031004
clear: both;
10041005
border-top: 1px solid var(--border-color);
10051006
}
@@ -1433,7 +1434,7 @@ h3.variant {
14331434
outline: none;
14341435
}
14351436

1436-
#settings-menu > a, #help-button > button, #copy-path {
1437+
#settings-menu > a, #help-button > a, #copy-path {
14371438
padding: 5px;
14381439
width: 33px;
14391440
border: 1px solid var(--border-color);
@@ -1442,7 +1443,7 @@ h3.variant {
14421443
line-height: 1.5;
14431444
}
14441445

1445-
#settings-menu > a, #help-button > button {
1446+
#settings-menu > a, #help-button > a {
14461447
padding: 5px;
14471448
height: 100%;
14481449
display: block;
@@ -1490,7 +1491,7 @@ input:checked + .slider {
14901491
background-color: var(--settings-input-color);
14911492
}
14921493

1493-
#help-button > button {
1494+
#help-button > a {
14941495
text-align: center;
14951496
/* Rare exception to specifying font sizes in rem. Since this is acting
14961497
as an icon, it's okay to specify their sizes in pixels. */

Diff for: src/librustdoc/html/static/css/themes/ayu.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ kbd {
248248
box-shadow: inset 0 -1px 0 #5c6773;
249249
}
250250

251-
#settings-menu > a, #help-button > button {
251+
#settings-menu > a, #help-button > a {
252252
color: #fff;
253253
}
254254

@@ -257,7 +257,7 @@ kbd {
257257
}
258258

259259
#settings-menu > a:hover, #settings-menu > a:focus,
260-
#help-button > button:hover, #help-button > button:focus {
260+
#help-button > a:hover, #help-button > a:focus {
261261
border-color: #e0e0e0;
262262
}
263263

Diff for: src/librustdoc/html/static/css/themes/dark.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ kbd {
153153
box-shadow: inset 0 -1px 0 #c6cbd1;
154154
}
155155

156-
#settings-menu > a, #help-button > button {
156+
#settings-menu > a, #help-button > a {
157157
color: #000;
158158
}
159159

160160
#settings-menu > a:hover, #settings-menu > a:focus,
161-
#help-button > button:hover, #help-button > button:focus {
161+
#help-button > a:hover, #help-button > a:focus {
162162
border-color: #ffb900;
163163
}
164164

Diff for: src/librustdoc/html/static/css/themes/light.css

+5-1
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,12 @@ kbd {
147147
box-shadow: inset 0 -1px 0 #c6cbd1;
148148
}
149149

150+
#settings-menu > a, #help-button > a {
151+
color: #000;
152+
}
153+
150154
#settings-menu > a:hover, #settings-menu > a:focus,
151-
#help-button > button:hover, #help-button > button:focus {
155+
#help-button > a:hover, #help-button > a:focus {
152156
border-color: #717171;
153157
}
154158

0 commit comments

Comments
 (0)