Skip to content

Commit 656f08d

Browse files
authored
Rollup merge of rust-lang#102027 - notriddle:notriddle/docblock-item-decl, r=GuillaumeGomez
rustdoc: remove `docblock` class from `item-decl` This class was originally added in 73b97c7 to support hiding and showing the item, because `main.js` went through all `docblock` elements in the DOM and added toggles to them. https://github.com/rust-lang/rust/blob/73b97c7e7c9cfac4dfa4804654b1db6ab687b589/src/librustdoc/html/static/main.js#L1856-L1867 The `item-decl` is no longer auto-hidden since c96f86d removed it. `item-decl` used to be called `type-decl`: that name was changed in 8b7a2dd. The `docblock` class is no longer used for implementing toggles, since rustdoc switched to using `<details>` elements. Preview: https://notriddle.com/notriddle-rustdoc-test/docblock-item-decl/rustdoc/clean/types/enum.Type.html
2 parents 8856423 + 8e6cf7d commit 656f08d

27 files changed

+87
-90
lines changed

src/librustdoc/html/render/print_item.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ fn item_function(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, f: &cle
514514
+ name.as_str().len()
515515
+ generics_len;
516516

517-
wrap_into_docblock(w, |w| {
517+
wrap_into_item_decl(w, |w| {
518518
wrap_item(w, "fn", |w| {
519519
render_attributes_in_pre(w, it, "");
520520
w.reserve(header_len);
@@ -553,7 +553,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
553553
cx.tcx().trait_def(t.def_id).must_implement_one_of.clone();
554554

555555
// Output the trait definition
556-
wrap_into_docblock(w, |w| {
556+
wrap_into_item_decl(w, |w| {
557557
wrap_item(w, "trait", |w| {
558558
render_attributes_in_pre(w, it, "");
559559
write!(
@@ -1033,7 +1033,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
10331033
}
10341034

10351035
fn item_trait_alias(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean::TraitAlias) {
1036-
wrap_into_docblock(w, |w| {
1036+
wrap_into_item_decl(w, |w| {
10371037
wrap_item(w, "trait-alias", |w| {
10381038
render_attributes_in_pre(w, it, "");
10391039
write!(
@@ -1057,7 +1057,7 @@ fn item_trait_alias(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &
10571057
}
10581058

10591059
fn item_opaque_ty(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean::OpaqueTy) {
1060-
wrap_into_docblock(w, |w| {
1060+
wrap_into_item_decl(w, |w| {
10611061
wrap_item(w, "opaque", |w| {
10621062
render_attributes_in_pre(w, it, "");
10631063
write!(
@@ -1096,7 +1096,7 @@ fn item_typedef(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clea
10961096
});
10971097
}
10981098

1099-
wrap_into_docblock(w, |w| write_content(w, cx, it, t));
1099+
wrap_into_item_decl(w, |w| write_content(w, cx, it, t));
11001100

11011101
document(w, cx, it, None, HeadingOffset::H2);
11021102

@@ -1110,7 +1110,7 @@ fn item_typedef(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clea
11101110
}
11111111

11121112
fn item_union(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean::Union) {
1113-
wrap_into_docblock(w, |w| {
1113+
wrap_into_item_decl(w, |w| {
11141114
wrap_item(w, "union", |w| {
11151115
render_attributes_in_pre(w, it, "");
11161116
render_union(w, it, Some(&s.generics), &s.fields, "", cx);
@@ -1174,7 +1174,7 @@ fn print_tuple_struct_fields(w: &mut Buffer, cx: &Context<'_>, s: &[clean::Item]
11741174

11751175
fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::Enum) {
11761176
let count_variants = e.variants().count();
1177-
wrap_into_docblock(w, |w| {
1177+
wrap_into_item_decl(w, |w| {
11781178
wrap_item(w, "enum", |w| {
11791179
render_attributes_in_pre(w, it, "");
11801180
write!(
@@ -1333,14 +1333,14 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
13331333
}
13341334

13351335
fn item_macro(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean::Macro) {
1336-
wrap_into_docblock(w, |w| {
1336+
wrap_into_item_decl(w, |w| {
13371337
highlight::render_macro_with_highlighting(&t.source, w);
13381338
});
13391339
document(w, cx, it, None, HeadingOffset::H2)
13401340
}
13411341

13421342
fn item_proc_macro(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, m: &clean::ProcMacro) {
1343-
wrap_into_docblock(w, |w| {
1343+
wrap_into_item_decl(w, |w| {
13441344
let name = it.name.expect("proc-macros always have names");
13451345
match m.kind {
13461346
MacroKind::Bang => {
@@ -1387,7 +1387,7 @@ fn item_primitive(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item) {
13871387
}
13881388

13891389
fn item_constant(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, c: &clean::Constant) {
1390-
wrap_into_docblock(w, |w| {
1390+
wrap_into_item_decl(w, |w| {
13911391
wrap_item(w, "const", |w| {
13921392
render_attributes_in_code(w, it);
13931393

@@ -1436,7 +1436,7 @@ fn item_constant(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, c: &cle
14361436
}
14371437

14381438
fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean::Struct) {
1439-
wrap_into_docblock(w, |w| {
1439+
wrap_into_item_decl(w, |w| {
14401440
wrap_item(w, "struct", |w| {
14411441
render_attributes_in_code(w, it);
14421442
render_struct(w, it, Some(&s.generics), s.struct_type, &s.fields, "", true, cx);
@@ -1489,7 +1489,7 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean
14891489
}
14901490

14911491
fn item_static(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean::Static) {
1492-
wrap_into_docblock(w, |w| {
1492+
wrap_into_item_decl(w, |w| {
14931493
wrap_item(w, "static", |w| {
14941494
render_attributes_in_code(w, it);
14951495
write!(
@@ -1506,7 +1506,7 @@ fn item_static(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean
15061506
}
15071507

15081508
fn item_foreign_type(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item) {
1509-
wrap_into_docblock(w, |w| {
1509+
wrap_into_item_decl(w, |w| {
15101510
wrap_item(w, "foreigntype", |w| {
15111511
w.write_str("extern {\n");
15121512
render_attributes_in_code(w, it);
@@ -1595,11 +1595,11 @@ fn bounds(t_bounds: &[clean::GenericBound], trait_alias: bool, cx: &Context<'_>)
15951595
bounds
15961596
}
15971597

1598-
fn wrap_into_docblock<F>(w: &mut Buffer, f: F)
1598+
fn wrap_into_item_decl<F>(w: &mut Buffer, f: F)
15991599
where
16001600
F: FnOnce(&mut Buffer),
16011601
{
1602-
w.write_str("<div class=\"docblock item-decl\">");
1602+
w.write_str("<div class=\"item-decl\">");
16031603
f(w);
16041604
w.write_str("</div>")
16051605
}

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

-3
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,6 @@ code, pre, a.test-arrow, .code-header {
372372
pre {
373373
padding: 14px;
374374
}
375-
.docblock.item-decl {
376-
margin-left: 0;
377-
}
378375
.item-decl pre {
379376
overflow-x: auto;
380377
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This test ensures that the docblock elements have the appropriate left margin.
22
goto: file://|DOC_PATH|/test_docs/fn.foo.html
33
// The top docblock elements shouldn't have left margin...
4-
assert-css: ("#main-content .docblock.item-decl", {"margin-left": "0px"})
4+
assert-css: ("#main-content .item-decl", {"margin-left": "0px"})
55
// ... but all the others should!
6-
assert-css: ("#main-content .docblock:not(.item-decl)", {"margin-left": "24px"})
6+
assert-css: ("#main-content .docblock", {"margin-left": "24px"})

src/test/rustdoc-gui/font-weight.goml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This test checks that the font weight is correctly applied.
22
goto: file://|DOC_PATH|/lib2/struct.Foo.html
3-
assert-css: ("//*[@class='docblock item-decl']//a[text()='Alias']", {"font-weight": "400"})
3+
assert-css: ("//*[@class='item-decl']//a[text()='Alias']", {"font-weight": "400"})
44
assert-css: (
55
"//*[@class='structfield small-section-header']//a[text()='Alias']",
66
{"font-weight": "400"},
@@ -19,7 +19,7 @@ goto: file://|DOC_PATH|/lib2/trait.Trait.html
1919

2020
// This is a complex selector, so here's how it works:
2121
//
22-
// * //*[@class='docblock item-decl'] — selects element of any tag with classes docblock and item-decl
22+
// * //*[@class='item-decl'] — selects element of any tag with classes docblock and item-decl
2323
// * /pre[@class='rust trait'] — selects immediate child with tag pre and classes rust and trait
2424
// * /code — selects immediate child with tag code
2525
// * /a[@class='constant'] — selects immediate child with tag a and class constant
@@ -29,11 +29,11 @@ goto: file://|DOC_PATH|/lib2/trait.Trait.html
2929
// This uses '/parent::*' as a proxy for the style of the text node.
3030
// We can't just select the '<a>' because intermediate tags could be added.
3131
assert-count: (
32-
"//*[@class='docblock item-decl']/pre[@class='rust trait']/code/a[@class='constant']//text()/parent::*",
32+
"//*[@class='item-decl']/pre[@class='rust trait']/code/a[@class='constant']//text()/parent::*",
3333
1,
3434
)
3535
assert-css: (
36-
"//*[@class='docblock item-decl']/pre[@class='rust trait']/code/a[@class='constant']//text()/parent::*",
36+
"//*[@class='item-decl']/pre[@class='rust trait']/code/a[@class='constant']//text()/parent::*",
3737
{"font-weight": "400"},
3838
)
3939

src/test/rustdoc-gui/item-info-overflow.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ goto: file://|DOC_PATH|/lib2/struct.LongItemInfo.html
33
// We set a fixed size so there is no chance of "random" resize.
44
size: (1200, 870)
55
// Logically, the "item-decl" and the "item-info" should have the same scroll width.
6-
compare-elements-property: (".docblock.item-decl", ".item-info", ["scrollWidth"])
6+
compare-elements-property: (".item-decl", ".item-info", ["scrollWidth"])
77
assert-property: (".item-info", {"scrollWidth": "890"})
88
// Just to be sure we're comparing the correct "item-info":
99
assert-text: (
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![crate_name = "foo"]
22

33
// @has 'foo/fn.f.html'
4-
// @has - //*[@'class="docblock item-decl"]' '#[export_name = "f"] pub fn f()'
4+
// @has - //*[@'class="item-decl"]' '#[export_name = "f"] pub fn f()'
55
#[export_name = "\
66
f"]
77
pub fn f() {}

src/test/rustdoc/attributes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ pub extern "C" fn f() {}
88
#[export_name = "bar"]
99
pub extern "C" fn g() {}
1010

11-
// @has foo/struct.Repr.html '//*[@class="docblock item-decl"]' '#[repr(C, align(8))]'
11+
// @has foo/struct.Repr.html '//*[@class="item-decl"]' '#[repr(C, align(8))]'
1212
#[repr(C, align(8))]
1313
pub struct Repr;
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#![crate_name = "foo"]
22

33
// @has 'foo/constant.HOUR_IN_SECONDS.html'
4-
// @has - '//*[@class="docblock item-decl"]//code' 'pub const HOUR_IN_SECONDS: u64 = _; // 3_600u64'
4+
// @has - '//*[@class="item-decl"]//code' 'pub const HOUR_IN_SECONDS: u64 = _; // 3_600u64'
55
pub const HOUR_IN_SECONDS: u64 = 60 * 60;
66

77
// @has 'foo/constant.NEGATIVE.html'
8-
// @has - '//*[@class="docblock item-decl"]//code' 'pub const NEGATIVE: i64 = _; // -3_600i64'
8+
// @has - '//*[@class="item-decl"]//code' 'pub const NEGATIVE: i64 = _; // -3_600i64'
99
pub const NEGATIVE: i64 = -60 * 60;

src/test/rustdoc/decl-trailing-whitespace.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub struct Error;
77
// @has 'foo/trait.Write.html'
88

99
pub trait Write {
10-
// @snapshot 'declaration' - '//*[@class="docblock item-decl"]//code'
10+
// @snapshot 'declaration' - '//*[@class="item-decl"]//code'
1111
fn poll_write(
1212
self: Option<String>,
1313
cx: &mut Option<String>,

src/test/rustdoc/macro-higher-kinded-function.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ macro_rules! gen {
1111
}
1212

1313
// @has 'foo/struct.Providers.html'
14-
// @has - '//*[@class="docblock item-decl"]//code' "pub a: for<'tcx> fn(_: TyCtxt<'tcx>, _: u8) -> i8,"
15-
// @has - '//*[@class="docblock item-decl"]//code' "pub b: for<'tcx> fn(_: TyCtxt<'tcx>, _: u16) -> i16,"
14+
// @has - '//*[@class="item-decl"]//code' "pub a: for<'tcx> fn(_: TyCtxt<'tcx>, _: u8) -> i8,"
15+
// @has - '//*[@class="item-decl"]//code' "pub b: for<'tcx> fn(_: TyCtxt<'tcx>, _: u16) -> i16,"
1616
// @has - '//*[@id="structfield.a"]/code' "a: for<'tcx> fn(_: TyCtxt<'tcx>, _: u8) -> i8"
1717
// @has - '//*[@id="structfield.b"]/code' "b: for<'tcx> fn(_: TyCtxt<'tcx>, _: u16) -> i16"
1818
gen! {

src/test/rustdoc/reexport-dep-foreign-fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
extern crate all_item_types;
99

1010
// @has 'foo/fn.foo_ffn.html'
11-
// @has - '//*[@class="docblock item-decl"]//code' 'pub unsafe extern "C" fn foo_ffn()'
11+
// @has - '//*[@class="item-decl"]//code' 'pub unsafe extern "C" fn foo_ffn()'
1212
pub use all_item_types::foo_ffn;

src/test/rustdoc/reexports-priv.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
extern crate reexports;
77

8-
// @has 'foo/macro.addr_of.html' '//*[@class="docblock item-decl"]' 'pub macro addr_of($place:expr) {'
8+
// @has 'foo/macro.addr_of.html' '//*[@class="item-decl"]' 'pub macro addr_of($place:expr) {'
99
pub use reexports::addr_of;
1010
// @!has 'foo/macro.addr_of_crate.html'
1111
pub(crate) use reexports::addr_of_crate;
@@ -14,7 +14,7 @@ pub(self) use reexports::addr_of_self;
1414
// @!has 'foo/macro.addr_of_local.html'
1515
use reexports::addr_of_local;
1616

17-
// @has 'foo/struct.Foo.html' '//*[@class="docblock item-decl"]' 'pub struct Foo;'
17+
// @has 'foo/struct.Foo.html' '//*[@class="item-decl"]' 'pub struct Foo;'
1818
pub use reexports::Foo;
1919
// @!has 'foo/struct.FooCrate.html'
2020
pub(crate) use reexports::FooCrate;
@@ -23,7 +23,7 @@ pub(self) use reexports::FooSelf;
2323
// @!has 'foo/struct.FooLocal.html'
2424
use reexports::FooLocal;
2525

26-
// @has 'foo/enum.Bar.html' '//*[@class="docblock item-decl"]' 'pub enum Bar {'
26+
// @has 'foo/enum.Bar.html' '//*[@class="item-decl"]' 'pub enum Bar {'
2727
pub use reexports::Bar;
2828
// @!has 'foo/enum.BarCrate.html'
2929
pub(crate) use reexports::BarCrate;
@@ -50,7 +50,7 @@ pub(self) use reexports::TypeSelf;
5050
// @!has 'foo/type.TypeLocal.html'
5151
use reexports::TypeLocal;
5252

53-
// @has 'foo/union.Union.html' '//*[@class="docblock item-decl"]' 'pub union Union {'
53+
// @has 'foo/union.Union.html' '//*[@class="item-decl"]' 'pub union Union {'
5454
pub use reexports::Union;
5555
// @!has 'foo/union.UnionCrate.html'
5656
pub(crate) use reexports::UnionCrate;
@@ -61,33 +61,33 @@ use reexports::UnionLocal;
6161

6262
pub mod outer {
6363
pub mod inner {
64-
// @has 'foo/outer/inner/macro.addr_of.html' '//*[@class="docblock item-decl"]' 'pub macro addr_of($place:expr) {'
64+
// @has 'foo/outer/inner/macro.addr_of.html' '//*[@class="item-decl"]' 'pub macro addr_of($place:expr) {'
6565
pub use reexports::addr_of;
66-
// @has 'foo/outer/inner/macro.addr_of_crate.html' '//*[@class="docblock item-decl"]' 'pub(crate) macro addr_of_crate($place:expr) {'
66+
// @has 'foo/outer/inner/macro.addr_of_crate.html' '//*[@class="item-decl"]' 'pub(crate) macro addr_of_crate($place:expr) {'
6767
pub(crate) use reexports::addr_of_crate;
68-
// @has 'foo/outer/inner/macro.addr_of_super.html' '//*[@class="docblock item-decl"]' 'pub(in outer) macro addr_of_super($place:expr) {'
68+
// @has 'foo/outer/inner/macro.addr_of_super.html' '//*[@class="item-decl"]' 'pub(in outer) macro addr_of_super($place:expr) {'
6969
pub(super) use reexports::addr_of_super;
7070
// @!has 'foo/outer/inner/macro.addr_of_self.html'
7171
pub(self) use reexports::addr_of_self;
7272
// @!has 'foo/outer/inner/macro.addr_of_local.html'
7373
use reexports::addr_of_local;
7474

75-
// @has 'foo/outer/inner/struct.Foo.html' '//*[@class="docblock item-decl"]' 'pub struct Foo;'
75+
// @has 'foo/outer/inner/struct.Foo.html' '//*[@class="item-decl"]' 'pub struct Foo;'
7676
pub use reexports::Foo;
77-
// @has 'foo/outer/inner/struct.FooCrate.html' '//*[@class="docblock item-decl"]' 'pub(crate) struct FooCrate;'
77+
// @has 'foo/outer/inner/struct.FooCrate.html' '//*[@class="item-decl"]' 'pub(crate) struct FooCrate;'
7878
pub(crate) use reexports::FooCrate;
79-
// @has 'foo/outer/inner/struct.FooSuper.html' '//*[@class="docblock item-decl"]' 'pub(in outer) struct FooSuper;'
79+
// @has 'foo/outer/inner/struct.FooSuper.html' '//*[@class="item-decl"]' 'pub(in outer) struct FooSuper;'
8080
pub(super) use reexports::FooSuper;
8181
// @!has 'foo/outer/inner/struct.FooSelf.html'
8282
pub(self) use reexports::FooSelf;
8383
// @!has 'foo/outer/inner/struct.FooLocal.html'
8484
use reexports::FooLocal;
8585

86-
// @has 'foo/outer/inner/enum.Bar.html' '//*[@class="docblock item-decl"]' 'pub enum Bar {'
86+
// @has 'foo/outer/inner/enum.Bar.html' '//*[@class="item-decl"]' 'pub enum Bar {'
8787
pub use reexports::Bar;
88-
// @has 'foo/outer/inner/enum.BarCrate.html' '//*[@class="docblock item-decl"]' 'pub(crate) enum BarCrate {'
88+
// @has 'foo/outer/inner/enum.BarCrate.html' '//*[@class="item-decl"]' 'pub(crate) enum BarCrate {'
8989
pub(crate) use reexports::BarCrate;
90-
// @has 'foo/outer/inner/enum.BarSuper.html' '//*[@class="docblock item-decl"]' 'pub(in outer) enum BarSuper {'
90+
// @has 'foo/outer/inner/enum.BarSuper.html' '//*[@class="item-decl"]' 'pub(in outer) enum BarSuper {'
9191
pub(super) use reexports::BarSuper;
9292
// @!has 'foo/outer/inner/enum.BarSelf.html'
9393
pub(self) use reexports::BarSelf;
@@ -116,11 +116,11 @@ pub mod outer {
116116
// @!has 'foo/outer/inner/type.TypeLocal.html'
117117
use reexports::TypeLocal;
118118

119-
// @has 'foo/outer/inner/union.Union.html' '//*[@class="docblock item-decl"]' 'pub union Union {'
119+
// @has 'foo/outer/inner/union.Union.html' '//*[@class="item-decl"]' 'pub union Union {'
120120
pub use reexports::Union;
121-
// @has 'foo/outer/inner/union.UnionCrate.html' '//*[@class="docblock item-decl"]' 'pub(crate) union UnionCrate {'
121+
// @has 'foo/outer/inner/union.UnionCrate.html' '//*[@class="item-decl"]' 'pub(crate) union UnionCrate {'
122122
pub(crate) use reexports::UnionCrate;
123-
// @has 'foo/outer/inner/union.UnionSuper.html' '//*[@class="docblock item-decl"]' 'pub(in outer) union UnionSuper {'
123+
// @has 'foo/outer/inner/union.UnionSuper.html' '//*[@class="item-decl"]' 'pub(in outer) union UnionSuper {'
124124
pub(super) use reexports::UnionSuper;
125125
// @!has 'foo/outer/inner/union.UnionSelf.html'
126126
pub(self) use reexports::UnionSelf;

0 commit comments

Comments
 (0)