Skip to content

Commit cd4d9d9

Browse files
committed
Auto merge of #102331 - notriddle:rollup-dmefd2d, r=notriddle
Rollup of 6 pull requests Successful merges: - #102283 (Improve code example for Option::unwrap_or_default) - #102319 (rustdoc: merge CSS `table` rules into `.docblock`) - #102321 ( Rustdoc-Json: List impls for primitives) - #102322 (Document that Display automatically implements ToString) - #102325 (rustdoc: give `.line-number` / `.line-numbers` meaningful names) - #102326 (rustdoc: Update doc comment for splitn_mut to include mutable in the …) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents f3a6fbf + 7381d7d commit cd4d9d9

File tree

23 files changed

+116
-70
lines changed

23 files changed

+116
-70
lines changed

Diff for: library/core/src/fmt/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -709,12 +709,19 @@ pub use macros::Debug;
709709

710710
/// Format trait for an empty format, `{}`.
711711
///
712+
/// Implementing this trait for a type will automatically implement the
713+
/// [`ToString`][tostring] trait for the type, allowing the usage
714+
/// of the [`.to_string()`][tostring_function] method. Prefer implementing
715+
/// the `Display` trait for a type, rather than [`ToString`][tostring].
716+
///
712717
/// `Display` is similar to [`Debug`], but `Display` is for user-facing
713718
/// output, and so cannot be derived.
714719
///
715720
/// For more information on formatters, see [the module-level documentation][module].
716721
///
717722
/// [module]: ../../std/fmt/index.html
723+
/// [tostring]: ../../std/string/trait.ToString.html
724+
/// [tostring_function]: ../../std/string/trait.ToString.html#tymethod.to_string
718725
///
719726
/// # Examples
720727
///

Diff for: library/core/src/slice/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2076,7 +2076,7 @@ impl<T> [T] {
20762076
SplitN::new(self.split(pred), n)
20772077
}
20782078

