Skip to content

Commit

Permalink
Rollup merge of rust-lang#88816 - dns2utf8:rustdoc_test_gui_2k_consta…
Browse files Browse the repository at this point in the history
…nts, r=GuillaumeGomez

Rustdoc migrate to table so the gui can handle >2k constants

Closes rust-lang#88545.

This PR adds a test for overlapping entries in the `item-table` rust-lang#88545
It currently includes the commit with the workaround from rust-lang#88776
  • Loading branch information
Manishearth committed Oct 5, 2021
2 parents b837cbf + e599e2d commit 117270d
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 22 deletions.
19 changes: 8 additions & 11 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ use crate::html::markdown::MarkdownSummaryLine;

const ITEM_TABLE_OPEN: &'static str = "<div class=\"item-table\">";
const ITEM_TABLE_CLOSE: &'static str = "</div>";
const ITEM_TABLE_ROW_OPEN: &'static str = "<div class=\"item-row\">";
const ITEM_TABLE_ROW_CLOSE: &'static str = "</div>";

pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer, page: &Page<'_>) {
debug_assert!(!item.is_stripped());
Expand Down Expand Up @@ -256,9 +258,6 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl

debug!("{:?}", indices);
let mut curty = None;
// See: https://github.com/rust-lang/rust/issues/88545
let item_table_block_size = 900usize;
let mut item_table_nth_element = 0usize;

for &idx in &indices {
let myitem = &items[idx];
Expand All @@ -285,13 +284,13 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
id = cx.derive_id(short.to_owned()),
name = name
);
item_table_nth_element = 0;
}

match *myitem.kind {
clean::ExternCrateItem { ref src } => {
use crate::html::format::anchor;

w.write_str(ITEM_TABLE_ROW_OPEN);
match *src {
Some(ref src) => write!(
w,
Expand All @@ -312,6 +311,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
),
}
w.write_str("</code></div>");
w.write_str(ITEM_TABLE_ROW_CLOSE);
}

clean::ImportItem(ref import) => {
Expand All @@ -336,6 +336,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl

let add = if stab.is_some() { " " } else { "" };

w.write_str(ITEM_TABLE_ROW_OPEN);
write!(
w,
"<div class=\"item-left {stab}{add}import-item\">\
Expand All @@ -348,6 +349,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
imp = import.print(cx),
stab_tags = stab_tags.unwrap_or_default(),
);
w.write_str(ITEM_TABLE_ROW_CLOSE);
}

_ => {
Expand All @@ -368,6 +370,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
let add = if stab.is_some() { " " } else { "" };

let doc_value = myitem.doc_value().unwrap_or_default();
w.write_str(ITEM_TABLE_ROW_OPEN);
write!(
w,
"<div class=\"item-left {stab}{add}module-item\">\
Expand All @@ -390,15 +393,9 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
.collect::<Vec<_>>()
.join(" "),
);
w.write_str(ITEM_TABLE_ROW_CLOSE);
}
}

item_table_nth_element += 1;
if item_table_nth_element > item_table_block_size {
w.write_str(ITEM_TABLE_CLOSE);
w.write_str(ITEM_TABLE_OPEN);
item_table_nth_element = 0;
}
}

if curty.is_some() {
Expand Down
19 changes: 9 additions & 10 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -773,22 +773,18 @@ h2.small-section-header > .anchor {
.block a.current.crate { font-weight: 500; }

.item-table {
display: grid;
column-gap: 1.2rem;
row-gap: 0.0rem;
grid-template-columns: auto 1fr;
display: table-row;
/* align content left */
justify-items: start;
}

.item-row {
display: table-row;
}
.item-left, .item-right {
display: block;
display: table-cell;
}
.item-left {
grid-column: 1;
}
.item-right {
grid-column: 2;
padding-right: 1.2rem;
}

.search-container {
Expand Down Expand Up @@ -1891,6 +1887,9 @@ details.undocumented[open] > summary::before {

/* Display an alternating layout on tablets and phones */
.item-table {
display: block;
}
.item-row {
display: flex;
flex-flow: column wrap;
}
Expand Down
5 changes: 5 additions & 0 deletions src/test/rustdoc-gui/huge-collection-of-constants.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
goto: file://|DOC_PATH|/test_docs/huge_amount_of_consts/index.html

// Make sure that the last two entries are more than 12 pixels apart and not stacked on each other.

compare-elements-position-near-false: ("//*[@class='item-table']//div[last()-1]", "//*[@class='item-table']//div[last()-3]", {"y": 12})
2 changes: 2 additions & 0 deletions src/test/rustdoc-gui/src/test_docs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ name = "test_docs"
version = "0.1.0"
edition = "2018"

build = "build.rs"

[lib]
path = "lib.rs"
15 changes: 15 additions & 0 deletions src/test/rustdoc-gui/src/test_docs/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! generate 2000 constants for testing

use std::{fs::write, path::PathBuf};

fn main() -> std::io::Result<()> {
let out_dir = std::env::var("OUT_DIR").expect("OUT_DIR is not defined");

let mut output = String::new();
for i in 0..2000 {
let line = format!("/// Some const A{0}\npub const A{0}: isize = 0;\n", i);
output.push_str(&*line);
};

write(&[&*out_dir, "huge_amount_of_consts.rs"].iter().collect::<PathBuf>(), output)
}
4 changes: 4 additions & 0 deletions src/test/rustdoc-gui/src/test_docs/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,7 @@ pub mod keyword {}

/// Just some type alias.
pub type SomeType = u32;

pub mod huge_amount_of_consts {
include!(concat!(env!("OUT_DIR"), "/huge_amount_of_consts.rs"));
}
2 changes: 1 addition & 1 deletion src/tools/rustdoc-gui/tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ async function main(argv) {
}
files.sort();

console.log(`Running ${files.length} rustdoc-gui tests...`);
console.log(`Running ${files.length} rustdoc-gui (${opts["jobs"]} concurrently) ...`);

if (opts["jobs"] < 1) {
process.setMaxListeners(files.length + 1);
Expand Down

0 comments on commit 117270d

Please sign in to comment.