@@ -2492,16 +2492,48 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
2492
2492
Ok ( ( ) )
2493
2493
}
2494
2494
2495
+ fn attribute_without_value ( s : & str ) -> bool {
2496
+ vec ! ( "must_use" , "no_mangle" , "unsafe_destructor_blind_to_params" ) . iter ( ) . any ( |x| x == & s)
2497
+ }
2498
+
2499
+ fn attribute_with_value ( s : & str ) -> bool {
2500
+ vec ! ( "export_name" , "lang" , "link_section" , "must_use" ) . iter ( ) . any ( |x| x == & s)
2501
+ }
2502
+
2503
+ fn attribute_with_values ( s : & str ) -> bool {
2504
+ vec ! ( "repr" ) . iter ( ) . any ( |x| x == & s)
2505
+ }
2506
+
2507
+ fn render_attribute ( attr : & clean:: Attribute , recurse : bool ) -> String {
2508
+ match * attr {
2509
+ clean:: Word ( ref s) if attribute_without_value ( & * s) || recurse => {
2510
+ format ! ( "{}" , s)
2511
+ }
2512
+ clean:: NameValue ( ref k, ref v) if attribute_with_value ( & * k) => {
2513
+ format ! ( "{} = \" {}\" " , k, v)
2514
+ }
2515
+ clean:: List ( ref k, ref values) if attribute_with_values ( & * k) => {
2516
+ let mut display = Vec :: new ( ) ;
2517
+
2518
+ for value in values {
2519
+ let s = render_attribute ( value, true ) ;
2520
+ if s. len ( ) > 0 {
2521
+ display. push ( format ! ( "{}" , s) ) ;
2522
+ }
2523
+ }
2524
+ format ! ( "{}({})" , k, display. join( ", " ) )
2525
+ }
2526
+ _ => {
2527
+ String :: new ( )
2528
+ }
2529
+ }
2530
+ }
2531
+
2495
2532
fn render_attributes ( w : & mut fmt:: Formatter , it : & clean:: Item ) -> fmt:: Result {
2496
2533
for attr in & it. attrs {
2497
- match * attr {
2498
- clean:: Word ( ref s) if * s == "must_use" => {
2499
- write ! ( w, "#[{}]\n " , s) ?;
2500
- }
2501
- clean:: NameValue ( ref k, ref v) if * k == "must_use" => {
2502
- write ! ( w, "#[{} = \" {}\" ]\n " , k, v) ?;
2503
- }
2504
- _ => ( )
2534
+ let s = render_attribute ( attr, false ) ;
2535
+ if s. len ( ) > 0 {
2536
+ write ! ( w, "#[{}]\n " , s) ?;
2505
2537
}
2506
2538
}
2507
2539
Ok ( ( ) )
0 commit comments