Skip to content

Commit

Permalink
Auto merge of #85231 - GuillaumeGomez:rollup-hufe4gz, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed May 12, 2021
2 parents 28e2b29 + 7684247 commit 70e52ca
Show file tree
Hide file tree
Showing 18 changed files with 354 additions and 138 deletions.
46 changes: 45 additions & 1 deletion compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,37 @@ impl<'a> Parser<'a> {
Ok(a_var)
}

fn expect_field_ty_separator(&mut self) -> PResult<'a, ()> {
if let Err(mut err) = self.expect(&token::Colon) {
let sm = self.sess.source_map();
let eq_typo = self.token.kind == token::Eq && self.look_ahead(1, |t| t.is_path_start());
let semi_typo = self.token.kind == token::Semi
&& self.look_ahead(1, |t| {
t.is_path_start()
// We check that we are in a situation like `foo; bar` to avoid bad suggestions
// when there's no type and `;` was used instead of a comma.
&& match (sm.lookup_line(self.token.span.hi()), sm.lookup_line(t.span.lo())) {
(Ok(l), Ok(r)) => l.line == r.line,
_ => true,
}
});
if eq_typo || semi_typo {
self.bump();
// Gracefully handle small typos.
err.span_suggestion_short(
self.prev_token.span,
"field names and their types are separated with `:`",
":".to_string(),
Applicability::MachineApplicable,
);
err.emit();
} else {
return Err(err);
}
}
Ok(())
}

