Skip to content

Commit

Permalink
Auto merge of #102331 - notriddle:rollup-dmefd2d, r=notriddle
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Sep 27, 2022
2 parents f3a6fbf + 7381d7d commit cd4d9d9
Show file tree
Hide file tree
Showing 23 changed files with 116 additions and 70 deletions.
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
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
7 changes: 6 additions & 1 deletion src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,12 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
ConstantItem(c) => ItemEnum::Constant(c.into_tcx(tcx)),
MacroItem(m) => ItemEnum::Macro(m.source),
ProcMacroItem(m) => ItemEnum::ProcMacro(m.into_tcx(tcx)),
PrimitiveItem(p) => ItemEnum::PrimitiveType(p.as_sym().to_string()),
PrimitiveItem(p) => {
ItemEnum::Primitive(Primitive {
name: p.as_sym().to_string(),
impls: Vec::new(), // Added in JsonRenderer::item
})
}
TyAssocConstItem(ty) => ItemEnum::AssocConst { type_: ty.into_tcx(tcx), default: None },
AssocConstItem(ty, default) => {
ItemEnum::AssocConst { type_: ty.into_tcx(tcx), default: Some(default.expr(tcx)) }
Expand Down
7 changes: 5 additions & 2 deletions src/librustdoc/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,15 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
u.impls = self.get_impls(item_id.expect_def_id());
false
}
types::ItemEnum::Primitive(ref mut p) => {
p.impls = self.get_impls(item_id.expect_def_id());
false
}

types::ItemEnum::Method(_)
| types::ItemEnum::Module(_)
| types::ItemEnum::AssocConst { .. }
| types::ItemEnum::AssocType { .. }
| types::ItemEnum::PrimitiveType(_) => true,
| types::ItemEnum::AssocType { .. } => true,
types::ItemEnum::ExternCrate { .. }
| types::ItemEnum::Import(_)
| types::ItemEnum::StructField(_)
Expand Down
10 changes: 8 additions & 2 deletions src/rustdoc-json-types/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::path::PathBuf;
use serde::{Deserialize, Serialize};

/// rustdoc format-version.
pub const FORMAT_VERSION: u32 = 21;
pub const FORMAT_VERSION: u32 = 22;

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

PrimitiveType(String),
Primitive(Primitive),

AssocConst {
#[serde(rename = "type")]
Expand Down Expand Up @@ -709,5 +709,11 @@ pub struct Static {
pub expr: String,
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Primitive {
pub name: String,
pub impls: Vec<Id>,
}

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Scraped example should only include line numbers for items b and c in ex.rs
// @!has foobar/fn.f.html '//*[@class="line-numbers"]' '14'
// @has foobar/fn.f.html '//*[@class="line-numbers"]' '15'
// @has foobar/fn.f.html '//*[@class="line-numbers"]' '21'
// @!has foobar/fn.f.html '//*[@class="line-numbers"]' '22'
// @!has foobar/fn.f.html '//*[@class="src-line-numbers"]' '14'
// @has foobar/fn.f.html '//*[@class="src-line-numbers"]' '15'
// @has foobar/fn.f.html '//*[@class="src-line-numbers"]' '21'
// @!has foobar/fn.f.html '//*[@class="src-line-numbers"]' '22'

pub fn f() {}

Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-gui/basic-code.goml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
goto: file://|DOC_PATH|/test_docs/index.html
click: ".srclink"
assert-count: (".line-numbers", 1)
assert-count: (".src-line-numbers", 1)
12 changes: 6 additions & 6 deletions src/test/rustdoc-gui/docblock-code-block-line-number.goml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
goto: file://|DOC_PATH|/test_docs/fn.foo.html

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

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

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

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

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

0 comments on commit cd4d9d9

Please sign in to comment.