@@ -204,7 +204,8 @@ fn commasep_cmnt[IN](&ps s, breaks b, vec[IN] elts, fn(&ps, &IN) op,
204
204
i += 1 u;
205
205
if ( i < len) {
206
206
word ( s. s , "," ) ;
207
- maybe_print_trailing_comment ( s, get_span ( elt) ) ;
207
+ maybe_print_trailing_comment ( s, get_span ( elt) ,
208
+ some ( get_span ( elts. ( i) ) . hi ) ) ;
208
209
space ( s. s ) ;
209
210
}
210
211
}
@@ -404,7 +405,7 @@ fn print_item(&ps s, &@ast::item item) {
404
405
pclose ( s) ;
405
406
}
406
407
word ( s. s , ";" ) ;
407
- maybe_print_trailing_comment ( s, v. span ) ;
408
+ maybe_print_trailing_comment ( s, v. span , none [ uint ] ) ;
408
409
}
409
410
bclose ( s, item. span ) ;
410
411
}
@@ -469,13 +470,12 @@ fn print_stmt(&ps s, &ast::stmt st) {
469
470
}
470
471
}
471
472
if ( front:: parser:: stmt_ends_with_semi ( st) ) { word ( s. s , ";" ) ; }
472
- maybe_print_trailing_comment ( s, st. span ) ;
473
+ maybe_print_trailing_comment ( s, st. span , none [ uint ] ) ;
473
474
}
474
475
475
476
fn print_block ( & ps s, ast:: block blk) {
476
477
maybe_print_comment ( s, blk. span . lo ) ;
477
478
bopen ( s) ;
478
- auto first = true ;
479
479
for ( @ast:: stmt st in blk. node. stmts) {
480
480
print_stmt ( s, * st)
481
481
@@ -484,7 +484,8 @@ fn print_block(&ps s, ast::block blk) {
484
484
case ( some ( ?expr) ) {
485
485
space ( s. s ) ;
486
486
print_expr ( s, expr) ;
487
- maybe_print_trailing_comment ( s, expr. span ) ;
487
+ maybe_print_trailing_comment ( s, expr. span ,
488
+ some ( blk. span . hi ) ) ;
488
489
}
489
490
case ( _) { }
490
491
}
@@ -1264,7 +1265,8 @@ fn maybe_print_comment(&ps s, uint pos) {
1264
1265
}
1265
1266
}
1266
1267
1267
- fn maybe_print_trailing_comment ( & ps s, common:: span span) {
1268
+ fn maybe_print_trailing_comment ( & ps s, common:: span span,
1269
+ option:: t[ uint] next_pos ) {
1268
1270
auto cm;
1269
1271
alt ( s. cm ) {
1270
1272
case ( some ( ?ccm) ) {
@@ -1278,9 +1280,14 @@ fn maybe_print_trailing_comment(&ps s, common::span span) {
1278
1280
1279
1281
auto span_line = codemap:: lookup_pos ( cm, span. hi ) ;
1280
1282
auto comment_line = codemap:: lookup_pos ( cm, cmnt. pos ) ;
1283
+ auto next = cmnt. pos + 1 u;
1284
+ alt ( next_pos) {
1285
+ case ( none) { }
1286
+ case ( some ( ?p) ) { next = p; }
1287
+ }
1281
1288
if ( span. hi < cmnt. pos &&
1289
+ cmnt. pos < next &&
1282
1290
span_line. line == comment_line. line ) {
1283
- word ( s. s , " " ) ;
1284
1291
print_comment ( s, cmnt) ;
1285
1292
s. cur_cmnt += 1 u;
1286
1293
}
@@ -1327,6 +1334,7 @@ fn print_comment(&ps s, lexer::cmnt cmnt) {
1327
1334
}
1328
1335
1329
1336
case ( lexer:: trailing) {
1337
+ word ( s. s , " " ) ;
1330
1338
if ( vec:: len ( cmnt. lines ) == 1 u) {
1331
1339
word ( s. s , cmnt. lines . ( 0 ) ) ;
1332
1340
hardbreak ( s. s ) ;
0 commit comments