/// Parses a structure field.
fn parse_name_and_ty(
&mut self,
Expand All @@ -1408,8 +1439,21 @@ impl<'a> Parser<'a> {
attrs: Vec<Attribute>,
) -> PResult<'a, FieldDef> {
let name = self.parse_field_ident(adt_ty, lo)?;
self.expect(&token::Colon)?;
self.expect_field_ty_separator()?;
let ty = self.parse_ty()?;
if self.token.kind == token::Eq {
self.bump();
let const_expr = self.parse_anon_const_expr()?;
let sp = ty.span.shrink_to_hi().to(const_expr.value.span);
self.struct_span_err(sp, "default values on `struct` fields aren't supported")
.span_suggestion(
sp,
"remove this unsupported default value",
String::new(),
Applicability::MachineApplicable,
)
.emit();
}
Ok(FieldDef {
span: lo.to(self.prev_token.span),
ident: Some(name),
Expand Down
2 changes: 1 addition & 1 deletion src/doc/book
Submodule book updated 34 files
+2 −2 .github/workflows/main.yml
+1 −1 listings/ch02-guessing-game-tutorial/no-listing-02-without-expect/output.txt
+1 −0 listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/output.txt
+2 −2 listings/ch09-error-handling/no-listing-02-ask-compiler-for-type/output.txt
+1 −1 listings/ch11-writing-automated-tests/listing-11-01/output.txt
+1 −1 listings/ch11-writing-automated-tests/listing-11-03/output.txt
+1 −1 listings/ch11-writing-automated-tests/listing-11-06/output.txt
+1 −1 listings/ch11-writing-automated-tests/listing-11-07/output.txt
+1 −1 listings/ch11-writing-automated-tests/listing-11-08/output.txt
+1 −1 listings/ch11-writing-automated-tests/listing-11-10/output.txt
+1 −1 listings/ch11-writing-automated-tests/listing-11-11/output.txt
+2 −2 listings/ch11-writing-automated-tests/listing-11-13/output.txt
+1 −1 listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/output.txt
+1 −1 listings/ch11-writing-automated-tests/no-listing-02-adding-another-rectangle-test/output.txt
+1 −1 listings/ch11-writing-automated-tests/no-listing-03-introducing-a-bug/output.txt
+1 −1 listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt
+1 −1 listings/ch11-writing-automated-tests/no-listing-06-greeter-with-bug/output.txt
+1 −1 listings/ch11-writing-automated-tests/no-listing-07-custom-failure-message/output.txt
+1 −1 listings/ch11-writing-automated-tests/no-listing-08-guess-with-bug/output.txt
+1 −1 listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/output.txt
+1 −1 listings/ch11-writing-automated-tests/no-listing-11-ignore-a-test/output.txt
+3 −3 listings/ch11-writing-automated-tests/no-listing-12-shared-test-code-problem/output.txt
+1 −1 listings/ch11-writing-automated-tests/output-only-01-show-output/output.txt
+1 −1 listings/ch11-writing-automated-tests/output-only-02-single-test/output.txt
+1 −1 listings/ch11-writing-automated-tests/output-only-03-multiple-tests/output.txt
+1 −1 listings/ch11-writing-automated-tests/output-only-04-running-ignored/output.txt
+1 −1 listings/ch11-writing-automated-tests/output-only-05-single-integration/output.txt
+1 −1 listings/ch12-an-io-project/listing-12-12/output.txt
+4 −4 listings/ch15-smart-pointers/listing-15-15/output.txt
+3 −1 listings/ch18-patterns-and-matching/listing-18-10/output.txt
+1 −1 rust-toolchain
+1 −1 src/ch11-01-writing-tests.md
+1 −1 src/title-page.md
+3 −3 tools/update-rustc.sh
2 changes: 1 addition & 1 deletion src/doc/reference
2 changes: 1 addition & 1 deletion src/doc/rust-by-example
2 changes: 1 addition & 1 deletion src/doc/rustc-dev-guide
2 changes: 1 addition & 1 deletion src/librustdoc/html/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ crate fn render<T: Print, S: Print>(
placeholder=\"Click or press ‘S’ to search, ‘?’ for more options…\" \
type=\"search\">\
</div>\
<button type=\"button\" class=\"help-button\">?</button>
<button type=\"button\" id=\"help-button\">?</button>
<a id=\"settings-menu\" href=\"{root_path}settings.html\">\
<img src=\"{static_root_path}wheel{suffix}.svg\" \
width=\"18\" height=\"18\" \
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,7 @@ fn init_id_map() -> FxHashMap<String, usize> {
map.insert("theme-picker".to_owned(), 1);
map.insert("theme-choices".to_owned(), 1);
map.insert("settings-menu".to_owned(), 1);
map.insert("help-button".to_owned(), 1);
map.insert("main".to_owned(), 1);
map.insert("search".to_owned(), 1);
map.insert("crate-search".to_owned(), 1);
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/render/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ impl SharedContext<'_> {
Ok(())
}

/// Based on whether the `collapse-docs` pass was run, return either the `doc_value` or the
/// `collapsed_doc_value` of the given item.
/// Returns the `collapsed_doc_value` of the given item if this is the main crate, otherwise
/// returns the `doc_value`.
crate fn maybe_collapsed_doc_value<'a>(&self, item: &'a clean::Item) -> Option<String> {
if self.collapsed { item.collapsed_doc_value() } else { item.doc_value() }
}
Expand Down
146 changes: 29 additions & 117 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,56 +381,9 @@ function hideThemeButtonState() {
}
}

function highlightSourceLines(match, ev) {
if (typeof match === "undefined") {
// If we're in mobile mode, we should hide the sidebar in any case.
hideSidebar();
match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
}
if (!match) {
return;
}
var from = parseInt(match[1], 10);
var to = from;
if (typeof match[2] !== "undefined") {
to = parseInt(match[2], 10);
}
if (to < from) {
var tmp = to;
to = from;
from = tmp;
}
var elem = document.getElementById(from);
if (!elem) {
return;
}
if (!ev) {
var x = document.getElementById(from);
if (x) {
x.scrollIntoView();
}
}
onEachLazy(document.getElementsByClassName("line-numbers"), function(e) {
onEachLazy(e.getElementsByTagName("span"), function(i_e) {
removeClass(i_e, "line-highlighted");
});
});
for (var i = from; i <= to; ++i) {
elem = document.getElementById(i);
if (!elem) {
break;
}
addClass(elem, "line-highlighted");
}
}

function onHashChange(ev) {
// If we're in mobile mode, we should hide the sidebar in any case.
hideSidebar();
var match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
if (match) {
return highlightSourceLines(match, ev);
}
handleHashes(ev);
}

Expand Down Expand Up @@ -585,78 +538,9 @@ function hideThemeButtonState() {
}
}

function findParentElement(elem, tagName) {
do {
if (elem && elem.tagName === tagName) {
return elem;
}
elem = elem.parentNode;
} while (elem);
return null;
}

document.addEventListener("keypress", handleShortcut);
document.addEventListener("keydown", handleShortcut);

