Skip to content

Commit 52d3afa

Browse files
authored
Rollup merge of #88816 - dns2utf8:rustdoc_test_gui_2k_constants, r=GuillaumeGomez
Rustdoc migrate to table so the gui can handle >2k constants Closes #88545. This PR adds a test for overlapping entries in the `item-table` #88545 It currently includes the commit with the workaround from #88776
2 parents dd223d5 + e599e2d commit 52d3afa

File tree

7 files changed

+44
-22
lines changed

7 files changed

+44
-22
lines changed

src/librustdoc/html/render/print_item.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ use crate::html::markdown::MarkdownSummaryLine;
3434

3535
const ITEM_TABLE_OPEN: &'static str = "<div class=\"item-table\">";
3636
const ITEM_TABLE_CLOSE: &'static str = "</div>";
37+
const ITEM_TABLE_ROW_OPEN: &'static str = "<div class=\"item-row\">";
38+
const ITEM_TABLE_ROW_CLOSE: &'static str = "</div>";
3739

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

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

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

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

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

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

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

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

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

370372
let doc_value = myitem.doc_value().unwrap_or_default();
373+
w.write_str(ITEM_TABLE_ROW_OPEN);
371374
write!(
372375
w,
373376
"<div class=\"item-left {stab}{add}module-item\">\
@@ -390,15 +393,9 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
390393
.collect::<Vec<_>>()
391394
.join(" "),
392395
);
396+
w.write_str(ITEM_TABLE_ROW_CLOSE);
393397
}
394398
}
395-
396-
item_table_nth_element += 1;
397-
if item_table_nth_element > item_table_block_size {
398-
w.write_str(ITEM_TABLE_CLOSE);
399-
w.write_str(ITEM_TABLE_OPEN);
400-
item_table_nth_element = 0;
401-
}
402399
}
403400

404401
if curty.is_some() {

src/librustdoc/html/static/css/rustdoc.css

+9-10
Original file line numberDiff line numberDiff line change
@@ -773,22 +773,18 @@ h2.small-section-header > .anchor {
773773
.block a.current.crate { font-weight: 500; }
774774

775775
.item-table {
776-
display: grid;
777-
column-gap: 1.2rem;
778-
row-gap: 0.0rem;
779-
grid-template-columns: auto 1fr;
776+
display: table-row;
780777
/* align content left */
781778
justify-items: start;
782779
}
783-
780+
.item-row {
781+
display: table-row;
782+
}
784783
.item-left, .item-right {
785-
display: block;
784+
display: table-cell;
786785
}
787786
.item-left {
788-
grid-column: 1;
789-
}
790-
.item-right {
791-
grid-column: 2;
787+
padding-right: 1.2rem;
792788
}
793789

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

18921888
/* Display an alternating layout on tablets and phones */
18931889
.item-table {
1890+
display: block;
1891+
}
1892+
.item-row {
18941893
display: flex;
18951894
flex-flow: column wrap;
18961895
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
goto: file://|DOC_PATH|/test_docs/huge_amount_of_consts/index.html
2+
3+
// Make sure that the last two entries are more than 12 pixels apart and not stacked on each other.
4+
5+
compare-elements-position-near-false: ("//*[@class='item-table']//div[last()-1]", "//*[@class='item-table']//div[last()-3]", {"y": 12})

src/test/rustdoc-gui/src/test_docs/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ name = "test_docs"
33
version = "0.1.0"
44
edition = "2018"
55

6+
build = "build.rs"
7+
68
[lib]
79
path = "lib.rs"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//! generate 2000 constants for testing
2+
3+
use std::{fs::write, path::PathBuf};
4+
5+
fn main() -> std::io::Result<()> {
6+
let out_dir = std::env::var("OUT_DIR").expect("OUT_DIR is not defined");
7+
8+
let mut output = String::new();
9+
for i in 0..2000 {
10+
let line = format!("/// Some const A{0}\npub const A{0}: isize = 0;\n", i);
11+
output.push_str(&*line);
12+
};
13+
14+
write(&[&*out_dir, "huge_amount_of_consts.rs"].iter().collect::<PathBuf>(), output)
15+
}

src/test/rustdoc-gui/src/test_docs/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,7 @@ pub mod keyword {}
116116

117117
/// Just some type alias.
118118
pub type SomeType = u32;
119+
120+
pub mod huge_amount_of_consts {
121+
include!(concat!(env!("OUT_DIR"), "/huge_amount_of_consts.rs"));
122+
}

src/tools/rustdoc-gui/tester.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ async function main(argv) {
172172
}
173173
files.sort();
174174

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

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

0 commit comments

Comments
 (0)