Skip to content

Commit 5971266

Browse files
Fixes attributes position in types decl
1 parent 464473a commit 5971266

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

src/librustdoc/html/render.rs

+15-14
Original file line numberDiff line numberDiff line change
@@ -3002,7 +3002,7 @@ fn short_stability(item: &clean::Item, cx: &Context) -> Vec<String> {
30023002
fn item_constant(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
30033003
c: &clean::Constant) -> fmt::Result {
30043004
write!(w, "<pre class='rust const'>")?;
3005-
render_attributes(w, it)?;
3005+
render_attributes(w, it, false)?;
30063006
write!(w, "{vis}const \
30073007
{name}: {typ}</pre>",
30083008
vis = VisSpace(&it.visibility),
@@ -3014,7 +3014,7 @@ fn item_constant(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
30143014
fn item_static(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
30153015
s: &clean::Static) -> fmt::Result {
30163016
write!(w, "<pre class='rust static'>")?;
3017-
render_attributes(w, it)?;
3017+
render_attributes(w, it, false)?;
30183018
write!(w, "{vis}static {mutability}\
30193019
{name}: {typ}</pre>",
30203020
vis = VisSpace(&it.visibility),
@@ -3037,7 +3037,7 @@ fn item_function(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
30373037
f.generics
30383038
).len();
30393039
write!(w, "{}<pre class='rust fn'>", render_spotlight_traits(it)?)?;
3040-
render_attributes(w, it)?;
3040+
render_attributes(w, it, false)?;
30413041
write!(w,
30423042
"{vis}{constness}{unsafety}{asyncness}{abi}fn \
30433043
{name}{generics}{decl}{where_clause}</pre>",
@@ -3126,7 +3126,7 @@ fn item_trait(
31263126
// Output the trait definition
31273127
wrap_into_docblock(w, |w| {
31283128
write!(w, "<pre class='rust trait'>")?;
3129-
render_attributes(w, it)?;
3129+
render_attributes(w, it, true)?;
31303130
write!(w, "{}{}{}trait {}{}{}",
31313131
VisSpace(&it.visibility),
31323132
UnsafetySpace(t.unsafety),
@@ -3479,7 +3479,7 @@ fn render_assoc_item(w: &mut fmt::Formatter<'_>,
34793479
} else {
34803480
(0, true)
34813481
};
3482-
render_attributes(w, meth)?;
3482+
render_attributes(w, meth, false)?;
34833483
write!(w, "{}{}{}{}{}{}{}fn <a href='{href}' class='fnname'>{name}</a>\
34843484
{generics}{decl}{where_clause}",
34853485
if parent == ItemType::Trait { " " } else { "" },
@@ -3526,7 +3526,7 @@ fn item_struct(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
35263526
s: &clean::Struct) -> fmt::Result {
35273527
wrap_into_docblock(w, |w| {
35283528
write!(w, "<pre class='rust struct'>")?;
3529-
render_attributes(w, it)?;
3529+
render_attributes(w, it, true)?;
35303530
render_struct(w,
35313531
it,
35323532
Some(&s.generics),
@@ -3577,7 +3577,7 @@ fn item_union(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
35773577
s: &clean::Union) -> fmt::Result {
35783578
wrap_into_docblock(w, |w| {
35793579
write!(w, "<pre class='rust union'>")?;
3580-
render_attributes(w, it)?;
3580+
render_attributes(w, it, true)?;
35813581
render_union(w,
35823582
it,
35833583
Some(&s.generics),
@@ -3622,7 +3622,7 @@ fn item_enum(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
36223622
e: &clean::Enum) -> fmt::Result {
36233623
wrap_into_docblock(w, |w| {
36243624
write!(w, "<pre class='rust enum'>")?;
3625-
render_attributes(w, it)?;
3625+
render_attributes(w, it, true)?;
36263626
write!(w, "{}enum {}{}{}",
36273627
VisSpace(&it.visibility),
36283628
it.name.as_ref().unwrap(),
@@ -3783,7 +3783,7 @@ const ATTRIBUTE_WHITELIST: &'static [&'static str] = &[
37833783
"non_exhaustive"
37843784
];
37853785

3786-
fn render_attributes(w: &mut dyn fmt::Write, it: &clean::Item) -> fmt::Result {
3786+
fn render_attributes(w: &mut dyn fmt::Write, it: &clean::Item, top: bool) -> fmt::Result {
37873787
let mut attrs = String::new();
37883788

37893789
for attr in &it.attrs.other_attrs {
@@ -3795,7 +3795,8 @@ fn render_attributes(w: &mut dyn fmt::Write, it: &clean::Item) -> fmt::Result {
37953795
}
37963796
}
37973797
if attrs.len() > 0 {
3798-
write!(w, "<div class=\"docblock attributes\">{}</div>", &attrs)?;
3798+
write!(w, "<div class=\"docblock attributes{}\">{}</div>",
3799+
if top { " top-attr" } else { "" }, &attrs)?;
37993800
}
38003801
Ok(())
38013802
}
@@ -4344,7 +4345,7 @@ fn item_existential(
43444345
t: &clean::Existential,
43454346
) -> fmt::Result {
43464347
write!(w, "<pre class='rust existential'>")?;
4347-
render_attributes(w, it)?;
4348+
render_attributes(w, it, false)?;
43484349
write!(w, "existential type {}{}{where_clause}: {bounds};</pre>",
43494350
it.name.as_ref().unwrap(),
43504351
t.generics,
@@ -4363,7 +4364,7 @@ fn item_existential(
43634364
fn item_trait_alias(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
43644365
t: &clean::TraitAlias) -> fmt::Result {
43654366
write!(w, "<pre class='rust trait-alias'>")?;
4366-
render_attributes(w, it)?;
4367+
render_attributes(w, it, false)?;
43674368
write!(w, "trait {}{}{} = {};</pre>",
43684369
it.name.as_ref().unwrap(),
43694370
t.generics,
@@ -4382,7 +4383,7 @@ fn item_trait_alias(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
43824383
fn item_typedef(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
43834384
t: &clean::Typedef) -> fmt::Result {
43844385
write!(w, "<pre class='rust typedef'>")?;
4385-
render_attributes(w, it)?;
4386+
render_attributes(w, it, false)?;
43864387
write!(w, "type {}{}{where_clause} = {type_};</pre>",
43874388
it.name.as_ref().unwrap(),
43884389
t.generics,
@@ -4400,7 +4401,7 @@ fn item_typedef(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
44004401

44014402
fn item_foreign_type(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item) -> fmt::Result {
44024403
writeln!(w, "<pre class='rust foreigntype'>extern {{")?;
4403-
render_attributes(w, it)?;
4404+
render_attributes(w, it, false)?;
44044405
write!(
44054406
w,
44064407
" {}type {};\n}}</pre>",

src/librustdoc/html/static/main.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -2325,7 +2325,11 @@ if (!DOMTokenList.prototype.remove) {
23252325
}
23262326
var attributesToggle = createToggleWrapper(createSimpleToggle(false));
23272327
onEachLazy(main.getElementsByClassName("attributes"), function(i_e) {
2328-
i_e.parentNode.insertBefore(attributesToggle.cloneNode(true), i_e);
2328+
var attr_tog = attributesToggle.cloneNode(true);
2329+
if (hasClass(i_e, "top-attr") === true) {
2330+
addClass(attr_tog, "top-attr");
2331+
}
2332+
i_e.parentNode.insertBefore(attr_tog, i_e);
23292333
itemAttributesFunc(i_e);
23302334
});
23312335

src/librustdoc/html/static/rustdoc.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -1579,10 +1579,10 @@ div.name.expand::before {
15791579
}
15801580

15811581
/* This part is to fix the "Expand attributes" part in the type declaration. */
1582-
.type-decl > pre > :first-child {
1582+
.type-decl > pre > .toggle-wrapper.toggle-attributes.top-attr {
15831583
margin-left: 0 !important;
15841584
}
1585-
.type-decl > pre > :nth-child(2) {
1585+
.type-decl > pre > .docblock.attributes.top-attr {
15861586
margin-left: 1.8em !important;
15871587
}
15881588
.type-decl > pre > .toggle-attributes {

0 commit comments

Comments
 (0)