Skip to content

Rollup of 7 pull requests #102329

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

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
475aeab
Improve code example for Option::unwrap_or_default
GuillaumeGomez Sep 25, 2022
a3e2314
create a new local var
TaKO8Ki Sep 26, 2022
63e5c93
add a label to struct/enum/union ident name
TaKO8Ki Sep 26, 2022
9d49d64
fix a ui test
TaKO8Ki Sep 26, 2022
1fe3ce4
rustdoc: remove unneeded CSS `td, th { padding 0 }`
notriddle Sep 26, 2022
9990444
rustdoc: merge `table { border-collapse } into `.docblock table`
notriddle Sep 26, 2022
4fad063
Document that Display entails ToString
sigaloid Sep 26, 2022
aac7429
Rustdoc-Json: List impls for primitives
aDotInTheVoid Sep 26, 2022
40f4044
rustdoc: Update doc comment for splitn_mut to include mutable in the …
yancyribbens Sep 26, 2022
0b97831
rustdoc: give `.line-number` / `.line-numbers` meaningful names
notriddle Sep 26, 2022
9ca2ae3
rustdoc: simplify example-line-numbers CSS selector
notriddle Sep 26, 2022
e096298
Rollup merge of #102283 - GuillaumeGomez:option-code-example-unwrap-o…
notriddle Sep 26, 2022
c455dac
Rollup merge of #102314 - TaKO8Ki:add-label-to-struct-enum-union-iden…
notriddle Sep 26, 2022
76e894a
Rollup merge of #102319 - notriddle:notriddle/td-th, r=GuillaumeGomez
notriddle Sep 26, 2022
a97f73c
Rollup merge of #102321 - aDotInTheVoid:rdj-prim-impls, r=GuillaumeGomez
notriddle Sep 26, 2022
6e8cbe2
Rollup merge of #102322 - sigaloid:master, r=GuillaumeGomez
notriddle Sep 26, 2022
cabfddf
Rollup merge of #102325 - notriddle:notriddle/line-number, r=Guillaum…
notriddle Sep 26, 2022
5ee831c
Rollup merge of #102326 - yancyribbens:splin-mut-doc-change, r=thomcc
notriddle Sep 26, 2022
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
44 changes: 29 additions & 15 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1283,12 +1283,10 @@ impl<'a> Parser<'a> {
/// Parses an enum declaration.
fn parse_item_enum(&mut self) -> PResult<'a, ItemInfo> {
if self.token.is_keyword(kw::Struct) {
let mut err = self.struct_span_err(
self.prev_token.span.to(self.token.span),
"`enum` and `struct` are mutually exclusive",
);
let span = self.prev_token.span.to(self.token.span);
let mut err = self.struct_span_err(span, "`enum` and `struct` are mutually exclusive");
err.span_suggestion(
self.prev_token.span.to(self.token.span),
span,
"replace `enum struct` with",
"enum",
Applicability::MachineApplicable,
Expand All @@ -1307,7 +1305,8 @@ impl<'a> Parser<'a> {

let (variants, _) = self
.parse_delim_comma_seq(Delimiter::Brace, |p| p.parse_enum_variant())
.map_err(|e| {
.map_err(|mut e| {
e.span_label(id.span, "while parsing this enum");
self.recover_stmt();
e
})?;
Expand All @@ -1332,7 +1331,8 @@ impl<'a> Parser<'a> {

let struct_def = if this.check(&token::OpenDelim(Delimiter::Brace)) {
// Parse a struct variant.
let (fields, recovered) = this.parse_record_struct_body("struct", false)?;
let (fields, recovered) =
this.parse_record_struct_body("struct", ident.span, false)?;
VariantData::Struct(fields, recovered)
} else if this.check(&token::OpenDelim(Delimiter::Parenthesis)) {
VariantData::Tuple(this.parse_tuple_struct_body()?, DUMMY_NODE_ID)
Expand Down Expand Up @@ -1386,17 +1386,23 @@ impl<'a> Parser<'a> {
VariantData::Unit(DUMMY_NODE_ID)
} else {
// If we see: `struct Foo<T> where T: Copy { ... }`
let (fields, recovered) =
self.parse_record_struct_body("struct", generics.where_clause.has_where_token)?;
let (fields, recovered) = self.parse_record_struct_body(
"struct",
class_name.span,
generics.where_clause.has_where_token,
)?;
VariantData::Struct(fields, recovered)
}
// No `where` so: `struct Foo<T>;`
} else if self.eat(&token::Semi) {
VariantData::Unit(DUMMY_NODE_ID)
// Record-style struct definition
} else if self.token == token::OpenDelim(Delimiter::Brace) {
let (fields, recovered) =
self.parse_record_struct_body("struct", generics.where_clause.has_where_token)?;
let (fields, recovered) = self.parse_record_struct_body(
"struct",
class_name.span,
generics.where_clause.has_where_token,
)?;
VariantData::Struct(fields, recovered)
// Tuple-style struct definition with optional where-clause.
} else if self.token == token::OpenDelim(Delimiter::Parenthesis) {
Expand Down Expand Up @@ -1425,12 +1431,18 @@ impl<'a> Parser<'a> {

let vdata = if self.token.is_keyword(kw::Where) {
generics.where_clause = self.parse_where_clause()?;
let (fields, recovered) =
self.parse_record_struct_body("union", generics.where_clause.has_where_token)?;
let (fields, recovered) = self.parse_record_struct_body(
"union",
class_name.span,
generics.where_clause.has_where_token,
)?;
VariantData::Struct(fields, recovered)
} else if self.token == token::OpenDelim(Delimiter::Brace) {
let (fields, recovered) =
self.parse_record_struct_body("union", generics.where_clause.has_where_token)?;
let (fields, recovered) = self.parse_record_struct_body(
"union",
class_name.span,
generics.where_clause.has_where_token,
)?;
VariantData::Struct(fields, recovered)
} else {
let token_str = super::token_descr(&self.token);
Expand All @@ -1446,6 +1458,7 @@ impl<'a> Parser<'a> {
fn parse_record_struct_body(
&mut self,
adt_ty: &str,
ident_span: Span,
parsed_where: bool,
) -> PResult<'a, (Vec<FieldDef>, /* recovered */ bool)> {
let mut fields = Vec::new();
Expand All @@ -1460,6 +1473,7 @@ impl<'a> Parser<'a> {
match field {
Ok(field) => fields.push(field),
Err(mut err) => {
err.span_label(ident_span, format!("while parsing this {adt_ty}"));
err.emit();
break;
}
Expand Down
7 changes: 7 additions & 0 deletions library/core/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,12 +709,19 @@ pub use macros::Debug;

/// Format trait for an empty format, `{}`.
///
/// Implementing this trait for a type will automatically implement the
/// [`ToString`][tostring] trait for the type, allowing the usage
/// of the [`.to_string()`][tostring_function] method. Prefer implementing
/// the `Display` trait for a type, rather than [`ToString`][tostring].
///
/// `Display` is similar to [`Debug`], but `Display` is for user-facing
/// output, and so cannot be derived.
///
/// For more information on formatters, see [the module-level documentation][module].
///
/// [module]: ../../std/fmt/index.html
/// [tostring]: ../../std/string/trait.ToString.html
/// [tostring_function]: ../../std/string/trait.ToString.html#tymethod.to_string
///
/// # Examples
///
Expand Down
16 changes: 4 additions & 12 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,20 +834,12 @@ impl<T> Option<T> {
///
/// # Examples
///
/// Converts a string to an integer, turning poorly-formed strings
/// into 0 (the default value for integers). [`parse`] converts
/// a string to any other type that implements [`FromStr`], returning
/// [`None`] on error.
///
/// ```
/// let good_year_from_input = "1909";
/// let bad_year_from_input = "190blarg";
/// // Result::ok() converts a Result<T> to an Option<T>
/// let good_year = good_year_from_input.parse().ok().unwrap_or_default();
/// let bad_year = bad_year_from_input.parse().ok().unwrap_or_default();
/// let x: Option<u32> = None;
/// let y: Option<u32> = Some(12);
///
/// assert_eq!(1909, good_year);
/// assert_eq!(0, bad_year);
/// assert_eq!(x.unwrap_or_default(), 0);
/// assert_eq!(y.unwrap_or_default(), 12);
/// ```
///
/// [default value]: Default::default
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2076,7 +2076,7 @@ impl<T> [T] {
SplitN::new(self.split(pred), n)
}

