File tree Expand file tree Collapse file tree 3 files changed +28
-12
lines changed Expand file tree Collapse file tree 3 files changed +28
-12
lines changed Original file line number Diff line number Diff line change @@ -113,17 +113,10 @@ impl Spanned for ast::Param {
113113
114114impl Spanned for ast:: GenericParam {
115115 fn span ( & self ) -> Span {
116- let lo = if let ast:: GenericParamKind :: Const {
117- ty : _,
118- kw_span,
119- default : _,
120- } = self . kind
121- {
122- kw_span. lo ( )
123- } else if self . attrs . is_empty ( ) {
124- self . ident . span . lo ( )
125- } else {
126- self . attrs [ 0 ] . span . lo ( )
116+ let lo = match self . kind {
117+ _ if !self . attrs . is_empty ( ) => self . attrs [ 0 ] . span . lo ( ) ,
118+ ast:: GenericParamKind :: Const { kw_span, .. } => kw_span. lo ( ) ,
119+ _ => self . ident . span . lo ( ) ,
127120 } ;
128121 let hi = if self . bounds . is_empty ( ) {
129122 self . ident . span . hi ( )
Original file line number Diff line number Diff line change @@ -575,7 +575,16 @@ impl Rewrite for ast::GenericParam {
575575 let mut result = String :: with_capacity ( 128 ) ;
576576 // FIXME: If there are more than one attributes, this will force multiline.
577577 match self . attrs . rewrite ( context, shape) {
578- Some ( ref rw) if !rw. is_empty ( ) => result. push_str ( & format ! ( "{} " , rw) ) ,
578+ Some ( ref rw) if !rw. is_empty ( ) => {
579+ result. push_str ( rw) ;
580+ // When rewriting generic params, an extra newline should be put
581+ // if the attributes end with a doc comment
582+ if let Some ( true ) = self . attrs . last ( ) . map ( |a| a. is_doc_comment ( ) ) {
583+ result. push_str ( & shape. indent . to_string_with_newline ( context. config ) ) ;
584+ } else {
585+ result. push ( ' ' ) ;
586+ }
587+ }
579588 _ => ( ) ,
580589 }
581590
Original file line number Diff line number Diff line change 1+ // Non-doc pre-comment of Foo
2+ /// doc of Foo
3+ // Non-doc post-comment of Foo
4+ struct Foo <
5+ // Non-doc pre-comment of 'a
6+ /// doc of 'a
7+ ' a ,
8+ // Non-doc pre-comment of T
9+ /// doc of T
10+ T ,
11+ // Non-doc pre-comment of N
12+ /// doc of N
13+ const N : item ,
14+ > ;
You can’t perform that action at this time.
0 commit comments