Skip to content

Commit

Permalink
Fixes attributes position in types decl
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Apr 17, 2019
1 parent 464473a commit 5971266
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
29 changes: 15 additions & 14 deletions src/librustdoc/html/render.rs
Expand Up @@ -3002,7 +3002,7 @@ fn short_stability(item: &clean::Item, cx: &Context) -> Vec<String> {
fn item_constant(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
c: &clean::Constant) -> fmt::Result {
write!(w, "<pre class='rust const'>")?;
render_attributes(w, it)?;
render_attributes(w, it, false)?;
write!(w, "{vis}const \
{name}: {typ}</pre>",
vis = VisSpace(&it.visibility),
Expand All @@ -3014,7 +3014,7 @@ fn item_constant(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
fn item_static(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
s: &clean::Static) -> fmt::Result {
write!(w, "<pre class='rust static'>")?;
render_attributes(w, it)?;
render_attributes(w, it, false)?;
write!(w, "{vis}static {mutability}\
{name}: {typ}</pre>",
vis = VisSpace(&it.visibility),
Expand All @@ -3037,7 +3037,7 @@ fn item_function(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
f.generics
).len();
write!(w, "{}<pre class='rust fn'>", render_spotlight_traits(it)?)?;
render_attributes(w, it)?;
render_attributes(w, it, false)?;
write!(w,
"{vis}{constness}{unsafety}{asyncness}{abi}fn \
{name}{generics}{decl}{where_clause}</pre>",
Expand Down Expand Up @@ -3126,7 +3126,7 @@ fn item_trait(
// Output the trait definition
wrap_into_docblock(w, |w| {
write!(w, "<pre class='rust trait'>")?;
render_attributes(w, it)?;
render_attributes(w, it, true)?;
write!(w, "{}{}{}trait {}{}{}",
VisSpace(&it.visibility),
UnsafetySpace(t.unsafety),
Expand Down Expand Up @@ -3479,7 +3479,7 @@ fn render_assoc_item(w: &mut fmt::Formatter<'_>,
} else {
(0, true)
};
render_attributes(w, meth)?;
render_attributes(w, meth, false)?;
write!(w, "{}{}{}{}{}{}{}fn <a href='{href}' class='fnname'>{name}</a>\
{generics}{decl}{where_clause}",
if parent == ItemType::Trait { " " } else { "" },
Expand Down Expand Up @@ -3526,7 +3526,7 @@ fn item_struct(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
s: &clean::Struct) -> fmt::Result {
wrap_into_docblock(w, |w| {
write!(w, "<pre class='rust struct'>")?;
render_attributes(w, it)?;
render_attributes(w, it, true)?;
render_struct(w,
it,
Some(&s.generics),
Expand Down Expand Up @@ -3577,7 +3577,7 @@ fn item_union(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
s: &clean::Union) -> fmt::Result {
wrap_into_docblock(w, |w| {
write!(w, "<pre class='rust union'>")?;
render_attributes(w, it)?;
render_attributes(w, it, true)?;
render_union(w,
it,
Some(&s.generics),
Expand Down Expand Up @@ -3622,7 +3622,7 @@ fn item_enum(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
e: &clean::Enum) -> fmt::Result {
wrap_into_docblock(w, |w| {
write!(w, "<pre class='rust enum'>")?;
render_attributes(w, it)?;
render_attributes(w, it, true)?;
write!(w, "{}enum {}{}{}",
VisSpace(&it.visibility),
it.name.as_ref().unwrap(),
Expand Down Expand Up @@ -3783,7 +3783,7 @@ const ATTRIBUTE_WHITELIST: &'static [&'static str] = &[
"non_exhaustive"
];

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

for attr in &it.attrs.other_attrs {
Expand All @@ -3795,7 +3795,8 @@ fn render_attributes(w: &mut dyn fmt::Write, it: &clean::Item) -> fmt::Result {
}
}
if attrs.len() > 0 {
write!(w, "<div class=\"docblock attributes\">{}</div>", &attrs)?;
write!(w, "<div class=\"docblock attributes{}\">{}</div>",
if top { " top-attr" } else { "" }, &attrs)?;
}
Ok(())
}
Expand Down Expand Up @@ -4344,7 +4345,7 @@ fn item_existential(
t: &clean::Existential,
) -> fmt::Result {
write!(w, "<pre class='rust existential'>")?;
render_attributes(w, it)?;
render_attributes(w, it, false)?;
write!(w, "existential type {}{}{where_clause}: {bounds};</pre>",
it.name.as_ref().unwrap(),
t.generics,
Expand All @@ -4363,7 +4364,7 @@ fn item_existential(
fn item_trait_alias(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
t: &clean::TraitAlias) -> fmt::Result {
write!(w, "<pre class='rust trait-alias'>")?;
render_attributes(w, it)?;
render_attributes(w, it, false)?;
write!(w, "trait {}{}{} = {};</pre>",
it.name.as_ref().unwrap(),
t.generics,
Expand All @@ -4382,7 +4383,7 @@ fn item_trait_alias(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
fn item_typedef(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
t: &clean::Typedef) -> fmt::Result {
write!(w, "<pre class='rust typedef'>")?;
render_attributes(w, it)?;
render_attributes(w, it, false)?;
write!(w, "type {}{}{where_clause} = {type_};</pre>",
it.name.as_ref().unwrap(),
t.generics,
Expand All @@ -4400,7 +4401,7 @@ fn item_typedef(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,

fn item_foreign_type(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item) -> fmt::Result {
writeln!(w, "<pre class='rust foreigntype'>extern {{")?;
render_attributes(w, it)?;
render_attributes(w, it, false)?;
write!(
w,
" {}type {};\n}}</pre>",
Expand Down
6 changes: 5 additions & 1 deletion src/librustdoc/html/static/main.js
Expand Up @@ -2325,7 +2325,11 @@ if (!DOMTokenList.prototype.remove) {
}
var attributesToggle = createToggleWrapper(createSimpleToggle(false));
onEachLazy(main.getElementsByClassName("attributes"), function(i_e) {
i_e.parentNode.insertBefore(attributesToggle.cloneNode(true), i_e);
var attr_tog = attributesToggle.cloneNode(true);
if (hasClass(i_e, "top-attr") === true) {
addClass(attr_tog, "top-attr");
}
i_e.parentNode.insertBefore(attr_tog, i_e);
itemAttributesFunc(i_e);
});

Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/static/rustdoc.css
Expand Up @@ -1579,10 +1579,10 @@ div.name.expand::before {
}

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

0 comments on commit 5971266

Please sign in to comment.