2079-
/// Returns an iterator over subslices separated by elements that match
2079+
/// Returns an iterator over mutable subslices separated by elements that match
20802080
/// `pred`, limited to returning at most `n` items. The matched element is
20812081
/// not contained in the subslices.
20822082
///

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ pub(crate) fn print_src(
274274
) {
275275
let lines = s.lines().count();
276276
let mut line_numbers = Buffer::empty_from(buf);
277-
line_numbers.write_str("<pre class=\"line-numbers\">");
277+
line_numbers.write_str("<pre class=\"src-line-numbers\">");
278278
match source_context {
279279
SourceContext::Standalone => {
280280
for line in 1..=lines {

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

+10-18
Original file line numberDiff line numberDiff line change
@@ -299,15 +299,6 @@ summary {
299299

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

302-
td,
303-
th {
304-
padding: 0;
305-
}
306-
307-
table {
308-
border-collapse: collapse;
309-
}
310-
311302
button,
312303
input,
313304
optgroup,
@@ -578,7 +569,7 @@ h2.location a {
578569
position: relative;
579570
}
580571

581-
.example-wrap > pre.line-number {
572+
pre.example-line-numbers {
582573
overflow: initial;
583574
border: 1px solid;
584575
padding: 13px 8px;
@@ -591,15 +582,15 @@ h2.location a {
591582
text-decoration: underline;
592583
}
593584

594-
.line-numbers {
585+
.src-line-numbers {
595586
text-align: right;
596587
}
597-
.rustdoc:not(.source) .example-wrap > pre:not(.line-number) {
588+
.rustdoc:not(.source) .example-wrap > pre:not(.example-line-numbers) {
598589
width: 100%;
599590
overflow-x: auto;
600591
}
601592

602-
.rustdoc:not(.source) .example-wrap > pre.line-numbers {
593+
.rustdoc:not(.source) .example-wrap > pre.src-line-numbers {
603594
width: auto;
604595
overflow-x: visible;
605596
}
@@ -612,14 +603,14 @@ h2.location a {
612603
text-align: center;
613604
}
614605

615-
.content > .example-wrap pre.line-numbers {
606+
.content > .example-wrap pre.src-line-numbers {
616607
position: relative;
617608
-webkit-user-select: none;
618609
-moz-user-select: none;
619610
-ms-user-select: none;
620611
user-select: none;
621612
}
622-
.line-numbers span {
613+
.src-line-numbers span {
623614
cursor: pointer;
624615
}
625616

@@ -695,6 +686,7 @@ pre, .rustdoc.source .example-wrap {
695686
width: calc(100% - 2px);
696687
overflow-x: auto;
697688
display: block;
689+
border-collapse: collapse;
698690
}
699691

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

2070-
.scraped-example:not(.expanded) .code-wrapper pre.line-numbers {
2062+
.scraped-example:not(.expanded) .code-wrapper pre.src-line-numbers {
20712063
overflow-x: hidden;
20722064
}
20732065

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

2116-
.scraped-example .code-wrapper .line-numbers {
2108+
.scraped-example .code-wrapper .src-line-numbers {
21172109
margin: 0;
21182110
padding: 14px 0;
21192111
}
21202112

2121-
.scraped-example .code-wrapper .line-numbers span {
2113+
.scraped-example .code-wrapper .src-line-numbers span {
21222114
padding: 0 14px;
21232115
}
21242116

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ pre, .rustdoc.source .example-wrap {
9393
color: #ff7733;
9494
}
9595

96-
.line-numbers span { color: #5c6773; }
97-
.line-numbers .line-highlighted {
96+
.src-line-numbers span { color: #5c6773; }
97+
.src-line-numbers .line-highlighted {
9898
color: #708090;
9999
background-color: rgba(255, 236, 164, 0.06);
100100
padding-right: 4px;
@@ -171,7 +171,7 @@ details.rustdoc-toggle > summary::before {
171171
color: #788797;
172172
}
173173

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

176176
/* Code highlighting */
177177
pre.rust .number, pre.rust .string { color: #b8cc52; }
@@ -190,7 +190,7 @@ pre.rust .attribute {
190190
color: #e6e1cf;
191191
}
192192

193-
.example-wrap > pre.line-number {
193+
pre.example-line-numbers {
194194
color: #5c67736e;
195195
border: none;
196196
}

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ input:focus + .slider {
5454
background: #444;
5555
}
5656

57-
.line-numbers span { color: #3B91E2; }
58-
.line-numbers .line-highlighted {
57+
.src-line-numbers span { color: #3B91E2; }
58+
.src-line-numbers .line-highlighted {
5959
background-color: #0a042f !important;
6060
}
6161

@@ -141,7 +141,7 @@ details.rustdoc-toggle > summary::before {
141141
background: none;
142142
}
143143

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

146146
/* Code highlighting */
147147
pre.rust .kw { color: #ab8ac1; }
@@ -155,7 +155,7 @@ pre.rust .question-mark {
155155
color: #ff9011;
156156
}
157157

158-
.example-wrap > pre.line-number {
158+
pre.example-line-numbers {
159159
border-color: #4a4949;
160160
}
161161

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ input:focus + .slider {
5353
background-color: #fff;
5454
}
5555

56-
.line-numbers span { color: #c67e2d; }
57-
.line-numbers .line-highlighted {
56+
.src-line-numbers span { color: #c67e2d; }
57+
.src-line-numbers .line-highlighted {
5858
background-color: #FDFFD3 !important;
5959
}
6060

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

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

130130
/* Code highlighting */
131131
pre.rust .kw { color: #8959A8; }
@@ -141,7 +141,7 @@ pre.rust .question-mark {
141141
color: #ff9011;
142142
}
143143

144-
.example-wrap > pre.line-number {
144+
pre.example-line-numbers {
145145
border-color: #c7c7c7;
146146
}
147147

Diff for: src/librustdoc/html/static/js/main.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ function loadCss(cssFileName) {
699699
window.rustdoc_add_line_numbers_to_examples = () => {
700700
onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => {
701701
const parent = x.parentNode;
702-
const line_numbers = parent.querySelectorAll(".line-number");
702+
const line_numbers = parent.querySelectorAll(".example-line-numbers");
703703
if (line_numbers.length > 0) {
704704
return;
705705
}
@@ -709,7 +709,7 @@ function loadCss(cssFileName) {
709709
elems.push(i + 1);
710710
}
711711
const node = document.createElement("pre");
712-
addClass(node, "line-number");
712+
addClass(node, "example-line-numbers");
713713
node.innerHTML = elems.join("\n");
714714
parent.insertBefore(node, x);
715715
});
@@ -718,7 +718,7 @@ function loadCss(cssFileName) {
718718
window.rustdoc_remove_line_numbers_from_examples = () => {
719719
onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => {
720720
const parent = x.parentNode;
721-
const line_numbers = parent.querySelectorAll(".line-number");
721+
const line_numbers = parent.querySelectorAll(".example-line-numbers");
722722
for (const node of line_numbers) {
723723
parent.removeChild(node);
724724
}

Diff for: src/librustdoc/html/static/js/scrape-examples.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

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

1414
// If the block is greater than the size of the viewer,

Diff for: src/librustdoc/html/static/js/source-script.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ function highlightSourceLines(match) {
183183
if (x) {
184184
x.scrollIntoView();
185185
}
186-
onEachLazy(document.getElementsByClassName("line-numbers"), e => {
186+
onEachLazy(document.getElementsByClassName("src-line-numbers"), e => {
187187
onEachLazy(e.getElementsByTagName("span"), i_e => {
188188
removeClass(i_e, "line-highlighted");
189189
});
@@ -245,7 +245,7 @@ window.addEventListener("hashchange", () => {
245245
}
246246
});
247247

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

Diff for: src/librustdoc/json/conversions.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,12 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
272272
ConstantItem(c) => ItemEnum::Constant(c.into_tcx(tcx)),
273273
MacroItem(m) => ItemEnum::Macro(m.source),
274274
ProcMacroItem(m) => ItemEnum::ProcMacro(m.into_tcx(tcx)),
275-
PrimitiveItem(p) => ItemEnum::PrimitiveType(p.as_sym().to_string()),
275+
PrimitiveItem(p) => {
276+
ItemEnum::Primitive(Primitive {
277+
name: p.as_sym().to_string(),
278+
impls: Vec::new(), // Added in JsonRenderer::item
279+
})
280+
}
276281
TyAssocConstItem(ty) => ItemEnum::AssocConst { type_: ty.into_tcx(tcx), default: None },
277282
AssocConstItem(ty, default) => {
278283
ItemEnum::AssocConst { type_: ty.into_tcx(tcx), default: Some(default.expr(tcx)) }

Diff for: src/librustdoc/json/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,15 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
219219
u.impls = self.get_impls(item_id.expect_def_id());
220220
false
221221
}
222+
types::ItemEnum::Primitive(ref mut p) => {
223+
p.impls = self.get_impls(item_id.expect_def_id());
224+
false
225+
}
222226

223227
types::ItemEnum::Method(_)
224228
| types::ItemEnum::Module(_)
225229
| types::ItemEnum::AssocConst { .. }
226-
| types::ItemEnum::AssocType { .. }
227-
| types::ItemEnum::PrimitiveType(_) => true,
230+
| types::ItemEnum::AssocType { .. } => true,
228231
types::ItemEnum::ExternCrate { .. }
229232
| types::ItemEnum::Import(_)
230233
| types::ItemEnum::StructField(_)

Diff for: src/rustdoc-json-types/lib.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::path::PathBuf;
99
use serde::{Deserialize, Serialize};
1010

1111
/// rustdoc format-version.
12-
pub const FORMAT_VERSION: u32 = 21;
12+
pub const FORMAT_VERSION: u32 = 22;
1313

1414
/// A `Crate` is the root of the emitted JSON blob. It contains all type/documentation information
1515
/// about the language items in the local crate, as well as info about external items to allow
@@ -254,7 +254,7 @@ pub enum ItemEnum {
254254
Macro(String),
255255
ProcMacro(ProcMacro),
256256

257-
PrimitiveType(String),
257+
Primitive(Primitive),
258258

259259
AssocConst {
260260
#[serde(rename = "type")]
@@ -709,5 +709,11 @@ pub struct Static {
709709
pub expr: String,
710710
}
711711

712+
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
713+
pub struct Primitive {
714+
pub name: String,
715+
pub impls: Vec<Id>,
716+
}
717+
712718
#[cfg(test)]
713719
mod tests;

Diff for: src/test/run-make-fulldeps/rustdoc-scrape-examples-macros/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Scraped example should only include line numbers for items b and c in ex.rs
2-
// @!has foobar/fn.f.html '//*[@class="line-numbers"]' '14'
3-
// @has foobar/fn.f.html '//*[@class="line-numbers"]' '15'
4-
// @has foobar/fn.f.html '//*[@class="line-numbers"]' '21'
5-
// @!has foobar/fn.f.html '//*[@class="line-numbers"]' '22'
2+
// @!has foobar/fn.f.html '//*[@class="src-line-numbers"]' '14'
3+
// @has foobar/fn.f.html '//*[@class="src-line-numbers"]' '15'
4+
// @has foobar/fn.f.html '//*[@class="src-line-numbers"]' '21'
5+
// @!has foobar/fn.f.html '//*[@class="src-line-numbers"]' '22'
66

77
pub fn f() {}
88

Diff for: src/test/rustdoc-gui/basic-code.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
goto: file://|DOC_PATH|/test_docs/index.html
22
click: ".srclink"
3-
assert-count: (".line-numbers", 1)
3+
assert-count: (".src-line-numbers", 1)

Diff for: src/test/rustdoc-gui/docblock-code-block-line-number.goml

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22
goto: file://|DOC_PATH|/test_docs/fn.foo.html
33

44
// We check that without this setting, there is no line number displayed.
5-
assert-false: "pre.line-number"
5+
assert-false: "pre.example-line-numbers"
66

77
// We now set the setting to show the line numbers on code examples.
88
local-storage: {"rustdoc-line-numbers": "true" }
99
// We reload to make the line numbers appear.
1010
reload:
1111

1212
// We wait for them to be added into the DOM by the JS...
13-
wait-for: "pre.line-number"
13+
wait-for: "pre.example-line-numbers"
1414
// If the test didn't fail, it means that it was found!
1515
// Let's now check some CSS properties...
16-
assert-css: ("pre.line-number", {
16+
assert-css: ("pre.example-line-numbers", {
1717
"margin": "0px",
1818
"padding": "13px 8px",
1919
"text-align": "right",
2020
})
2121
// The first code block has two lines so let's check its `<pre>` elements lists both of them.
22-
assert-text: ("pre.line-number", "1\n2")
22+
assert-text: ("pre.example-line-numbers", "1\n2")
2323

2424
// Now, try changing the setting dynamically. We'll turn it off, using the settings menu,
2525
// and make sure it goes away.
@@ -32,8 +32,8 @@ assert-css: ("#settings", {"display": "block"})
3232
// Then, click the toggle button.
3333
click: "input#line-numbers + .slider"
3434
wait-for: 100 // wait-for-false does not exist
35-
assert-false: "pre.line-number"
35+
assert-false: "pre.example-line-numbers"
3636

3737
// Finally, turn it on again.
3838
click: "input#line-numbers + .slider"
39-
wait-for: "pre.line-number"
39+
wait-for: "pre.example-line-numbers"

0 commit comments

Comments
 (0)