@@ -2992,7 +2992,7 @@ fn short_stability(item: &clean::Item, cx: &Context) -> Vec<String> {
29922992fn item_constant ( w : & mut fmt:: Formatter < ' _ > , cx : & Context , it : & clean:: Item ,
29932993 c : & clean:: Constant ) -> fmt:: Result {
29942994 write ! ( w, "<pre class='rust const'>" ) ?;
2995- render_attributes ( w, it) ?;
2995+ render_attributes ( w, it, false ) ?;
29962996 write ! ( w, "{vis}const \
29972997 {name}: {typ}</pre>",
29982998 vis = VisSpace ( & it. visibility) ,
@@ -3004,7 +3004,7 @@ fn item_constant(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
30043004fn item_static ( w : & mut fmt:: Formatter < ' _ > , cx : & Context , it : & clean:: Item ,
30053005 s : & clean:: Static ) -> fmt:: Result {
30063006 write ! ( w, "<pre class='rust static'>" ) ?;
3007- render_attributes ( w, it) ?;
3007+ render_attributes ( w, it, false ) ?;
30083008 write ! ( w, "{vis}static {mutability}\
30093009 {name}: {typ}</pre>",
30103010 vis = VisSpace ( & it. visibility) ,
@@ -3027,7 +3027,7 @@ fn item_function(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
30273027 f. generics
30283028 ) . len ( ) ;
30293029 write ! ( w, "{}<pre class='rust fn'>" , render_spotlight_traits( it) ?) ?;
3030- render_attributes ( w, it) ?;
3030+ render_attributes ( w, it, false ) ?;
30313031 write ! ( w,
30323032 "{vis}{constness}{unsafety}{asyncness}{abi}fn \
30333033 {name}{generics}{decl}{where_clause}</pre>",
@@ -3116,7 +3116,7 @@ fn item_trait(
31163116 // Output the trait definition
31173117 wrap_into_docblock ( w, |w| {
31183118 write ! ( w, "<pre class='rust trait'>" ) ?;
3119- render_attributes ( w, it) ?;
3119+ render_attributes ( w, it, true ) ?;
31203120 write ! ( w, "{}{}{}trait {}{}{}" ,
31213121 VisSpace ( & it. visibility) ,
31223122 UnsafetySpace ( t. unsafety) ,
@@ -3379,8 +3379,10 @@ fn assoc_const(w: &mut fmt::Formatter<'_>,
33793379 it : & clean:: Item ,
33803380 ty : & clean:: Type ,
33813381 _default : Option < & String > ,
3382- link : AssocItemLink < ' _ > ) -> fmt:: Result {
3383- write ! ( w, "{}const <a href='{}' class=\" constant\" ><b>{}</b></a>: {}" ,
3382+ link : AssocItemLink < ' _ > ,
3383+ extra : & str ) -> fmt:: Result {
3384+ write ! ( w, "{}{}const <a href='{}' class=\" constant\" ><b>{}</b></a>: {}" ,
3385+ extra,
33843386 VisSpace ( & it. visibility) ,
33853387 naive_assoc_href( it, link) ,
33863388 it. name. as_ref( ) . unwrap( ) ,
@@ -3391,8 +3393,10 @@ fn assoc_const(w: &mut fmt::Formatter<'_>,
33913393fn assoc_type < W : fmt:: Write > ( w : & mut W , it : & clean:: Item ,
33923394 bounds : & [ clean:: GenericBound ] ,
33933395 default : Option < & clean:: Type > ,
3394- link : AssocItemLink < ' _ > ) -> fmt:: Result {
3395- write ! ( w, "type <a href='{}' class=\" type\" >{}</a>" ,
3396+ link : AssocItemLink < ' _ > ,
3397+ extra : & str ) -> fmt:: Result {
3398+ write ! ( w, "{}type <a href='{}' class=\" type\" >{}</a>" ,
3399+ extra,
33963400 naive_assoc_href( it, link) ,
33973401 it. name. as_ref( ) . unwrap( ) ) ?;
33983402 if !bounds. is_empty ( ) {
@@ -3469,7 +3473,7 @@ fn render_assoc_item(w: &mut fmt::Formatter<'_>,
34693473 } else {
34703474 ( 0 , true )
34713475 } ;
3472- render_attributes ( w, meth) ?;
3476+ render_attributes ( w, meth, false ) ?;
34733477 write ! ( w, "{}{}{}{}{}{}{}fn <a href='{href}' class='fnname'>{name}</a>\
34743478 {generics}{decl}{where_clause}",
34753479 if parent == ItemType :: Trait { " " } else { "" } ,
@@ -3503,10 +3507,12 @@ fn render_assoc_item(w: &mut fmt::Formatter<'_>,
35033507 method ( w, item, m. header , & m. generics , & m. decl , link, parent)
35043508 }
35053509 clean:: AssociatedConstItem ( ref ty, ref default) => {
3506- assoc_const ( w, item, ty, default. as_ref ( ) , link)
3510+ assoc_const ( w, item, ty, default. as_ref ( ) , link,
3511+ if parent == ItemType :: Trait { " " } else { "" } )
35073512 }
35083513 clean:: AssociatedTypeItem ( ref bounds, ref default) => {
3509- assoc_type ( w, item, bounds, default. as_ref ( ) , link)
3514+ assoc_type ( w, item, bounds, default. as_ref ( ) , link,
3515+ if parent == ItemType :: Trait { " " } else { "" } )
35103516 }
35113517 _ => panic ! ( "render_assoc_item called on non-associated-item" )
35123518 }
@@ -3516,7 +3522,7 @@ fn item_struct(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
35163522 s : & clean:: Struct ) -> fmt:: Result {
35173523 wrap_into_docblock ( w, |w| {
35183524 write ! ( w, "<pre class='rust struct'>" ) ?;
3519- render_attributes ( w, it) ?;
3525+ render_attributes ( w, it, true ) ?;
35203526 render_struct ( w,
35213527 it,
35223528 Some ( & s. generics ) ,
@@ -3567,7 +3573,7 @@ fn item_union(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
35673573 s : & clean:: Union ) -> fmt:: Result {
35683574 wrap_into_docblock ( w, |w| {
35693575 write ! ( w, "<pre class='rust union'>" ) ?;
3570- render_attributes ( w, it) ?;
3576+ render_attributes ( w, it, true ) ?;
35713577 render_union ( w,
35723578 it,
35733579 Some ( & s. generics ) ,
@@ -3612,7 +3618,7 @@ fn item_enum(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
36123618 e : & clean:: Enum ) -> fmt:: Result {
36133619 wrap_into_docblock ( w, |w| {
36143620 write ! ( w, "<pre class='rust enum'>" ) ?;
3615- render_attributes ( w, it) ?;
3621+ render_attributes ( w, it, true ) ?;
36163622 write ! ( w, "{}enum {}{}{}" ,
36173623 VisSpace ( & it. visibility) ,
36183624 it. name. as_ref( ) . unwrap( ) ,
@@ -3773,7 +3779,15 @@ const ATTRIBUTE_WHITELIST: &'static [Symbol] = &[
37733779 sym:: non_exhaustive
37743780] ;
37753781
3776- fn render_attributes ( w : & mut dyn fmt:: Write , it : & clean:: Item ) -> fmt:: Result {
3782+ // The `top` parameter is used when generating the item declaration to ensure it doesn't have a
3783+ // left padding. For example:
3784+ //
3785+ // #[foo] <----- "top" attribute
3786+ // struct Foo {
3787+ // #[bar] <---- not "top" attribute
3788+ // bar: usize,
3789+ // }
3790+ fn render_attributes ( w : & mut dyn fmt:: Write , it : & clean:: Item , top : bool ) -> fmt:: Result {
37773791 let mut attrs = String :: new ( ) ;
37783792
37793793 for attr in & it. attrs . other_attrs {
@@ -3785,7 +3799,8 @@ fn render_attributes(w: &mut dyn fmt::Write, it: &clean::Item) -> fmt::Result {
37853799 }
37863800 }
37873801 if attrs. len ( ) > 0 {
3788- write ! ( w, "<div class=\" docblock attributes\" >{}</div>" , & attrs) ?;
3802+ write ! ( w, "<div class=\" docblock attributes{}\" >{}</div>" ,
3803+ if top { " top-attr" } else { "" } , & attrs) ?;
37893804 }
37903805 Ok ( ( ) )
37913806}
@@ -4118,7 +4133,8 @@ fn spotlight_decl(decl: &clean::FnDecl) -> Result<String, fmt::Error> {
41184133 out. push_str ( "<span class=\" where fmt-newline\" > " ) ;
41194134 assoc_type ( & mut out, it, & [ ] ,
41204135 Some ( & tydef. type_ ) ,
4121- AssocItemLink :: GotoSource ( t_did, & FxHashSet :: default ( ) ) ) ?;
4136+ AssocItemLink :: GotoSource ( t_did, & FxHashSet :: default ( ) ) ,
4137+ "" ) ?;
41224138 out. push_str ( ";</span>" ) ;
41234139 }
41244140 }
@@ -4158,7 +4174,8 @@ fn render_impl(w: &mut fmt::Formatter<'_>, cx: &Context, i: &Impl, link: AssocIt
41584174 if let clean:: TypedefItem ( ref tydef, _) = it. inner {
41594175 write ! ( w, "<span class=\" where fmt-newline\" > " ) ?;
41604176 assoc_type ( w, it, & vec ! [ ] , Some ( & tydef. type_ ) ,
4161- AssocItemLink :: Anchor ( None ) ) ?;
4177+ AssocItemLink :: Anchor ( None ) ,
4178+ "" ) ?;
41624179 write ! ( w, ";</span>" ) ?;
41634180 }
41644181 }
@@ -4228,15 +4245,15 @@ fn render_impl(w: &mut fmt::Formatter<'_>, cx: &Context, i: &Impl, link: AssocIt
42284245 let ns_id = cx. derive_id ( format ! ( "{}.{}" , name, item_type. name_space( ) ) ) ;
42294246 write ! ( w, "<h4 id='{}' class=\" {}{}\" >" , id, item_type, extra_class) ?;
42304247 write ! ( w, "<code id='{}'>" , ns_id) ?;
4231- assoc_type ( w, item, & Vec :: new ( ) , Some ( & tydef. type_ ) , link. anchor ( & id) ) ?;
4248+ assoc_type ( w, item, & Vec :: new ( ) , Some ( & tydef. type_ ) , link. anchor ( & id) , "" ) ?;
42324249 write ! ( w, "</code></h4>" ) ?;
42334250 }
42344251 clean:: AssociatedConstItem ( ref ty, ref default) => {
42354252 let id = cx. derive_id ( format ! ( "{}.{}" , item_type, name) ) ;
42364253 let ns_id = cx. derive_id ( format ! ( "{}.{}" , name, item_type. name_space( ) ) ) ;
42374254 write ! ( w, "<h4 id='{}' class=\" {}{}\" >" , id, item_type, extra_class) ?;
42384255 write ! ( w, "<code id='{}'>" , ns_id) ?;
4239- assoc_const ( w, item, ty, default. as_ref ( ) , link. anchor ( & id) ) ?;
4256+ assoc_const ( w, item, ty, default. as_ref ( ) , link. anchor ( & id) , "" ) ?;
42404257 write ! ( w, "</code>" ) ?;
42414258 render_stability_since_raw ( w, item. stable_since ( ) , outer_version) ?;
42424259 if let Some ( l) = ( Item { cx, item } ) . src_href ( ) {
@@ -4250,7 +4267,7 @@ fn render_impl(w: &mut fmt::Formatter<'_>, cx: &Context, i: &Impl, link: AssocIt
42504267 let ns_id = cx. derive_id ( format ! ( "{}.{}" , name, item_type. name_space( ) ) ) ;
42514268 write ! ( w, "<h4 id='{}' class=\" {}{}\" >" , id, item_type, extra_class) ?;
42524269 write ! ( w, "<code id='{}'>" , ns_id) ?;
4253- assoc_type ( w, item, bounds, default. as_ref ( ) , link. anchor ( & id) ) ?;
4270+ assoc_type ( w, item, bounds, default. as_ref ( ) , link. anchor ( & id) , "" ) ?;
42544271 write ! ( w, "</code></h4>" ) ?;
42554272 }
42564273 clean:: StrippedItem ( ..) => return Ok ( ( ) ) ,
@@ -4338,7 +4355,7 @@ fn item_existential(
43384355 t : & clean:: Existential ,
43394356) -> fmt:: Result {
43404357 write ! ( w, "<pre class='rust existential'>" ) ?;
4341- render_attributes ( w, it) ?;
4358+ render_attributes ( w, it, false ) ?;
43424359 write ! ( w, "existential type {}{}{where_clause}: {bounds};</pre>" ,
43434360 it. name. as_ref( ) . unwrap( ) ,
43444361 t. generics,
@@ -4357,7 +4374,7 @@ fn item_existential(
43574374fn item_trait_alias ( w : & mut fmt:: Formatter < ' _ > , cx : & Context , it : & clean:: Item ,
43584375 t : & clean:: TraitAlias ) -> fmt:: Result {
43594376 write ! ( w, "<pre class='rust trait-alias'>" ) ?;
4360- render_attributes ( w, it) ?;
4377+ render_attributes ( w, it, false ) ?;
43614378 write ! ( w, "trait {}{}{} = {};</pre>" ,
43624379 it. name. as_ref( ) . unwrap( ) ,
43634380 t. generics,
@@ -4376,7 +4393,7 @@ fn item_trait_alias(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
43764393fn item_typedef ( w : & mut fmt:: Formatter < ' _ > , cx : & Context , it : & clean:: Item ,
43774394 t : & clean:: Typedef ) -> fmt:: Result {
43784395 write ! ( w, "<pre class='rust typedef'>" ) ?;
4379- render_attributes ( w, it) ?;
4396+ render_attributes ( w, it, false ) ?;
43804397 write ! ( w, "type {}{}{where_clause} = {type_};</pre>" ,
43814398 it. name. as_ref( ) . unwrap( ) ,
43824399 t. generics,
@@ -4394,7 +4411,7 @@ fn item_typedef(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
43944411
43954412fn item_foreign_type ( w : & mut fmt:: Formatter < ' _ > , cx : & Context , it : & clean:: Item ) -> fmt:: Result {
43964413 writeln ! ( w, "<pre class='rust foreigntype'>extern {{" ) ?;
4397- render_attributes ( w, it) ?;
4414+ render_attributes ( w, it, false ) ?;
43984415 write ! (
43994416 w,
44004417 " {}type {};\n }}</pre>" ,
0 commit comments