@@ -291,7 +291,7 @@ fn identify_comment(
291
291
let mut hbl = false ;
292
292
293
293
for line in orig. lines ( ) {
294
- let trimmed_line = line. trim_left ( ) ;
294
+ let trimmed_line = line. trim_start ( ) ;
295
295
if trimmed_line. is_empty ( ) {
296
296
hbl = true ;
297
297
break ;
@@ -308,22 +308,22 @@ fn identify_comment(
308
308
309
309
let ( has_bare_lines, first_group_ending) = match style {
310
310
CommentStyle :: DoubleSlash | CommentStyle :: TripleSlash | CommentStyle :: Doc => {
311
- let line_start = style. line_start ( ) . trim_left ( ) ;
311
+ let line_start = style. line_start ( ) . trim_start ( ) ;
312
312
consume_same_line_comments ( style, orig, line_start)
313
313
}
314
314
CommentStyle :: Custom ( opener) => {
315
- let trimmed_opener = opener. trim_right ( ) ;
315
+ let trimmed_opener = opener. trim_end ( ) ;
316
316
consume_same_line_comments ( style, orig, trimmed_opener)
317
317
}
318
318
// for a block comment, search for the closing symbol
319
319
CommentStyle :: DoubleBullet | CommentStyle :: SingleBullet | CommentStyle :: Exclamation => {
320
- let closer = style. closer ( ) . trim_left ( ) ;
320
+ let closer = style. closer ( ) . trim_start ( ) ;
321
321
let mut closing_symbol_offset = 0 ;
322
322
let mut hbl = false ;
323
323
let mut first = true ;
324
324
for line in orig. lines ( ) {
325
325
closing_symbol_offset += compute_len ( & orig[ closing_symbol_offset..] , line) ;
326
- let mut trimmed_line = line. trim_left ( ) ;
326
+ let mut trimmed_line = line. trim_start ( ) ;
327
327
if !trimmed_line. starts_with ( '*' )
328
328
&& !trimmed_line. starts_with ( "//" )
329
329
&& !trimmed_line. starts_with ( "/*" )
@@ -333,7 +333,7 @@ fn identify_comment(
333
333
334
334
// Remove opener from consideration when searching for closer
335
335
if first {
336
- let opener = style. opener ( ) . trim_right ( ) ;
336
+ let opener = style. opener ( ) . trim_end ( ) ;
337
337
trimmed_line = & trimmed_line[ opener. len ( ) ..] ;
338
338
first = false ;
339
339
}
@@ -367,22 +367,27 @@ fn identify_comment(
367
367
if rest. is_empty ( ) {
368
368
Some ( rewritten_first_group)
369
369
} else {
370
- identify_comment ( rest. trim_left ( ) , block_style, shape, config, is_doc_comment) . map (
371
- |rest_str| {
372
- format ! (
373
- "{}\n {}{}{}" ,
374
- rewritten_first_group,
375
- // insert back the blank line
376
- if has_bare_lines && style. is_line_comment( ) {
377
- "\n "
378
- } else {
379
- ""
380
- } ,
381
- shape. indent. to_string( config) ,
382
- rest_str
383
- )
384
- } ,
370
+ identify_comment (
371
+ rest. trim_start ( ) ,
372
+ block_style,
373
+ shape,
374
+ config,
375
+ is_doc_comment,
385
376
)
377
+ . map ( |rest_str| {
378
+ format ! (
379
+ "{}\n {}{}{}" ,
380
+ rewritten_first_group,
381
+ // insert back the blank line
382
+ if has_bare_lines && style. is_line_comment( ) {
383
+ "\n "
384
+ } else {
385
+ ""
386
+ } ,
387
+ shape. indent. to_string( config) ,
388
+ rest_str
389
+ )
390
+ } )
386
391
}
387
392
}
388
393
@@ -427,7 +432,7 @@ struct ItemizedBlock {
427
432
impl ItemizedBlock {
428
433
/// Returns true if the line is formatted as an item
429
434
fn is_itemized_line ( line : & str ) -> bool {
430
- let trimmed = line. trim_left ( ) ;
435
+ let trimmed = line. trim_start ( ) ;
431
436
trimmed. starts_with ( "* " ) || trimmed. starts_with ( "- " )
432
437
}
433
438
@@ -537,7 +542,7 @@ impl<'a> CommentRewrite<'a> {
537
542
while let Some ( line) = iter. next ( ) {
538
543
result. push_str ( line) ;
539
544
result. push_str ( match iter. peek ( ) {
540
- Some ( next_line) if next_line. is_empty ( ) => sep. trim_right ( ) ,
545
+ Some ( next_line) if next_line. is_empty ( ) => sep. trim_end ( ) ,
541
546
Some ( ..) => & sep,
542
547
None => "" ,
543
548
} ) ;
@@ -757,15 +762,15 @@ fn rewrite_comment_inner(
757
762
) -> Option < String > {
758
763
let mut rewriter = CommentRewrite :: new ( orig, block_style, shape, config) ;
759
764
760
- let line_breaks = count_newlines ( orig. trim_right ( ) ) ;
765
+ let line_breaks = count_newlines ( orig. trim_end ( ) ) ;
761
766
let lines = orig
762
767
. lines ( )
763
768
. enumerate ( )
764
769
. map ( |( i, mut line) | {
765
- line = trim_right_unless_two_whitespaces ( line. trim_left ( ) , is_doc_comment) ;
770
+ line = trim_end_unless_two_whitespaces ( line. trim_start ( ) , is_doc_comment) ;
766
771
// Drop old closer.
767
772
if i == line_breaks && line. ends_with ( "*/" ) && !line. starts_with ( "//" ) {
768
- line = line[ ..( line. len ( ) - 2 ) ] . trim_right ( ) ;
773
+ line = line[ ..( line. len ( ) - 2 ) ] . trim_end ( ) ;
769
774
}
770
775
771
776
line
@@ -774,7 +779,7 @@ fn rewrite_comment_inner(
774
779
. map ( |( line, has_leading_whitespace) | {
775
780
if orig. starts_with ( "/*" ) && line_breaks == 0 {
776
781
(
777
- line. trim_left ( ) ,
782
+ line. trim_start ( ) ,
778
783
has_leading_whitespace || config. normalize_comments ( ) ,
779
784
)
780
785
} else {
@@ -794,7 +799,7 @@ fn rewrite_comment_inner(
794
799
const RUSTFMT_CUSTOM_COMMENT_PREFIX : & str = "//#### " ;
795
800
796
801
fn hide_sharp_behind_comment ( s : & str ) -> Cow < str > {
797
- if s. trim_left ( ) . starts_with ( "# " ) {
802
+ if s. trim_start ( ) . starts_with ( "# " ) {
798
803
Cow :: from ( format ! ( "{}{}" , RUSTFMT_CUSTOM_COMMENT_PREFIX , s) )
799
804
} else {
800
805
Cow :: from ( s)
@@ -804,9 +809,9 @@ fn hide_sharp_behind_comment(s: &str) -> Cow<str> {
804
809
fn trim_custom_comment_prefix ( s : & str ) -> String {
805
810
s. lines ( )
806
811
. map ( |line| {
807
- let left_trimmed = line. trim_left ( ) ;
812
+ let left_trimmed = line. trim_start ( ) ;
808
813
if left_trimmed. starts_with ( RUSTFMT_CUSTOM_COMMENT_PREFIX ) {
809
- left_trimmed. trim_left_matches ( RUSTFMT_CUSTOM_COMMENT_PREFIX )
814
+ left_trimmed. trim_start_matches ( RUSTFMT_CUSTOM_COMMENT_PREFIX )
810
815
} else {
811
816
line
812
817
}
@@ -866,11 +871,11 @@ pub fn recover_missing_comment_in_span(
866
871
}
867
872
868
873
/// Trim trailing whitespaces unless they consist of two or more whitespaces.
869
- fn trim_right_unless_two_whitespaces ( s : & str , is_doc_comment : bool ) -> & str {
874
+ fn trim_end_unless_two_whitespaces ( s : & str , is_doc_comment : bool ) -> & str {
870
875
if is_doc_comment && s. ends_with ( " " ) {
871
876
s
872
877
} else {
873
- s. trim_right ( )
878
+ s. trim_end ( )
874
879
}
875
880
}
876
881
@@ -898,7 +903,7 @@ fn light_rewrite_comment(
898
903
""
899
904
} ;
900
905
// Preserve markdown's double-space line break syntax in doc comment.
901
- trim_right_unless_two_whitespaces ( left_trimmed, is_doc_comment)
906
+ trim_end_unless_two_whitespaces ( left_trimmed, is_doc_comment)
902
907
} )
903
908
. collect ( ) ;
904
909
lines. join ( & format ! ( "\n {}" , offset. to_string( config) ) )
@@ -918,7 +923,7 @@ fn left_trim_comment_line<'a>(line: &'a str, style: &CommentStyle) -> (&'a str,
918
923
if line. starts_with ( opener) {
919
924
( & line[ opener. len ( ) ..] , true )
920
925
} else {
921
- ( & line[ opener. trim_right ( ) . len ( ) ..] , false )
926
+ ( & line[ opener. trim_end ( ) . len ( ) ..] , false )
922
927
}
923
928
} else if line. starts_with ( "/* " )
924
929
|| line. starts_with ( "// " )
0 commit comments