/// Returns an iterator over subslices separated by elements that match
/// Returns an iterator over mutable subslices separated by elements that match
/// `pred`, limited to returning at most `n` items. The matched element is
/// not contained in the subslices.
///
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ pub(crate) fn print_src(
) {
let lines = s.lines().count();
let mut line_numbers = Buffer::empty_from(buf);
line_numbers.write_str("<pre class=\"line-numbers\">");
line_numbers.write_str("<pre class=\"src-line-numbers\">");
match source_context {
SourceContext::Standalone => {
for line in 1..=lines {
Expand Down
28 changes: 10 additions & 18 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,6 @@ summary {

/* Fix some style changes due to normalize.css 8 */

td,
th {
padding: 0;
}

table {
border-collapse: collapse;
}

button,
input,
optgroup,
Expand Down Expand Up @@ -578,7 +569,7 @@ h2.location a {
position: relative;
}

.example-wrap > pre.line-number {
pre.example-line-numbers {
overflow: initial;
border: 1px solid;
padding: 13px 8px;
Expand All @@ -591,15 +582,15 @@ h2.location a {
text-decoration: underline;
}

.line-numbers {
.src-line-numbers {
text-align: right;
}
.rustdoc:not(.source) .example-wrap > pre:not(.line-number) {
.rustdoc:not(.source) .example-wrap > pre:not(.example-line-numbers) {
width: 100%;
overflow-x: auto;
}

.rustdoc:not(.source) .example-wrap > pre.line-numbers {
.rustdoc:not(.source) .example-wrap > pre.src-line-numbers {
width: auto;
overflow-x: visible;
}
Expand All @@ -612,14 +603,14 @@ h2.location a {
text-align: center;
}

.content > .example-wrap pre.line-numbers {
.content > .example-wrap pre.src-line-numbers {
position: relative;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.line-numbers span {
.src-line-numbers span {
cursor: pointer;
}

Expand Down Expand Up @@ -695,6 +686,7 @@ pre, .rustdoc.source .example-wrap {
width: calc(100% - 2px);
overflow-x: auto;
display: block;
border-collapse: collapse;
}

.docblock table td {
Expand Down Expand Up @@ -2067,7 +2059,7 @@ in storage.js plus the media query with (min-width: 701px)
padding-bottom: 0;
}

.scraped-example:not(.expanded) .code-wrapper pre.line-numbers {
.scraped-example:not(.expanded) .code-wrapper pre.src-line-numbers {
overflow-x: hidden;
}

Expand Down Expand Up @@ -2113,12 +2105,12 @@ in storage.js plus the media query with (min-width: 701px)
bottom: 0;
}

.scraped-example .code-wrapper .line-numbers {
.scraped-example .code-wrapper .src-line-numbers {
margin: 0;
padding: 14px 0;
}

.scraped-example .code-wrapper .line-numbers span {
.scraped-example .code-wrapper .src-line-numbers span {
padding: 0 14px;
}

Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/html/static/css/themes/ayu.css
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ pre, .rustdoc.source .example-wrap {
color: #ff7733;
}

.line-numbers span { color: #5c6773; }
.line-numbers .line-highlighted {
.src-line-numbers span { color: #5c6773; }
.src-line-numbers .line-highlighted {
color: #708090;
background-color: rgba(255, 236, 164, 0.06);
padding-right: 4px;
Expand Down Expand Up @@ -171,7 +171,7 @@ details.rustdoc-toggle > summary::before {
color: #788797;
}

.line-numbers :target { background-color: transparent; }
.src-line-numbers :target { background-color: transparent; }

/* Code highlighting */
pre.rust .number, pre.rust .string { color: #b8cc52; }
Expand All @@ -190,7 +190,7 @@ pre.rust .attribute {
color: #e6e1cf;
}

.example-wrap > pre.line-number {
pre.example-line-numbers {
color: #5c67736e;
border: none;
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/html/static/css/themes/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ input:focus + .slider {
background: #444;
}

.line-numbers span { color: #3B91E2; }
.line-numbers .line-highlighted {
.src-line-numbers span { color: #3B91E2; }
.src-line-numbers .line-highlighted {
background-color: #0a042f !important;
}

Expand Down Expand Up @@ -141,7 +141,7 @@ details.rustdoc-toggle > summary::before {
background: none;
}

.line-numbers :target { background-color: transparent; }
.src-line-numbers :target { background-color: transparent; }

/* Code highlighting */
pre.rust .kw { color: #ab8ac1; }
Expand All @@ -155,7 +155,7 @@ pre.rust .question-mark {
color: #ff9011;
}

.example-wrap > pre.line-number {
pre.example-line-numbers {
border-color: #4a4949;
}

Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/html/static/css/themes/light.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ input:focus + .slider {
background-color: #fff;
}

.line-numbers span { color: #c67e2d; }
.line-numbers .line-highlighted {
.src-line-numbers span { color: #c67e2d; }
.src-line-numbers .line-highlighted {
background-color: #FDFFD3 !important;
}

Expand Down Expand Up @@ -125,7 +125,7 @@ body.source .example-wrap pre.rust a {
.stab { background: #FFF5D6; border-color: #FFC600; }
.stab.portability > code { background: none; }

.line-numbers :target { background-color: transparent; }
.src-line-numbers :target { background-color: transparent; }

/* Code highlighting */
pre.rust .kw { color: #8959A8; }
Expand All @@ -141,7 +141,7 @@ pre.rust .question-mark {
color: #ff9011;
}

.example-wrap > pre.line-number {
pre.example-line-numbers {
border-color: #c7c7c7;
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ function loadCss(cssFileName) {
window.rustdoc_add_line_numbers_to_examples = () => {
onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => {
const parent = x.parentNode;
const line_numbers = parent.querySelectorAll(".line-number");
const line_numbers = parent.querySelectorAll(".example-line-numbers");
if (line_numbers.length > 0) {
return;
}
Expand All @@ -709,7 +709,7 @@ function loadCss(cssFileName) {
elems.push(i + 1);
}
const node = document.createElement("pre");
addClass(node, "line-number");
addClass(node, "example-line-numbers");
node.innerHTML = elems.join("\n");
parent.insertBefore(node, x);
});
Expand All @@ -718,7 +718,7 @@ function loadCss(cssFileName) {
window.rustdoc_remove_line_numbers_from_examples = () => {
onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => {
const parent = x.parentNode;
const line_numbers = parent.querySelectorAll(".line-number");
const line_numbers = parent.querySelectorAll(".example-line-numbers");
for (const node of line_numbers) {
parent.removeChild(node);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/static/js/scrape-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

// Scroll code block to the given code location
function scrollToLoc(elt, loc) {
const lines = elt.querySelector(".line-numbers");
const lines = elt.querySelector(".src-line-numbers");
let scrollOffset;

// If the block is greater than the size of the viewer,
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/static/js/source-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function highlightSourceLines(match) {
if (x) {
x.scrollIntoView();
}
onEachLazy(document.getElementsByClassName("line-numbers"), e => {
onEachLazy(document.getElementsByClassName("src-line-numbers"), e => {
onEachLazy(e.getElementsByTagName("span"), i_e => {
removeClass(i_e, "line-highlighted");
});
Expand Down Expand Up @@ -245,7 +245,7 @@ window.addEventListener("hashchange", () => {
}
});

onEachLazy(document.getElementsByClassName("line-numbers"), el => {
onEachLazy(document.getElementsByClassName("src-line-numbers"), el => {
el.addEventListener("click", handleSourceHighlight);
});

Expand Down
Loading