@@ -530,21 +530,18 @@ impl EmitterWriter {
530
530
let left = margin. left ( line_len) ;
531
531
let right = margin. right ( line_len) ;
532
532
// On long lines, we strip the source line, accounting for unicode.
533
- // Make sure that the trimming on the right will fall within the terminal width.
534
- // FIXME: `unicode_width` sometimes disagrees with terminals on how wide a `char` is.
535
- // For now, just accept that sometimes the code line will be longer than desired.
536
- let code: String = source_string. chars ( ) . skip ( left)
537
- . map ( |ch| {
538
- let width = unicode_width:: UnicodeWidthChar :: width ( * ch) . unwrap_or ( 1 ) ;
539
- ( width, ch)
540
- } )
541
- . scan ( 0 , |len, ( width, ch) | {
542
- * len += width;
543
- Some ( * len, ch)
544
- } )
545
- . take_while ( |& ( prefix_len, _ch) | prefix_len <= right - left)
546
- . map ( |( _prefix_len, ch) | ch)
547
- . collect ( ) ;
533
+ let mut taken = 0 ;
534
+ let code: String = source_string. chars ( ) . skip ( left) . take_while ( |ch| {
535
+ // Make sure that the trimming on the right will fall within the terminal width.
536
+ // FIXME: `unicode_width` sometimes disagrees with terminals on how wide a `char` is.
537
+ // For now, just accept that sometimes the code line will be longer than desired.
538
+ let next = unicode_width:: UnicodeWidthChar :: width ( * ch) . unwrap_or ( 1 ) ;
539
+ if taken + next > right - left {
540
+ return false ;
541
+ }
542
+ taken += next;
543
+ true
544
+ } ) . collect ( ) ;
548
545
buffer. puts ( line_offset, code_offset, & code, Style :: Quotation ) ;
549
546
if margin. was_cut_left ( ) {
550
547
// We have stripped some code/whitespace from the beginning, make it clear.
0 commit comments