Skip to content

Commit 5d0fae5

Browse files
committed
Auto merge of rust-lang#86594 - dns2utf8:move_label_to_symbol, r=GuillaumeGomez
rustdoc: Move label to symbol Implements rust-lang#86578 depends on rust-lang#85651 r? `@GuillaumeGomez` # Screenshot of mobile ![grafik](https://user-images.githubusercontent.com/739070/123267064-1be07f80-d4ec-11eb-8bdb-0b18a41908dc.png) # Screenshot on desktop ![grafik](https://user-images.githubusercontent.com/739070/123267204-46323d00-d4ec-11eb-97ca-2750421352f4.png)
2 parents f12d91f + 0f2e137 commit 5d0fae5

File tree

9 files changed

+60
-14
lines changed

9 files changed

+60
-14
lines changed

src/librustdoc/html/render/print_item.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,11 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
363363
write!(
364364
w,
365365
"<div class=\"item-left {stab}{add}module-item\">\
366-
<a class=\"{class}\" href=\"{href}\" \
367-
title=\"{title}\">{name}</a>{unsafety_flag}\
366+
<a class=\"{class}\" href=\"{href}\" title=\"{title}\">{name}</a>\
367+
{unsafety_flag}\
368+
{stab_tags}\
368369
</div>\
369-
<div class=\"item-right docblock-short\">{stab_tags}{docs}</div>",
370+
<div class=\"item-right docblock-short\">{docs}</div>",
370371
name = *myitem.name.as_ref().unwrap(),
371372
stab_tags = extra_info_tags(myitem, item, cx.tcx()),
372373
docs = MarkdownSummaryLine(&doc_value, &myitem.links(cx)).into_string(),

src/librustdoc/html/static/rustdoc.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ body.blur > :not(#help) {
923923
font-size: 80%;
924924
line-height: 1.2;
925925
margin-bottom: 0;
926-
margin-right: .3em;
926+
margin-left: .3em;
927927
padding: 2px;
928928
vertical-align: text-bottom;
929929
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// These tests verify that labels like "UNIX" and "Deprecated" stay on the same line as their symbol.
2+
// It also verifies the staggered layout on mobile.
3+
goto: file://|DOC_PATH|/test_docs/index.html
4+
5+
// Desktop view
6+
size: (1080, 600)
7+
assert: (".stab.deprecated")
8+
assert: (".stab.portability")
9+
10+
// make sure that deprecated and portability are different colours
11+
assert-css: (".item-table .item-left .stab.deprecated", { "background-color": "rgb(255, 196, 196)" })
12+
assert-css: (".item-table .item-left .stab.portability", { "background-color": "rgb(243, 223, 255)" })
13+
14+
// table like view
15+
assert-css: (".item-right.docblock-short", { "padding-left": "0px" })
16+
// Requires new function: https://github.com/GuillaumeGomez/browser-UI-test/pull/202
17+
//compare-elements-position-near: ("//*[@class='item-left module-item']//a[text()='replaced_function']", ".item-left .stab.deprecated", ("y"))
18+
compare-elements-position: (".item-left .stab.deprecated", ".item-left .stab.portability", ("y"))
19+
20+
// Ensure no wrap
21+
//compare-elements-position: ("//*[@class='item-left module-item']//a[text()='replaced_function']", "//*[@class='item-right docblock-short']//p[text()='a thing with a label']", ("y"))
22+
compare-elements-position: ("//*[@class='item-left module-item']//a[text()='replaced_function']/..", "//*[@class='item-right docblock-short']//p[text()='a thing with a label']/..", ("y"))
23+
24+
25+
// Mobile view
26+
size: (600, 600)
27+
// staggered layout with 2em spacing
28+
assert-css: (".item-right.docblock-short", { "padding-left": "32px" })
29+
// Requires new function: https://github.com/GuillaumeGomez/browser-UI-test/pull/202
30+
//compare-elements-position-near: ("//*[@class='item-left module-item']//a[text()='replaced_function']", ".item-left .stab.deprecated", ("y"))
31+
compare-elements-position: (".item-left .stab.deprecated", ".item-left .stab.portability", ("y"))
32+
33+
// Ensure wrap
34+
compare-elements-position-false: ("//*[@class='item-left module-item']//a[text()='replaced_function']", "//*[@class='item-right docblock-short']//p[text()='a thing with a label']", ("y"))
35+
compare-elements-position-false: ("//*[@class='item-left module-item']//a[text()='replaced_function']/..", "//*[@class='item-right docblock-short']//p[text()='a thing with a label']/..", ("y"))
36+
compare-elements-position-false: (".item-left .stab.deprecated", "//*[@class='item-right docblock-short']//p[text()='a thing with a label']", ("y"))

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

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
#![crate_name = "test_docs"]
55
#![feature(doc_keyword)]
6+
#![feature(doc_cfg)]
67

78
use std::fmt;
89

@@ -90,6 +91,11 @@ pub trait AnotherOne {
9091
/// ```
9192
pub fn check_list_code_block() {}
9293

94+
/// a thing with a label
95+
#[deprecated(since = "1.0.0", note = "text why this deprecated")]
96+
#[doc(cfg(unix))]
97+
pub fn replaced_function() {}
98+
9399
pub enum AnEnum {
94100
WithVariants { and: usize, sub: usize, variants: usize },
95101
}

src/test/rustdoc/deprecated.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @has deprecated/index.html '//*[@class="item-right docblock-short"]/span[@class="stab deprecated"]' \
1+
// @has deprecated/index.html '//*[@class="item-left module-item"]/span[@class="stab deprecated"]' \
22
// 'Deprecated'
33
// @has - '//*[@class="item-right docblock-short"]' 'Deprecated docs'
44

src/test/rustdoc/doc-cfg.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct Portable;
1212
// @has doc_cfg/unix_only/index.html \
1313
// '//*[@id="main"]/*[@class="item-info"]/*[@class="stab portability"]' \
1414
// 'This is supported on Unix only.'
15-
// @matches - '//*[@class="item-right docblock-short"]//*[@class="stab portability"]' '\AARM\Z'
15+
// @matches - '//*[@class="item-left module-item"]//*[@class="stab portability"]' '\AARM\Z'
1616
// @count - '//*[@class="stab portability"]' 2
1717
#[doc(cfg(unix))]
1818
pub mod unix_only {
@@ -42,7 +42,7 @@ pub mod unix_only {
4242
// @has doc_cfg/wasi_only/index.html \
4343
// '//*[@id="main"]/*[@class="item-info"]/*[@class="stab portability"]' \
4444
// 'This is supported on WASI only.'
45-
// @matches - '//*[@class="item-right docblock-short"]//*[@class="stab portability"]' '\AWebAssembly\Z'
45+
// @matches - '//*[@class="item-left module-item"]//*[@class="stab portability"]' '\AWebAssembly\Z'
4646
// @count - '//*[@class="stab portability"]' 2
4747
#[doc(cfg(target_os = "wasi"))]
4848
pub mod wasi_only {
@@ -74,7 +74,7 @@ pub mod wasi_only {
7474

7575
// the portability header is different on the module view versus the full view
7676
// @has doc_cfg/index.html
77-
// @matches - '//*[@class="item-right docblock-short"]//*[@class="stab portability"]' '\Aavx\Z'
77+
// @matches - '//*[@class="item-left module-item"]//*[@class="stab portability"]' '\Aavx\Z'
7878

7979
// @has doc_cfg/fn.uses_target_feature.html
8080
// @has - '//*[@id="main"]/*[@class="item-info"]/*[@class="stab portability"]' \

src/test/rustdoc/duplicate-cfg.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
#![feature(doc_cfg)]
33

44
// @has 'foo/index.html'
5-
// @matches '-' '//*[@class="item-right docblock-short"]//*[@class="stab portability"]' '^sync$'
6-
// @has '-' '//*[@class="item-right docblock-short"]//*[@class="stab portability"]/@title' 'This is supported on crate feature `sync` only'
5+
// @matches '-' '//*[@class="item-left module-item"]//*[@class="stab portability"]' '^sync$'
6+
// @has '-' '//*[@class="item-left module-item"]//*[@class="stab portability"]/@title' 'This is supported on crate feature `sync` only'
77

88
// @has 'foo/struct.Foo.html'
99
// @has '-' '//*[@class="stab portability"]' 'sync'
1010
#[doc(cfg(feature = "sync"))]
1111
#[doc(cfg(feature = "sync"))]
12+
/// my feature sync struct
1213
pub struct Foo;
1314

1415
// @has 'foo/bar/index.html'

src/test/rustdoc/inline_cross/macros.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
extern crate macros;
99

10-
// @has foo/index.html '//*[@class="item-right docblock-short"]/span[@class="stab deprecated"]' Deprecated
11-
// @has - '//*[@class="item-right docblock-short"]/span[@class="stab unstable"]' Experimental
10+
// @has foo/index.html '//*[@class="item-left unstable deprecated module-item"]/span[@class="stab deprecated"]' \
11+
// Deprecated
12+
// @has - '//*[@class="item-left unstable deprecated module-item"]/span[@class="stab unstable"]' \
13+
// Experimental
1214

1315
// @has foo/macro.my_macro.html
1416
// @has - '//*[@class="docblock"]' 'docs for my_macro'

src/test/rustdoc/issue-32374.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
#![unstable(feature="test", issue = "32374")]
55

6-
// @matches issue_32374/index.html '//*[@class="item-right docblock-short"]/span[@class="stab deprecated"]' \
6+
// @matches issue_32374/index.html '//*[@class="item-left unstable deprecated module-item"]/span[@class="stab deprecated"]' \
77
// 'Deprecated'
8-
// @matches issue_32374/index.html '//*[@class="item-right docblock-short"]/span[@class="stab unstable"]' \
8+
// @matches issue_32374/index.html '//*[@class="item-left unstable deprecated module-item"]/span[@class="stab unstable"]' \
99
// 'Experimental'
1010
// @matches issue_32374/index.html '//*[@class="item-right docblock-short"]/text()' 'Docs'
1111

0 commit comments

Comments
 (0)