Skip to content

Commit 70e52ca

Browse files
committed
Auto merge of #85231 - GuillaumeGomez:rollup-hufe4gz, r=GuillaumeGomez
Rollup of 5 pull requests Successful merges: - #84793 (Recover from invalid `struct` item syntax) - #85117 (Move global click handlers to per-element ones.) - #85141 (Update documentation for SharedContext::maybe_collapsed_doc_value) - #85174 (Fix border radius for doc code blocks in rustdoc) - #85205 (Update books) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 28e2b29 + 7684247 commit 70e52ca

18 files changed

+354
-138
lines changed

compiler/rustc_parse/src/parser/item.rs

+45-1
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,37 @@ impl<'a> Parser<'a> {
13991399
Ok(a_var)
14001400
}
14011401

1402+
fn expect_field_ty_separator(&mut self) -> PResult<'a, ()> {
1403+
if let Err(mut err) = self.expect(&token::Colon) {
1404+
let sm = self.sess.source_map();
1405+
let eq_typo = self.token.kind == token::Eq && self.look_ahead(1, |t| t.is_path_start());
1406+
let semi_typo = self.token.kind == token::Semi
1407+
&& self.look_ahead(1, |t| {
1408+
t.is_path_start()
1409+
// We check that we are in a situation like `foo; bar` to avoid bad suggestions
1410+
// when there's no type and `;` was used instead of a comma.
1411+
&& match (sm.lookup_line(self.token.span.hi()), sm.lookup_line(t.span.lo())) {
1412+
(Ok(l), Ok(r)) => l.line == r.line,
1413+
_ => true,
1414+
}
1415+
});
1416+
if eq_typo || semi_typo {
1417+
self.bump();
1418+
// Gracefully handle small typos.
1419+
err.span_suggestion_short(
1420+
self.prev_token.span,
1421+
"field names and their types are separated with `:`",
1422+
":".to_string(),
1423+
Applicability::MachineApplicable,
1424+
);
1425+
err.emit();
1426+
} else {
1427+
return Err(err);
1428+
}
1429+
}
1430+
Ok(())
1431+
}
1432+
14021433
/// Parses a structure field.
14031434
fn parse_name_and_ty(
14041435
&mut self,
@@ -1408,8 +1439,21 @@ impl<'a> Parser<'a> {
14081439
attrs: Vec<Attribute>,
14091440
) -> PResult<'a, FieldDef> {
14101441
let name = self.parse_field_ident(adt_ty, lo)?;
1411-
self.expect(&token::Colon)?;
1442+
self.expect_field_ty_separator()?;
14121443
let ty = self.parse_ty()?;
1444+
if self.token.kind == token::Eq {
1445+
self.bump();
1446+
let const_expr = self.parse_anon_const_expr()?;
1447+
let sp = ty.span.shrink_to_hi().to(const_expr.value.span);
1448+
self.struct_span_err(sp, "default values on `struct` fields aren't supported")
1449+
.span_suggestion(
1450+
sp,
1451+
"remove this unsupported default value",
1452+
String::new(),
1453+
Applicability::MachineApplicable,
1454+
)
1455+
.emit();
1456+
}
14131457
Ok(FieldDef {
14141458
span: lo.to(self.prev_token.span),
14151459
ident: Some(name),

src/doc/book

Submodule book updated 34 files

src/librustdoc/html/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ crate fn render<T: Print, S: Print>(
105105
placeholder=\"Click or press ‘S’ to search, ‘?’ for more options…\" \
106106
type=\"search\">\
107107
</div>\
108-
<button type=\"button\" class=\"help-button\">?</button>
108+
<button type=\"button\" id=\"help-button\">?</button>
109109
<a id=\"settings-menu\" href=\"{root_path}settings.html\">\
110110
<img src=\"{static_root_path}wheel{suffix}.svg\" \
111111
width=\"18\" height=\"18\" \

src/librustdoc/html/markdown.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,7 @@ fn init_id_map() -> FxHashMap<String, usize> {
13471347
map.insert("theme-picker".to_owned(), 1);
13481348
map.insert("theme-choices".to_owned(), 1);
13491349
map.insert("settings-menu".to_owned(), 1);
1350+
map.insert("help-button".to_owned(), 1);
13501351
map.insert("main".to_owned(), 1);
13511352
map.insert("search".to_owned(), 1);
13521353
map.insert("crate-search".to_owned(), 1);

src/librustdoc/html/render/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ impl SharedContext<'_> {
137137
Ok(())
138138
}
139139

140-
/// Based on whether the `collapse-docs` pass was run, return either the `doc_value` or the
141-
/// `collapsed_doc_value` of the given item.
140+
/// Returns the `collapsed_doc_value` of the given item if this is the main crate, otherwise
141+
/// returns the `doc_value`.
142142
crate fn maybe_collapsed_doc_value<'a>(&self, item: &'a clean::Item) -> Option<String> {
143143
if self.collapsed { item.collapsed_doc_value() } else { item.doc_value() }
144144
}

src/librustdoc/html/static/main.js

+29-117
Original file line numberDiff line numberDiff line change
@@ -381,56 +381,9 @@ function hideThemeButtonState() {
381381
}
382382
}
383383

384-
function highlightSourceLines(match, ev) {
385-
if (typeof match === "undefined") {
386-
// If we're in mobile mode, we should hide the sidebar in any case.
387-
hideSidebar();
388-
match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
389-
}
390-
if (!match) {
391-
return;
392-
}
393-
var from = parseInt(match[1], 10);
394-
var to = from;
395-
if (typeof match[2] !== "undefined") {
396-
to = parseInt(match[2], 10);
397-
}
398-
if (to < from) {
399-
var tmp = to;
400-
to = from;
401-
from = tmp;
402-
}
403-
var elem = document.getElementById(from);
404-
if (!elem) {
405-
return;
406-
}
407-
if (!ev) {
408-
var x = document.getElementById(from);
409-
if (x) {
410-
x.scrollIntoView();
411-
}
412-
}
413-
onEachLazy(document.getElementsByClassName("line-numbers"), function(e) {
414-
onEachLazy(e.getElementsByTagName("span"), function(i_e) {
415-
removeClass(i_e, "line-highlighted");
416-
});
417-
});
418-
for (var i = from; i <= to; ++i) {
419-
elem = document.getElementById(i);
420-
if (!elem) {
421-
break;
422-
}
423-
addClass(elem, "line-highlighted");
424-
}
425-
}
426-
427384
function onHashChange(ev) {
428385
// If we're in mobile mode, we should hide the sidebar in any case.
429386
hideSidebar();
430-
var match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
431-
if (match) {
432-
return highlightSourceLines(match, ev);
433-
}
434387
handleHashes(ev);
435388
}
436389

@@ -585,78 +538,9 @@ function hideThemeButtonState() {
585538
}
586539
}
587540

588-
function findParentElement(elem, tagName) {
589-
do {
590-
if (elem && elem.tagName === tagName) {
591-
return elem;
592-
}
593-
elem = elem.parentNode;
594-
} while (elem);
595-
return null;
596-
}
597-
598541
document.addEventListener("keypress", handleShortcut);
599542
document.addEventListener("keydown", handleShortcut);
600543

601-
var handleSourceHighlight = (function() {
602-
var prev_line_id = 0;
603-
604-
var set_fragment = function(name) {
605-
var x = window.scrollX,
606-
y = window.scrollY;
607-
if (searchState.browserSupportsHistoryApi()) {
608-
history.replaceState(null, null, "#" + name);
609-
highlightSourceLines();
610-
} else {
611-
location.replace("#" + name);
612-
}
613-
// Prevent jumps when selecting one or many lines
614-
window.scrollTo(x, y);
615-
};
616-
617-
return function(ev) {
618-
var cur_line_id = parseInt(ev.target.id, 10);
619-
ev.preventDefault();
620-
621-
if (ev.shiftKey && prev_line_id) {
622-
// Swap selection if needed
623-
if (prev_line_id > cur_line_id) {
624-
var tmp = prev_line_id;
625-
prev_line_id = cur_line_id;
626-
cur_line_id = tmp;
627-
}
628-
629-
set_fragment(prev_line_id + "-" + cur_line_id);
630-
} else {
631-
prev_line_id = cur_line_id;
632-
633-
set_fragment(cur_line_id);
634-
}
635-
};
636-
}());
637-
638-
document.addEventListener("click", function(ev) {
639-
var helpElem = getHelpElement(false);
640-
if (hasClass(ev.target, "help-button")) {
641-
displayHelp(true, ev);
642-
} else if (ev.target.tagName === "SPAN" && hasClass(ev.target.parentNode, "line-numbers")) {
643-
handleSourceHighlight(ev);
644-
} else if (helpElem && hasClass(helpElem, "hidden") === false) {
645-
var is_inside_help_popup = ev.target !== helpElem && helpElem.contains(ev.target);
646-
if (is_inside_help_popup === false) {
647-
addClass(helpElem, "hidden");
648-
removeClass(document.body, "blur");
649-
}
650-
} else {
651-
// Making a collapsed element visible on onhashchange seems
652-
// too late
653-
var a = findParentElement(ev.target, "A");
654-
if (a && a.hash) {
655-
expandSection(a.hash.replace(/^#/, ""));
656-
}
657-
}
658-
});
659-
660544
(function() {
661545
var x = document.getElementsByClassName("version-selector");
662546
if (x.length > 0) {
@@ -1121,6 +1005,27 @@ function hideThemeButtonState() {
11211005
});
11221006
}());
11231007

1008+
function handleClick(id, f) {
1009+
var elem = document.getElementById(id);
1010+
if (elem) {
1011+
elem.addEventListener("click", f);
1012+
}
1013+
}
1014+
handleClick("help-button", function(ev) {
1015+
displayHelp(true, ev);
1016+
});
1017+
1018+
onEachLazy(document.getElementsByTagName("a"), function(el) {
1019+
// For clicks on internal links (<A> tags with a hash property), we expand the section we're
1020+
// jumping to *before* jumping there. We can't do this in onHashChange, because it changes
1021+
// the height of the document so we wind up scrolled to the wrong place.
1022+
if (el.hash) {
1023+
el.addEventListener("click", function() {
1024+
expandSection(el.hash.slice(1));
1025+
});
1026+
}
1027+
});
1028+
11241029
onEachLazy(document.getElementsByClassName("notable-traits"), function(e) {
11251030
e.onclick = function() {
11261031
this.getElementsByClassName('notable-traits-tooltiptext')[0]
@@ -1165,6 +1070,13 @@ function hideThemeButtonState() {
11651070
addClass(popup, "hidden");
11661071
popup.id = "help";
11671072

1073+
popup.addEventListener("click", function(ev) {
1074+
if (ev.target === popup) {
1075+
// Clicked the blurred zone outside the help popup; dismiss help.
1076+
displayHelp(false, ev);
1077+
}
1078+
});
1079+
11681080
var book_info = document.createElement("span");
11691081
book_info.innerHTML = "You can find more information in \
11701082
<a href=\"https://doc.rust-lang.org/rustdoc/\">the rustdoc book</a>.";
@@ -1223,7 +1135,7 @@ function hideThemeButtonState() {
12231135
}
12241136

12251137
onHashChange(null);
1226-
window.onhashchange = onHashChange;
1138+
window.addEventListener("hashchange", onHashChange);
12271139
searchState.setup();
12281140
}());
12291141

src/librustdoc/html/static/rustdoc.css

+6-6
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ nav.sub {
371371
border: 1px solid;
372372
padding: 13px 8px;
373373
text-align: right;
374+
border-top-left-radius: 5px;
375+
border-bottom-left-radius: 5px;
374376
}
375377

376378
.rustdoc:not(.source) .example-wrap > pre.rust {
@@ -398,8 +400,6 @@ nav.sub {
398400
-moz-user-select: none;
399401
-ms-user-select: none;
400402
user-select: none;
401-
border-top-left-radius: 5px;
402-
border-bottom-left-radius: 5px;
403403
}
404404
.line-numbers span {
405405
cursor: pointer;
@@ -1289,7 +1289,7 @@ h4 > .notable-traits {
12891289
outline: none;
12901290
}
12911291

1292-
#settings-menu, .help-button {
1292+
#settings-menu, #help-button {
12931293
position: absolute;
12941294
top: 10px;
12951295
}
@@ -1299,7 +1299,7 @@ h4 > .notable-traits {
12991299
outline: none;
13001300
}
13011301

1302-
#theme-picker, #settings-menu, .help-button, #copy-path {
1302+
#theme-picker, #settings-menu, #help-button, #copy-path {
13031303
padding: 4px;
13041304
width: 27px;
13051305
height: 29px;
@@ -1308,7 +1308,7 @@ h4 > .notable-traits {
13081308
cursor: pointer;
13091309
}
13101310

1311-
.help-button {
1311+
#help-button {
13121312
right: 30px;
13131313
font-family: "Fira Sans", Arial, sans-serif;
13141314
text-align: center;
@@ -1593,7 +1593,7 @@ h4 > .notable-traits {
15931593
}
15941594

15951595
/* We don't display the help button on mobile devices. */
1596-
.help-button {
1596+
#help-button {
15971597
display: none;
15981598
}
15991599
.search-container > div {

0 commit comments

Comments
 (0)