File tree Expand file tree Collapse file tree 2 files changed +64
-18
lines changed Expand file tree Collapse file tree 2 files changed +64
-18
lines changed Original file line number Diff line number Diff line change @@ -2919,26 +2919,34 @@ fn max_line_number(groups: &[Group<'_>]) -> usize {
29192919 | Element :: Origin ( _)
29202920 | Element :: Padding ( _) => 0 ,
29212921 Element :: Cause ( cause) => {
2922- let end = cause
2923- . markers
2924- . iter ( )
2925- . map ( |a| a. span . end )
2926- . max ( )
2927- . unwrap_or ( cause. source . len ( ) )
2928- . min ( cause. source . len ( ) ) ;
2929-
2930- cause. line_start + newline_count ( & cause. source [ ..end] )
2922+ if cause. fold {
2923+ let end = cause
2924+ . markers
2925+ . iter ( )
2926+ . map ( |a| a. span . end )
2927+ . max ( )
2928+ . unwrap_or ( cause. source . len ( ) )
2929+ . min ( cause. source . len ( ) ) ;
2930+
2931+ cause. line_start + newline_count ( & cause. source [ ..end] )
2932+ } else {
2933+ cause. line_start + newline_count ( & cause. source )
2934+ }
29312935 }
29322936 Element :: Suggestion ( suggestion) => {
2933- let end = suggestion
2934- . markers
2935- . iter ( )
2936- . map ( |a| a. span . end )
2937- . max ( )
2938- . unwrap_or ( suggestion. source . len ( ) )
2939- . min ( suggestion. source . len ( ) ) ;
2940-
2941- suggestion. line_start + newline_count ( & suggestion. source [ ..end] )
2937+ if suggestion. fold {
2938+ let end = suggestion
2939+ . markers
2940+ . iter ( )
2941+ . map ( |a| a. span . end )
2942+ . max ( )
2943+ . unwrap_or ( suggestion. source . len ( ) )
2944+ . min ( suggestion. source . len ( ) ) ;
2945+
2946+ suggestion. line_start + newline_count ( & suggestion. source [ ..end] )
2947+ } else {
2948+ suggestion. line_start + newline_count ( & suggestion. source )
2949+ }
29422950 }
29432951 } )
29442952 . max ( )
Original file line number Diff line number Diff line change @@ -2574,3 +2574,41 @@ LL + break;
25742574 let renderer_unicode = renderer_ascii. theme ( OutputTheme :: Unicode ) ;
25752575 assert_data_eq ! ( renderer_unicode. render( input) , expected_unicode) ;
25762576}
2577+
2578+ #[ test]
2579+ fn max_line_num_no_fold ( ) {
2580+ let source = r#"cargo
2581+ fuzzy
2582+ pizza
2583+ jumps
2584+ crazy
2585+ quack
2586+ zappy
2587+ "# ;
2588+
2589+ let input_new = & [ Group :: with_title (
2590+ Level :: ERROR
2591+ . title ( "the size for values of type `T` cannot be known at compilation time" )
2592+ . id ( "E0277" ) ,
2593+ )
2594+ . element (
2595+ Snippet :: source ( source)
2596+ . line_start ( 8 )
2597+ . fold ( false )
2598+ . annotation ( AnnotationKind :: Primary . span ( 6 ..11 ) ) ,
2599+ ) ] ;
2600+ let expected = str![ [ r#"
2601+ error[E0277]: the size for values of type `T` cannot be known at compilation time
2602+ |
2603+ 8 | cargo
2604+ 9 | fuzzy
2605+ | ^^^^^
2606+ 10 | pizza
2607+ 11 | jumps
2608+ 12 | crazy
2609+ 13 | quack
2610+ 14 | zappy
2611+ "# ] ] ;
2612+ let renderer = Renderer :: plain ( ) ;
2613+ assert_data_eq ! ( renderer. render( input_new) , expected) ;
2614+ }
You can’t perform that action at this time.
0 commit comments