var handleSourceHighlight = (function() {
var prev_line_id = 0;

var set_fragment = function(name) {
var x = window.scrollX,
y = window.scrollY;
if (searchState.browserSupportsHistoryApi()) {
history.replaceState(null, null, "#" + name);
highlightSourceLines();
} else {
location.replace("#" + name);
}
// Prevent jumps when selecting one or many lines
window.scrollTo(x, y);
};

return function(ev) {
var cur_line_id = parseInt(ev.target.id, 10);
ev.preventDefault();

if (ev.shiftKey && prev_line_id) {
// Swap selection if needed
if (prev_line_id > cur_line_id) {
var tmp = prev_line_id;
prev_line_id = cur_line_id;
cur_line_id = tmp;
}

set_fragment(prev_line_id + "-" + cur_line_id);
} else {
prev_line_id = cur_line_id;

set_fragment(cur_line_id);
}
};
}());

document.addEventListener("click", function(ev) {
var helpElem = getHelpElement(false);
if (hasClass(ev.target, "help-button")) {
displayHelp(true, ev);
} else if (ev.target.tagName === "SPAN" && hasClass(ev.target.parentNode, "line-numbers")) {
handleSourceHighlight(ev);
} else if (helpElem && hasClass(helpElem, "hidden") === false) {
var is_inside_help_popup = ev.target !== helpElem && helpElem.contains(ev.target);
if (is_inside_help_popup === false) {
addClass(helpElem, "hidden");
removeClass(document.body, "blur");
}
} else {
// Making a collapsed element visible on onhashchange seems
// too late
var a = findParentElement(ev.target, "A");
if (a && a.hash) {
expandSection(a.hash.replace(/^#/, ""));
}
}
});

(function() {
var x = document.getElementsByClassName("version-selector");
if (x.length > 0) {
Expand Down Expand Up @@ -1121,6 +1005,27 @@ function hideThemeButtonState() {
});
}());

function handleClick(id, f) {
var elem = document.getElementById(id);
if (elem) {
elem.addEventListener("click", f);
}
}
handleClick("help-button", function(ev) {
displayHelp(true, ev);
});

onEachLazy(document.getElementsByTagName("a"), function(el) {
// For clicks on internal links (<A> tags with a hash property), we expand the section we're
// jumping to *before* jumping there. We can't do this in onHashChange, because it changes
// the height of the document so we wind up scrolled to the wrong place.
if (el.hash) {
el.addEventListener("click", function() {
expandSection(el.hash.slice(1));
});
}
});

onEachLazy(document.getElementsByClassName("notable-traits"), function(e) {
e.onclick = function() {
this.getElementsByClassName('notable-traits-tooltiptext')[0]
Expand Down Expand Up @@ -1165,6 +1070,13 @@ function hideThemeButtonState() {
addClass(popup, "hidden");
popup.id = "help";

popup.addEventListener("click", function(ev) {
if (ev.target === popup) {
// Clicked the blurred zone outside the help popup; dismiss help.
displayHelp(false, ev);
}
});

var book_info = document.createElement("span");
book_info.innerHTML = "You can find more information in \
<a href=\"https://doc.rust-lang.org/rustdoc/\">the rustdoc book</a>.";
Expand Down Expand Up @@ -1223,7 +1135,7 @@ function hideThemeButtonState() {
}

onHashChange(null);
window.onhashchange = onHashChange;
window.addEventListener("hashchange", onHashChange);
searchState.setup();
}());

Expand Down
12 changes: 6 additions & 6 deletions src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ nav.sub {
border: 1px solid;
padding: 13px 8px;
text-align: right;
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
}

.rustdoc:not(.source) .example-wrap > pre.rust {
Expand Down Expand Up @@ -398,8 +400,6 @@ nav.sub {
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
}
.line-numbers span {
cursor: pointer;
Expand Down Expand Up @@ -1289,7 +1289,7 @@ h4 > .notable-traits {
outline: none;
}

#settings-menu, .help-button {
#settings-menu, #help-button {
position: absolute;
top: 10px;
}
Expand All @@ -1299,7 +1299,7 @@ h4 > .notable-traits {
outline: none;
}

#theme-picker, #settings-menu, .help-button, #copy-path {
#theme-picker, #settings-menu, #help-button, #copy-path {
padding: 4px;
width: 27px;
height: 29px;
Expand All @@ -1308,7 +1308,7 @@ h4 > .notable-traits {
cursor: pointer;
}

.help-button {
#help-button {
right: 30px;
font-family: "Fira Sans", Arial, sans-serif;
text-align: center;
Expand Down Expand Up @@ -1593,7 +1593,7 @@ h4 > .notable-traits {
}

/* We don't display the help button on mobile devices. */
.help-button {
#help-button {
display: none;
}
.search-container > div {
Expand Down
Loading

0 comments on commit 70e52ca

Please sign in to comment.