File tree 3 files changed +28
-12
lines changed
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 {
113
113
114
114
impl Spanned for ast:: GenericParam {
115
115
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 ( ) ,
127
120
} ;
128
121
let hi = if self . bounds . is_empty ( ) {
129
122
self . ident . span . hi ( )
Original file line number Diff line number Diff line change @@ -575,7 +575,16 @@ impl Rewrite for ast::GenericParam {
575
575
let mut result = String :: with_capacity ( 128 ) ;
576
576
// FIXME: If there are more than one attributes, this will force multiline.
577
577
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
+ }
579
588
_ => ( ) ,
580
589
}
581
590
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