Skip to content

Commit 753598a

Browse files
Rollup merge of rust-lang#79340 - GuillaumeGomez:rename-stability, r=jyn514
Rename "stability" CSS class to "item-info" and combine `document_stability` with `document_short` Follow-up of rust-lang#79300 The point of this PR is to make the CSS class more accurate since it's not only about stability anymore. r? `@jyn514`
2 parents e37f25a + be0484b commit 753598a

File tree

8 files changed

+77
-58
lines changed

8 files changed

+77
-58
lines changed

src/librustdoc/html/render/mod.rs

+46-28
Original file line numberDiff line numberDiff line change
@@ -1844,7 +1844,7 @@ fn document(w: &mut Buffer, cx: &Context, item: &clean::Item, parent: Option<&cl
18441844
if let Some(ref name) = item.name {
18451845
info!("Documenting {}", name);
18461846
}
1847-
document_stability(w, cx, item, false, parent);
1847+
document_item_info(w, cx, item, false, parent);
18481848
document_full(w, item, cx, "", false);
18491849
}
18501850

@@ -1880,10 +1880,17 @@ fn render_markdown(
18801880
fn document_short(
18811881
w: &mut Buffer,
18821882
item: &clean::Item,
1883+
cx: &Context,
18831884
link: AssocItemLink<'_>,
18841885
prefix: &str,
18851886
is_hidden: bool,
1887+
parent: Option<&clean::Item>,
1888+
show_def_docs: bool,
18861889
) {
1890+
document_item_info(w, cx, item, is_hidden, parent);
1891+
if !show_def_docs {
1892+
return;
1893+
}
18871894
if let Some(s) = item.doc_value() {
18881895
let mut summary_html = MarkdownSummaryLine(s, &item.links()).into_string();
18891896

@@ -1928,18 +1935,23 @@ fn document_full(w: &mut Buffer, item: &clean::Item, cx: &Context, prefix: &str,
19281935
}
19291936
}
19301937

1931-
fn document_stability(
1938+
/// Add extra information about an item such as:
1939+
///
1940+
/// * Stability
1941+
/// * Deprecated
1942+
/// * Required features (through the `doc_cfg` feature)
1943+
fn document_item_info(
19321944
w: &mut Buffer,
19331945
cx: &Context,
19341946
item: &clean::Item,
19351947
is_hidden: bool,
19361948
parent: Option<&clean::Item>,
19371949
) {
1938-
let stabilities = short_stability(item, cx, parent);
1939-
if !stabilities.is_empty() {
1940-
write!(w, "<div class=\"stability{}\">", if is_hidden { " hidden" } else { "" });
1941-
for stability in stabilities {
1942-
write!(w, "{}", stability);
1950+
let item_infos = short_item_info(item, cx, parent);
1951+
if !item_infos.is_empty() {
1952+
write!(w, "<div class=\"item-info{}\">", if is_hidden { " hidden" } else { "" });
1953+
for info in item_infos {
1954+
write!(w, "{}", info);
19431955
}
19441956
write!(w, "</div>");
19451957
}
@@ -2194,7 +2206,7 @@ fn item_module(w: &mut Buffer, cx: &Context, item: &clean::Item, items: &[clean:
21942206
<td class=\"docblock-short\">{stab_tags}{docs}</td>\
21952207
</tr>",
21962208
name = *myitem.name.as_ref().unwrap(),
2197-
stab_tags = stability_tags(myitem, item),
2209+
stab_tags = extra_info_tags(myitem, item),
21982210
docs = MarkdownSummaryLine(doc_value, &myitem.links()).into_string(),
21992211
class = myitem.type_(),
22002212
add = add,
@@ -2216,9 +2228,9 @@ fn item_module(w: &mut Buffer, cx: &Context, item: &clean::Item, items: &[clean:
22162228
}
22172229
}
22182230

2219-
/// Render the stability and deprecation tags that are displayed in the item's summary at the
2220-
/// module level.
2221-
fn stability_tags(item: &clean::Item, parent: &clean::Item) -> String {
2231+
/// Render the stability, deprecation and portability tags that are displayed in the item's summary
2232+
/// at the module level.
2233+
fn extra_info_tags(item: &clean::Item, parent: &clean::Item) -> String {
22222234
let mut tags = String::new();
22232235

22242236
fn tag_html(class: &str, title: &str, contents: &str) -> String {
@@ -2271,10 +2283,10 @@ fn portability(item: &clean::Item, parent: Option<&clean::Item>) -> Option<Strin
22712283
Some(format!("<div class=\"stab portability\">{}</div>", cfg?.render_long_html()))
22722284
}
22732285

2274-
/// Render the stability and/or deprecation warning that is displayed at the top of the item's
2275-
/// documentation.
2276-
fn short_stability(item: &clean::Item, cx: &Context, parent: Option<&clean::Item>) -> Vec<String> {
2277-
let mut stability = vec![];
2286+
/// Render the stability, deprecation and portability information that is displayed at the top of
2287+
/// the item's documentation.
2288+
fn short_item_info(item: &clean::Item, cx: &Context, parent: Option<&clean::Item>) -> Vec<String> {
2289+
let mut extra_info = vec![];
22782290
let error_codes = cx.shared.codes;
22792291

22802292
if let Some(Deprecation { ref note, ref since, is_since_rustc_version }) = item.deprecation {
@@ -2301,7 +2313,7 @@ fn short_stability(item: &clean::Item, cx: &Context, parent: Option<&clean::Item
23012313
);
23022314
message.push_str(&format!(": {}", html.into_string()));
23032315
}
2304-
stability.push(format!(
2316+
extra_info.push(format!(
23052317
"<div class=\"stab deprecated\"><span class=\"emoji\">👎</span> {}</div>",
23062318
message,
23072319
));
@@ -2345,14 +2357,14 @@ fn short_stability(item: &clean::Item, cx: &Context, parent: Option<&clean::Item
23452357
);
23462358
}
23472359

2348-
stability.push(format!("<div class=\"stab unstable\">{}</div>", message));
2360+
extra_info.push(format!("<div class=\"stab unstable\">{}</div>", message));
23492361
}
23502362

23512363
if let Some(portability) = portability(item, parent) {
2352-
stability.push(portability);
2364+
extra_info.push(portability);
23532365
}
23542366

2355-
stability
2367+
extra_info
23562368
}
23572369

23582370
fn item_constant(w: &mut Buffer, cx: &Context, it: &clean::Item, c: &clean::Constant) {
@@ -3703,7 +3715,7 @@ fn render_impl(
37033715

37043716
if trait_.is_some() {
37053717
if let Some(portability) = portability(&i.impl_item, Some(parent)) {
3706-
write!(w, "<div class=\"stability\">{}</div>", portability);
3718+
write!(w, "<div class=\"item-info\">{}</div>", portability);
37073719
}
37083720
}
37093721

@@ -3801,26 +3813,32 @@ fn render_impl(
38013813
if let Some(it) = t.items.iter().find(|i| i.name == item.name) {
38023814
// We need the stability of the item from the trait
38033815
// because impls can't have a stability.
3804-
document_stability(w, cx, it, is_hidden, Some(parent));
38053816
if item.doc_value().is_some() {
3817+
document_item_info(w, cx, it, is_hidden, Some(parent));
38063818
document_full(w, item, cx, "", is_hidden);
3807-
} else if show_def_docs {
3819+
} else {
38083820
// In case the item isn't documented,
38093821
// provide short documentation from the trait.
3810-
document_short(w, it, link, "", is_hidden);
3822+
document_short(
3823+
w,
3824+
it,
3825+
cx,
3826+
link,
3827+
"",
3828+
is_hidden,
3829+
Some(parent),
3830+
show_def_docs,
3831+
);
38113832
}
38123833
}
38133834
} else {
3814-
document_stability(w, cx, item, is_hidden, Some(parent));
3835+
document_item_info(w, cx, item, is_hidden, Some(parent));
38153836
if show_def_docs {
38163837
document_full(w, item, cx, "", is_hidden);
38173838
}
38183839
}
38193840
} else {
3820-
document_stability(w, cx, item, is_hidden, Some(parent));
3821-
if show_def_docs {
3822-
document_short(w, item, link, "", is_hidden);
3823-
}
3841+
document_short(w, item, cx, link, "", is_hidden, Some(parent), show_def_docs);
38243842
}
38253843
}
38263844
}

src/librustdoc/html/static/main.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,7 @@ function defocusSearchBar() {
22662266
}
22672267
}
22682268
var ns = n.nextElementSibling;
2269-
while (ns && (hasClass(ns, "docblock") || hasClass(ns, "stability"))) {
2269+
while (ns && (hasClass(ns, "docblock") || hasClass(ns, "item-info"))) {
22702270
if (addOrRemove) {
22712271
addClass(ns, "hidden-by-impl-hider");
22722272
} else {
@@ -2282,7 +2282,7 @@ function defocusSearchBar() {
22822282
var action = mode;
22832283
if (hasClass(toggle.parentNode, "impl") === false) {
22842284
relatedDoc = toggle.parentNode.nextElementSibling;
2285-
if (hasClass(relatedDoc, "stability")) {
2285+
if (hasClass(relatedDoc, "item-info")) {
22862286
relatedDoc = relatedDoc.nextElementSibling;
22872287
}
22882288
if (hasClass(relatedDoc, "docblock") || hasClass(relatedDoc, "sub-variant")) {
@@ -2332,16 +2332,17 @@ function defocusSearchBar() {
23322332
var dontApplyBlockRule = toggle.parentNode.parentNode.id !== "main";
23332333
if (action === "show") {
23342334
removeClass(relatedDoc, "fns-now-collapsed");
2335-
// Stability information is never hidden.
2336-
if (hasClass(docblock, "stability") === false) {
2335+
// Stability/deprecation/portability information is never hidden.
2336+
if (hasClass(docblock, "item-info") === false) {
23372337
removeClass(docblock, "hidden-by-usual-hider");
23382338
}
23392339
onEachLazy(toggle.childNodes, adjustToggle(false, dontApplyBlockRule));
23402340
onEachLazy(relatedDoc.childNodes, implHider(false, dontApplyBlockRule));
23412341
} else if (action === "hide") {
23422342
addClass(relatedDoc, "fns-now-collapsed");
2343-
// Stability information should be shown even when detailed info is hidden.
2344-
if (hasClass(docblock, "stability") === false) {
2343+
// Stability/deprecation/portability information should be shown even when detailed
2344+
// info is hidden.
2345+
if (hasClass(docblock, "item-info") === false) {
23452346
addClass(docblock, "hidden-by-usual-hider");
23462347
}
23472348
onEachLazy(toggle.childNodes, adjustToggle(true, dontApplyBlockRule));
@@ -2445,7 +2446,7 @@ function defocusSearchBar() {
24452446

24462447
var func = function(e) {
24472448
var next = e.nextElementSibling;
2448-
if (next && hasClass(next, "stability")) {
2449+
if (next && hasClass(next, "item-info")) {
24492450
next = next.nextElementSibling;
24502451
}
24512452
if (!next) {
@@ -2462,7 +2463,7 @@ function defocusSearchBar() {
24622463

24632464
var funcImpl = function(e) {
24642465
var next = e.nextElementSibling;
2465-
if (next && hasClass(next, "stability")) {
2466+
if (next && hasClass(next, "item-info")) {
24662467
next = next.nextElementSibling;
24672468
}
24682469
if (next && hasClass(next, "docblock")) {

src/librustdoc/html/static/rustdoc.css

+9-9
Original file line numberDiff line numberDiff line change
@@ -553,21 +553,21 @@ h4 > code, h3 > code, .invisible > code {
553553
border: none;
554554
}
555555

556-
.content .stability code {
556+
.content .item-info code {
557557
font-size: 90%;
558558
}
559559

560-
.content .stability {
560+
.content .item-info {
561561
position: relative;
562562
margin-left: 33px;
563563
margin-top: -13px;
564564
}
565565

566-
.sub-variant > div > .stability {
566+
.sub-variant > div > .item-info {
567567
margin-top: initial;
568568
}
569569

570-
.content .stability::before {
570+
.content .item-info::before {
571571
content: '⬑';
572572
font-size: 25px;
573573
position: absolute;
@@ -579,23 +579,23 @@ h4 > code, h3 > code, .invisible > code {
579579
margin-left: 20px;
580580
}
581581

582-
.content .impl-items .docblock, .content .impl-items .stability {
582+
.content .impl-items .docblock, .content .impl-items .item-info {
583583
margin-bottom: .6em;
584584
}
585585

586-
.content .impl-items > .stability {
586+
.content .impl-items > .item-info {
587587
margin-left: 40px;
588588
}
589589

590-
.methods > .stability, .content .impl-items > .stability {
590+
.methods > .item-info, .content .impl-items > .item-info {
591591
margin-top: -8px;
592592
}
593593

594594
.impl-items {
595595
flex-basis: 100%;
596596
}
597597

598-
#main > .stability {
598+
#main > .item-info {
599599
margin-top: 0;
600600
}
601601

@@ -655,7 +655,7 @@ a {
655655
}
656656

657657
.docblock a:not(.srclink):not(.test-arrow):hover,
658-
.docblock-short a:not(.srclink):not(.test-arrow):hover, .stability a {
658+
.docblock-short a:not(.srclink):not(.test-arrow):hover, .item-info a {
659659
text-decoration: underline;
660660
}
661661

src/librustdoc/html/static/themes/ayu.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ pre {
166166
color: #c5c5c5;
167167
}
168168

169-
.content .stability::before { color: #ccc; }
169+
.content .item-info::before { color: #ccc; }
170170

171171
.content span.foreigntype, .content a.foreigntype { color: #ef57ff; }
172172
.content span.union, .content a.union { color: #98a01c; }
@@ -219,7 +219,7 @@ a {
219219
}
220220

221221
.docblock:not(.type-decl) a:not(.srclink):not(.test-arrow),
222-
.docblock-short a:not(.srclink):not(.test-arrow), .stability a,
222+
.docblock-short a:not(.srclink):not(.test-arrow), .item-info a,
223223
#help a {
224224
color: #39AFD7;
225225
}

src/librustdoc/html/static/themes/dark.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pre {
136136
.content .highlighted.primitive { background-color: #00708a; }
137137
.content .highlighted.keyword { background-color: #884719; }
138138

139-
.content .stability::before { color: #ccc; }
139+
.content .item-info::before { color: #ccc; }
140140

141141
.content span.enum, .content a.enum, .block a.current.enum { color: #82b089; }
142142
.content span.struct, .content a.struct, .block a.current.struct { color: #2dbfb8; }
@@ -177,7 +177,7 @@ a {
177177
}
178178

179179
.docblock:not(.type-decl) a:not(.srclink):not(.test-arrow),
180-
.docblock-short a:not(.srclink):not(.test-arrow), .stability a,
180+
.docblock-short a:not(.srclink):not(.test-arrow), .item-info a,
181181
#help a {
182182
color: #D2991D;
183183
}

src/librustdoc/html/static/themes/light.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pre {
134134
.content .highlighted.primitive { background-color: #9aecff; }
135135
.content .highlighted.keyword { background-color: #f99650; }
136136

137-
.content .stability::before { color: #ccc; }
137+
.content .item-info::before { color: #ccc; }
138138

139139
.content span.enum, .content a.enum, .block a.current.enum { color: #508157; }
140140
.content span.struct, .content a.struct, .block a.current.struct { color: #ad448e; }
@@ -175,7 +175,7 @@ a {
175175
}
176176

177177
.docblock:not(.type-decl) a:not(.srclink):not(.test-arrow),
178-
.docblock-short a:not(.srclink):not(.test-arrow), .stability a,
178+
.docblock-short a:not(.srclink):not(.test-arrow), .item-info a,
179179
#help a {
180180
color: #3873AD;
181181
}

src/test/rustdoc/doc-cfg.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@
22
#![feature(target_feature, cfg_target_feature)]
33

44
// @has doc_cfg/struct.Portable.html
5-
// @!has - '//*[@id="main"]/*[@class="stability"]/*[@class="stab portability"]' ''
5+
// @!has - '//*[@id="main"]/*[@class="item-info"]/*[@class="stab portability"]' ''
66
// @has - '//*[@id="method.unix_and_arm_only_function"]' 'fn unix_and_arm_only_function()'
77
// @has - '//*[@class="stab portability"]' 'This is supported on Unix and ARM only.'
88
pub struct Portable;
99

1010
// @has doc_cfg/unix_only/index.html \
11-
// '//*[@id="main"]/*[@class="stability"]/*[@class="stab portability"]' \
11+
// '//*[@id="main"]/*[@class="item-info"]/*[@class="stab portability"]' \
1212
// 'This is supported on Unix only.'
1313
// @matches - '//*[@class="module-item"]//*[@class="stab portability"]' '\AARM\Z'
1414
// @count - '//*[@class="stab portability"]' 2
1515
#[doc(cfg(unix))]
1616
pub mod unix_only {
1717
// @has doc_cfg/unix_only/fn.unix_only_function.html \
18-
// '//*[@id="main"]/*[@class="stability"]/*[@class="stab portability"]' \
18+
// '//*[@id="main"]/*[@class="item-info"]/*[@class="stab portability"]' \
1919
// 'This is supported on Unix only.'
2020
// @count - '//*[@class="stab portability"]' 1
2121
pub fn unix_only_function() {
2222
content::should::be::irrelevant();
2323
}
2424

2525
// @has doc_cfg/unix_only/trait.ArmOnly.html \
26-
// '//*[@id="main"]/*[@class="stability"]/*[@class="stab portability"]' \
26+
// '//*[@id="main"]/*[@class="item-info"]/*[@class="stab portability"]' \
2727
// 'This is supported on Unix and ARM only.'
2828
// @count - '//*[@class="stab portability"]' 2
2929
#[doc(cfg(target_arch = "arm"))]
@@ -44,15 +44,15 @@ pub mod unix_only {
4444
// @matches - '//*[@class="module-item"]//*[@class="stab portability"]' '\Aavx\Z'
4545

4646
// @has doc_cfg/fn.uses_target_feature.html
47-
// @has - '//*[@id="main"]/*[@class="stability"]/*[@class="stab portability"]' \
47+
// @has - '//*[@id="main"]/*[@class="item-info"]/*[@class="stab portability"]' \
4848
// 'This is supported with target feature avx only.'
4949
#[target_feature(enable = "avx")]
5050
pub unsafe fn uses_target_feature() {
5151
content::should::be::irrelevant();
5252
}
5353

5454
// @has doc_cfg/fn.uses_cfg_target_feature.html
55-
// @has - '//*[@id="main"]/*[@class="stability"]/*[@class="stab portability"]' \
55+
// @has - '//*[@id="main"]/*[@class="item-info"]/*[@class="stab portability"]' \
5656
// 'This is supported with target feature avx only.'
5757
#[doc(cfg(target_feature = "avx"))]
5858
pub fn uses_cfg_target_feature() {

0 commit comments

Comments
 (0)