@@ -2992,7 +2992,7 @@ fn short_stability(item: &clean::Item, cx: &Context) -> Vec<String> {
2992
2992
fn item_constant ( w : & mut fmt:: Formatter < ' _ > , cx : & Context , it : & clean:: Item ,
2993
2993
c : & clean:: Constant ) -> fmt:: Result {
2994
2994
write ! ( w, "<pre class='rust const'>" ) ?;
2995
- render_attributes ( w, it) ?;
2995
+ render_attributes ( w, it, false ) ?;
2996
2996
write ! ( w, "{vis}const \
2997
2997
{name}: {typ}</pre>",
2998
2998
vis = VisSpace ( & it. visibility) ,
@@ -3004,7 +3004,7 @@ fn item_constant(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
3004
3004
fn item_static ( w : & mut fmt:: Formatter < ' _ > , cx : & Context , it : & clean:: Item ,
3005
3005
s : & clean:: Static ) -> fmt:: Result {
3006
3006
write ! ( w, "<pre class='rust static'>" ) ?;
3007
- render_attributes ( w, it) ?;
3007
+ render_attributes ( w, it, false ) ?;
3008
3008
write ! ( w, "{vis}static {mutability}\
3009
3009
{name}: {typ}</pre>",
3010
3010
vis = VisSpace ( & it. visibility) ,
@@ -3027,7 +3027,7 @@ fn item_function(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
3027
3027
f. generics
3028
3028
) . len ( ) ;
3029
3029
write ! ( w, "{}<pre class='rust fn'>" , render_spotlight_traits( it) ?) ?;
3030
- render_attributes ( w, it) ?;
3030
+ render_attributes ( w, it, false ) ?;
3031
3031
write ! ( w,
3032
3032
"{vis}{constness}{unsafety}{asyncness}{abi}fn \
3033
3033
{name}{generics}{decl}{where_clause}</pre>",
@@ -3116,7 +3116,7 @@ fn item_trait(
3116
3116
// Output the trait definition
3117
3117
wrap_into_docblock ( w, |w| {
3118
3118
write ! ( w, "<pre class='rust trait'>" ) ?;
3119
- render_attributes ( w, it) ?;
3119
+ render_attributes ( w, it, true ) ?;
3120
3120
write ! ( w, "{}{}{}trait {}{}{}" ,
3121
3121
VisSpace ( & it. visibility) ,
3122
3122
UnsafetySpace ( t. unsafety) ,
@@ -3379,8 +3379,10 @@ fn assoc_const(w: &mut fmt::Formatter<'_>,
3379
3379
it : & clean:: Item ,
3380
3380
ty : & clean:: Type ,
3381
3381
_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,
3384
3386
VisSpace ( & it. visibility) ,
3385
3387
naive_assoc_href( it, link) ,
3386
3388
it. name. as_ref( ) . unwrap( ) ,
@@ -3391,8 +3393,10 @@ fn assoc_const(w: &mut fmt::Formatter<'_>,
3391
3393
fn assoc_type < W : fmt:: Write > ( w : & mut W , it : & clean:: Item ,
3392
3394
bounds : & [ clean:: GenericBound ] ,
3393
3395
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,
3396
3400
naive_assoc_href( it, link) ,
3397
3401
it. name. as_ref( ) . unwrap( ) ) ?;
3398
3402
if !bounds. is_empty ( ) {
@@ -3469,7 +3473,7 @@ fn render_assoc_item(w: &mut fmt::Formatter<'_>,
3469
3473
} else {
3470
3474
( 0 , true )
3471
3475
} ;
3472
- render_attributes ( w, meth) ?;
3476
+ render_attributes ( w, meth, false ) ?;
3473
3477
write ! ( w, "{}{}{}{}{}{}{}fn <a href='{href}' class='fnname'>{name}</a>\
3474
3478
{generics}{decl}{where_clause}",
3475
3479
if parent == ItemType :: Trait { " " } else { "" } ,
@@ -3503,10 +3507,12 @@ fn render_assoc_item(w: &mut fmt::Formatter<'_>,
3503
3507
method ( w, item, m. header , & m. generics , & m. decl , link, parent)
3504
3508
}
3505
3509
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 { "" } )
3507
3512
}
3508
3513
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 { "" } )
3510
3516
}
3511
3517
_ => panic ! ( "render_assoc_item called on non-associated-item" )
3512
3518
}
@@ -3516,7 +3522,7 @@ fn item_struct(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
3516
3522
s : & clean:: Struct ) -> fmt:: Result {
3517
3523
wrap_into_docblock ( w, |w| {
3518
3524
write ! ( w, "<pre class='rust struct'>" ) ?;
3519
- render_attributes ( w, it) ?;
3525
+ render_attributes ( w, it, true ) ?;
3520
3526
render_struct ( w,
3521
3527
it,
3522
3528
Some ( & s. generics ) ,
@@ -3567,7 +3573,7 @@ fn item_union(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
3567
3573
s : & clean:: Union ) -> fmt:: Result {
3568
3574
wrap_into_docblock ( w, |w| {
3569
3575
write ! ( w, "<pre class='rust union'>" ) ?;
3570
- render_attributes ( w, it) ?;
3576
+ render_attributes ( w, it, true ) ?;
3571
3577
render_union ( w,
3572
3578
it,
3573
3579
Some ( & s. generics ) ,
@@ -3612,7 +3618,7 @@ fn item_enum(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
3612
3618
e : & clean:: Enum ) -> fmt:: Result {
3613
3619
wrap_into_docblock ( w, |w| {
3614
3620
write ! ( w, "<pre class='rust enum'>" ) ?;
3615
- render_attributes ( w, it) ?;
3621
+ render_attributes ( w, it, true ) ?;
3616
3622
write ! ( w, "{}enum {}{}{}" ,
3617
3623
VisSpace ( & it. visibility) ,
3618
3624
it. name. as_ref( ) . unwrap( ) ,
@@ -3773,7 +3779,15 @@ const ATTRIBUTE_WHITELIST: &'static [Symbol] = &[
3773
3779
sym:: non_exhaustive
3774
3780
] ;
3775
3781
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 {
3777
3791
let mut attrs = String :: new ( ) ;
3778
3792
3779
3793
for attr in & it. attrs . other_attrs {
@@ -3785,7 +3799,8 @@ fn render_attributes(w: &mut dyn fmt::Write, it: &clean::Item) -> fmt::Result {
3785
3799
}
3786
3800
}
3787
3801
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) ?;
3789
3804
}
3790
3805
Ok ( ( ) )
3791
3806
}
@@ -4118,7 +4133,8 @@ fn spotlight_decl(decl: &clean::FnDecl) -> Result<String, fmt::Error> {
4118
4133
out. push_str ( "<span class=\" where fmt-newline\" > " ) ;
4119
4134
assoc_type ( & mut out, it, & [ ] ,
4120
4135
Some ( & tydef. type_ ) ,
4121
- AssocItemLink :: GotoSource ( t_did, & FxHashSet :: default ( ) ) ) ?;
4136
+ AssocItemLink :: GotoSource ( t_did, & FxHashSet :: default ( ) ) ,
4137
+ "" ) ?;
4122
4138
out. push_str ( ";</span>" ) ;
4123
4139
}
4124
4140
}
@@ -4158,7 +4174,8 @@ fn render_impl(w: &mut fmt::Formatter<'_>, cx: &Context, i: &Impl, link: AssocIt
4158
4174
if let clean:: TypedefItem ( ref tydef, _) = it. inner {
4159
4175
write ! ( w, "<span class=\" where fmt-newline\" > " ) ?;
4160
4176
assoc_type ( w, it, & vec ! [ ] , Some ( & tydef. type_ ) ,
4161
- AssocItemLink :: Anchor ( None ) ) ?;
4177
+ AssocItemLink :: Anchor ( None ) ,
4178
+ "" ) ?;
4162
4179
write ! ( w, ";</span>" ) ?;
4163
4180
}
4164
4181
}
@@ -4228,15 +4245,15 @@ fn render_impl(w: &mut fmt::Formatter<'_>, cx: &Context, i: &Impl, link: AssocIt
4228
4245
let ns_id = cx. derive_id ( format ! ( "{}.{}" , name, item_type. name_space( ) ) ) ;
4229
4246
write ! ( w, "<h4 id='{}' class=\" {}{}\" >" , id, item_type, extra_class) ?;
4230
4247
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) , "" ) ?;
4232
4249
write ! ( w, "</code></h4>" ) ?;
4233
4250
}
4234
4251
clean:: AssociatedConstItem ( ref ty, ref default) => {
4235
4252
let id = cx. derive_id ( format ! ( "{}.{}" , item_type, name) ) ;
4236
4253
let ns_id = cx. derive_id ( format ! ( "{}.{}" , name, item_type. name_space( ) ) ) ;
4237
4254
write ! ( w, "<h4 id='{}' class=\" {}{}\" >" , id, item_type, extra_class) ?;
4238
4255
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) , "" ) ?;
4240
4257
write ! ( w, "</code>" ) ?;
4241
4258
render_stability_since_raw ( w, item. stable_since ( ) , outer_version) ?;
4242
4259
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
4250
4267
let ns_id = cx. derive_id ( format ! ( "{}.{}" , name, item_type. name_space( ) ) ) ;
4251
4268
write ! ( w, "<h4 id='{}' class=\" {}{}\" >" , id, item_type, extra_class) ?;
4252
4269
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) , "" ) ?;
4254
4271
write ! ( w, "</code></h4>" ) ?;
4255
4272
}
4256
4273
clean:: StrippedItem ( ..) => return Ok ( ( ) ) ,
@@ -4338,7 +4355,7 @@ fn item_existential(
4338
4355
t : & clean:: Existential ,
4339
4356
) -> fmt:: Result {
4340
4357
write ! ( w, "<pre class='rust existential'>" ) ?;
4341
- render_attributes ( w, it) ?;
4358
+ render_attributes ( w, it, false ) ?;
4342
4359
write ! ( w, "existential type {}{}{where_clause}: {bounds};</pre>" ,
4343
4360
it. name. as_ref( ) . unwrap( ) ,
4344
4361
t. generics,
@@ -4357,7 +4374,7 @@ fn item_existential(
4357
4374
fn item_trait_alias ( w : & mut fmt:: Formatter < ' _ > , cx : & Context , it : & clean:: Item ,
4358
4375
t : & clean:: TraitAlias ) -> fmt:: Result {
4359
4376
write ! ( w, "<pre class='rust trait-alias'>" ) ?;
4360
- render_attributes ( w, it) ?;
4377
+ render_attributes ( w, it, false ) ?;
4361
4378
write ! ( w, "trait {}{}{} = {};</pre>" ,
4362
4379
it. name. as_ref( ) . unwrap( ) ,
4363
4380
t. generics,
@@ -4376,7 +4393,7 @@ fn item_trait_alias(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
4376
4393
fn item_typedef ( w : & mut fmt:: Formatter < ' _ > , cx : & Context , it : & clean:: Item ,
4377
4394
t : & clean:: Typedef ) -> fmt:: Result {
4378
4395
write ! ( w, "<pre class='rust typedef'>" ) ?;
4379
- render_attributes ( w, it) ?;
4396
+ render_attributes ( w, it, false ) ?;
4380
4397
write ! ( w, "type {}{}{where_clause} = {type_};</pre>" ,
4381
4398
it. name. as_ref( ) . unwrap( ) ,
4382
4399
t. generics,
@@ -4394,7 +4411,7 @@ fn item_typedef(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item,
4394
4411
4395
4412
fn item_foreign_type ( w : & mut fmt:: Formatter < ' _ > , cx : & Context , it : & clean:: Item ) -> fmt:: Result {
4396
4413
writeln ! ( w, "<pre class='rust foreigntype'>extern {{" ) ?;
4397
- render_attributes ( w, it) ?;
4414
+ render_attributes ( w, it, false ) ?;
4398
4415
write ! (
4399
4416
w,
4400
4417
" {}type {};\n }}</pre>" ,
0 commit comments