Skip to content

Commit 825a11e

Browse files
Fix attributes position in type declaration
1 parent 2002b4b commit 825a11e

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/librustdoc/html/render.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -3117,23 +3117,20 @@ fn item_trait(
31173117
// FIXME: we should be using a derived_id for the Anchors here
31183118
write!(w, "{{\n")?;
31193119
for t in &types {
3120-
write!(w, " ")?;
31213120
render_assoc_item(w, t, AssocItemLink::Anchor(None), ItemType::Trait)?;
31223121
write!(w, ";\n")?;
31233122
}
31243123
if !types.is_empty() && !consts.is_empty() {
31253124
w.write_str("\n")?;
31263125
}
31273126
for t in &consts {
3128-
write!(w, " ")?;
31293127
render_assoc_item(w, t, AssocItemLink::Anchor(None), ItemType::Trait)?;
31303128
write!(w, ";\n")?;
31313129
}
31323130
if !consts.is_empty() && !required.is_empty() {
31333131
w.write_str("\n")?;
31343132
}
31353133
for (pos, m) in required.iter().enumerate() {
3136-
write!(w, " ")?;
31373134
render_assoc_item(w, m, AssocItemLink::Anchor(None), ItemType::Trait)?;
31383135
write!(w, ";\n")?;
31393136

@@ -3145,7 +3142,6 @@ fn item_trait(
31453142
w.write_str("\n")?;
31463143
}
31473144
for (pos, m) in provided.iter().enumerate() {
3148-
write!(w, " ")?;
31493145
render_assoc_item(w, m, AssocItemLink::Anchor(None), ItemType::Trait)?;
31503146
match m.inner {
31513147
clean::MethodItem(ref inner) if !inner.generics.where_predicates.is_empty() => {
@@ -3454,8 +3450,9 @@ fn render_assoc_item(w: &mut fmt::Formatter<'_>,
34543450
(0, true)
34553451
};
34563452
render_attributes(w, meth)?;
3457-
write!(w, "{}{}{}{}{}{}fn <a href='{href}' class='fnname'>{name}</a>\
3453+
write!(w, "{}{}{}{}{}{}{}fn <a href='{href}' class='fnname'>{name}</a>\
34583454
{generics}{decl}{where_clause}",
3455+
if parent == ItemType::Trait { " " } else { "" },
34593456
VisSpace(&meth.visibility),
34603457
ConstnessSpace(header.constness),
34613458
UnsafetySpace(header.unsafety),
@@ -3755,7 +3752,7 @@ const ATTRIBUTE_WHITELIST: &'static [&'static str] = &[
37553752
"non_exhaustive"
37563753
];
37573754

3758-
fn render_attributes(w: &mut fmt::Formatter<'_>, it: &clean::Item) -> fmt::Result {
3755+
fn render_attributes(w: &mut dyn fmt::Write, it: &clean::Item) -> fmt::Result {
37593756
let mut attrs = String::new();
37603757

37613758
for attr in &it.attrs.other_attrs {

src/librustdoc/html/static/rustdoc.css

+14
Original file line numberDiff line numberDiff line change
@@ -1577,3 +1577,17 @@ div.name.expand::before {
15771577
left: -15px;
15781578
top: 2px;
15791579
}
1580+
1581+
/* This part is to fix the "Expand attributes" part in the type declaration. */
1582+
.type-decl > pre > :first-child {
1583+
margin-left: 0 !important;
1584+
}
1585+
.type-decl > pre > :nth-child(2) {
1586+
margin-left: 1.8em !important;
1587+
}
1588+
.type-decl > pre > .toggle-attributes {
1589+
margin-left: 2.2em;
1590+
}
1591+
.type-decl > pre > .docblock.attributes {
1592+
margin-left: 4em;
1593+
}

0 commit comments

Comments
 (0)