Skip to content

Commit

Permalink
Auto merge of #86594 - dns2utf8:move_label_to_symbol, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
rustdoc: Move label to symbol

Implements #86578 depends on #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)
  • Loading branch information
bors committed Jun 29, 2021
2 parents f12d91f + 0f2e137 commit 5d0fae5
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 14 deletions.
7 changes: 4 additions & 3 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,11 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
write!(
w,
"<div class=\"item-left {stab}{add}module-item\">\
<a class=\"{class}\" href=\"{href}\" \
title=\"{title}\">{name}</a>{unsafety_flag}\
<a class=\"{class}\" href=\"{href}\" title=\"{title}\">{name}</a>\
{unsafety_flag}\
{stab_tags}\
</div>\
<div class=\"item-right docblock-short\">{stab_tags}{docs}</div>",
<div class=\"item-right docblock-short\">{docs}</div>",
name = *myitem.name.as_ref().unwrap(),
stab_tags = extra_info_tags(myitem, item, cx.tcx()),
docs = MarkdownSummaryLine(&doc_value, &myitem.links(cx)).into_string(),
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ body.blur > :not(#help) {
font-size: 80%;
line-height: 1.2;
margin-bottom: 0;
margin-right: .3em;
margin-left: .3em;
padding: 2px;
vertical-align: text-bottom;
}
Expand Down
36 changes: 36 additions & 0 deletions src/test/rustdoc-gui/label-next-to-symbol.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// These tests verify that labels like "UNIX" and "Deprecated" stay on the same line as their symbol.
// It also verifies the staggered layout on mobile.
goto: file://|DOC_PATH|/test_docs/index.html

// Desktop view
size: (1080, 600)
assert: (".stab.deprecated")
assert: (".stab.portability")

// make sure that deprecated and portability are different colours
assert-css: (".item-table .item-left .stab.deprecated", { "background-color": "rgb(255, 196, 196)" })
assert-css: (".item-table .item-left .stab.portability", { "background-color": "rgb(243, 223, 255)" })

// table like view
assert-css: (".item-right.docblock-short", { "padding-left": "0px" })
// Requires new function: https://github.com/GuillaumeGomez/browser-UI-test/pull/202
//compare-elements-position-near: ("//*[@class='item-left module-item']//a[text()='replaced_function']", ".item-left .stab.deprecated", ("y"))
compare-elements-position: (".item-left .stab.deprecated", ".item-left .stab.portability", ("y"))

// Ensure no wrap
//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"))
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"))


// Mobile view
size: (600, 600)
// staggered layout with 2em spacing
assert-css: (".item-right.docblock-short", { "padding-left": "32px" })
// Requires new function: https://github.com/GuillaumeGomez/browser-UI-test/pull/202
//compare-elements-position-near: ("//*[@class='item-left module-item']//a[text()='replaced_function']", ".item-left .stab.deprecated", ("y"))
compare-elements-position: (".item-left .stab.deprecated", ".item-left .stab.portability", ("y"))

// Ensure wrap
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"))
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"))
compare-elements-position-false: (".item-left .stab.deprecated", "//*[@class='item-right docblock-short']//p[text()='a thing with a label']", ("y"))
6 changes: 6 additions & 0 deletions src/test/rustdoc-gui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#![crate_name = "test_docs"]
#![feature(doc_keyword)]
#![feature(doc_cfg)]

use std::fmt;

Expand Down Expand Up @@ -90,6 +91,11 @@ pub trait AnotherOne {
/// ```
pub fn check_list_code_block() {}

/// a thing with a label
#[deprecated(since = "1.0.0", note = "text why this deprecated")]
#[doc(cfg(unix))]
pub fn replaced_function() {}

pub enum AnEnum {
WithVariants { and: usize, sub: usize, variants: usize },
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc/deprecated.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @has deprecated/index.html '//*[@class="item-right docblock-short"]/span[@class="stab deprecated"]' \
// @has deprecated/index.html '//*[@class="item-left module-item"]/span[@class="stab deprecated"]' \
// 'Deprecated'
// @has - '//*[@class="item-right docblock-short"]' 'Deprecated docs'

Expand Down
6 changes: 3 additions & 3 deletions src/test/rustdoc/doc-cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct Portable;
// @has doc_cfg/unix_only/index.html \
// '//*[@id="main"]/*[@class="item-info"]/*[@class="stab portability"]' \
// 'This is supported on Unix only.'
// @matches - '//*[@class="item-right docblock-short"]//*[@class="stab portability"]' '\AARM\Z'
// @matches - '//*[@class="item-left module-item"]//*[@class="stab portability"]' '\AARM\Z'
// @count - '//*[@class="stab portability"]' 2
#[doc(cfg(unix))]
pub mod unix_only {
Expand Down Expand Up @@ -42,7 +42,7 @@ pub mod unix_only {
// @has doc_cfg/wasi_only/index.html \
// '//*[@id="main"]/*[@class="item-info"]/*[@class="stab portability"]' \
// 'This is supported on WASI only.'
// @matches - '//*[@class="item-right docblock-short"]//*[@class="stab portability"]' '\AWebAssembly\Z'
// @matches - '//*[@class="item-left module-item"]//*[@class="stab portability"]' '\AWebAssembly\Z'
// @count - '//*[@class="stab portability"]' 2
#[doc(cfg(target_os = "wasi"))]
pub mod wasi_only {
Expand Down Expand Up @@ -74,7 +74,7 @@ pub mod wasi_only {

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

// @has doc_cfg/fn.uses_target_feature.html
// @has - '//*[@id="main"]/*[@class="item-info"]/*[@class="stab portability"]' \
Expand Down
5 changes: 3 additions & 2 deletions src/test/rustdoc/duplicate-cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
#![feature(doc_cfg)]

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

// @has 'foo/struct.Foo.html'
// @has '-' '//*[@class="stab portability"]' 'sync'
#[doc(cfg(feature = "sync"))]
#[doc(cfg(feature = "sync"))]
/// my feature sync struct
pub struct Foo;

// @has 'foo/bar/index.html'
Expand Down
6 changes: 4 additions & 2 deletions src/test/rustdoc/inline_cross/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

extern crate macros;

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

// @has foo/macro.my_macro.html
// @has - '//*[@class="docblock"]' 'docs for my_macro'
Expand Down
4 changes: 2 additions & 2 deletions src/test/rustdoc/issue-32374.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

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

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

Expand Down

0 comments on commit 5d0fae5

Please sign in to comment.