@@ -120,6 +120,12 @@ fn bclose(&ps s, common::span span) {
120
120
121
121
}
122
122
123
+ fn hardbreak_if_not_eof ( & ps s) {
124
+ if ( s. s . last_token ( ) != pp:: EOF ) {
125
+ hardbreak ( s. s ) ;
126
+ }
127
+ }
128
+
123
129
fn space_if_not_hardbreak ( & ps s) {
124
130
if ( s. s . last_token ( ) != pp:: hardbreak_tok ( ) ) {
125
131
space ( s. s ) ;
@@ -177,7 +183,7 @@ fn print_mod(&ps s, ast::_mod _mod) {
177
183
for ( @ast:: item item in _mod. items) {
178
184
// Mod-level item printing we're a little more space-y about.
179
185
180
- hardbreak ( s . s ) ;
186
+ hardbreak_if_not_eof ( s) ;
181
187
print_item ( s, item) ;
182
188
}
183
189
print_remaining_comments ( s) ;
@@ -265,7 +271,7 @@ fn print_type(&ps s, &ast::ty ty) {
265
271
}
266
272
267
273
fn print_item ( & ps s, & @ast:: item item) {
268
- hardbreak ( s . s ) ;
274
+ hardbreak_if_not_eof ( s) ;
269
275
maybe_print_comment ( s, item. span . lo ) ;
270
276
print_outer_attributes ( s, item. attrs ) ;
271
277
alt ( item. node ) {
@@ -867,7 +873,7 @@ fn print_decl(&ps s, &@ast::decl decl) {
867
873
maybe_print_comment ( s, decl. span . lo ) ;
868
874
alt ( decl. node ) {
869
875
case ( ast:: decl_local ( ?loc) ) {
870
- space ( s . s ) ;
876
+ space_if_not_hardbreak ( s) ;
871
877
ibox ( s, indent_unit) ;
872
878
alt ( loc. node . ty ) {
873
879
case ( some ( ?ty) ) {
@@ -985,7 +991,7 @@ fn print_fn_args_and_ret(&ps s, &ast::fn_decl decl) {
985
991
pclose ( s) ;
986
992
maybe_print_comment ( s, decl. output . span . lo ) ;
987
993
if ( decl. output . node != ast:: ty_nil) {
988
- space ( s . s ) ;
994
+ space_if_not_hardbreak ( s) ;
989
995
word_space ( s, "->" ) ;
990
996
print_type ( s, * decl. output ) ;
991
997
}
@@ -1017,7 +1023,7 @@ fn print_meta_item(&ps s, &@ast::meta_item item) {
1017
1023
}
1018
1024
1019
1025
fn print_view_item ( & ps s, & @ast:: view_item item) {
1020
- hardbreak ( s . s ) ;
1026
+ hardbreak_if_not_eof ( s) ;
1021
1027
maybe_print_comment ( s, item. span . lo ) ;
1022
1028
alt ( item. node ) {
1023
1029
case ( ast:: view_item_use ( ?id, ?mta, _, _) ) {
@@ -1122,7 +1128,7 @@ fn print_ty_fn(&ps s, &ast::proto proto, &option::t[str] id,
1122
1128
pclose ( s) ;
1123
1129
maybe_print_comment ( s, output. span . lo ) ;
1124
1130
if ( output. node != ast:: ty_nil) {
1125
- space ( s . s ) ;
1131
+ space_if_not_hardbreak ( s) ;
1126
1132
ibox ( s, indent_unit) ;
1127
1133
word_space ( s, "->" ) ;
1128
1134
alt ( cf) {
0 commit comments