11use crate :: renderer:: { char_width, is_different, num_overlap, LineAnnotation , LineAnnotationType } ;
22use crate :: { Annotation , AnnotationKind , Patch } ;
33use std:: borrow:: Cow ;
4- use std:: cmp:: { max, min} ;
4+ use std:: cmp:: { max, min, Ordering } ;
55use std:: ops:: Range ;
66
77#[ derive( Debug ) ]
@@ -294,12 +294,16 @@ impl<'a> SourceMap<'a> {
294294 . map_or ( ann. start . line , |( line, _) | line) ;
295295 for line in ann. start . line + 1 ..until {
296296 // Every `|` that joins the beginning of the span (`___^`) to the end (`|__^`).
297- self . add_annotation_to_file ( & mut annotated_line_infos, line, ann. as_line ( ) ) ;
297+ self . add_annotation_to_file ( & mut annotated_line_infos, line, ann. as_line ( line ) ) ;
298298 }
299299 let line_end = ann. end . line - 1 ;
300300 let end_is_empty = self . get_line ( line_end) . map_or ( false , |s| !filter ( s) ) ;
301301 if middle < line_end && !end_is_empty {
302- self . add_annotation_to_file ( & mut annotated_line_infos, line_end, ann. as_line ( ) ) ;
302+ self . add_annotation_to_file (
303+ & mut annotated_line_infos,
304+ line_end,
305+ ann. as_line ( line_end) ,
306+ ) ;
303307 }
304308 }
305309 self . add_annotation_to_file ( & mut annotated_line_infos, end_ann. end . line , end_ann) ;
@@ -575,10 +579,16 @@ impl<'a> MultilineAnnotation<'a> {
575579 }
576580 }
577581
578- pub ( crate ) fn as_line ( & self ) -> LineAnnotation < ' a > {
582+ pub ( crate ) fn as_line ( & self , line : usize ) -> LineAnnotation < ' a > {
579583 LineAnnotation {
580- start : Loc :: default ( ) ,
581- end : Loc :: default ( ) ,
584+ start : Loc {
585+ line,
586+ ..Default :: default ( )
587+ } ,
588+ end : Loc {
589+ line,
590+ ..Default :: default ( )
591+ } ,
582592 kind : self . kind ,
583593 label : None ,
584594 annotation_type : LineAnnotationType :: MultilineLine ( self . depth ) ,
@@ -604,7 +614,7 @@ pub(crate) struct AnnotatedLineInfo<'a> {
604614}
605615
606616/// A source code location used for error reporting.
607- #[ derive( Clone , Copy , Debug , Default , PartialOrd , Ord , PartialEq , Eq ) ]
617+ #[ derive( Clone , Copy , Debug , Default , Eq ) ]
608618pub ( crate ) struct Loc {
609619 /// The (1-based) line number.
610620 pub ( crate ) line : usize ,
@@ -616,6 +626,30 @@ pub(crate) struct Loc {
616626 pub ( crate ) byte : usize ,
617627}
618628
629+ impl PartialEq for Loc {
630+ fn eq ( & self , other : & Self ) -> bool {
631+ self . line . eq ( & other. line ) && self . display . eq ( & other. display ) && self . char . eq ( & other. char )
632+ }
633+ }
634+
635+ impl Ord for Loc {
636+ fn cmp ( & self , other : & Self ) -> Ordering {
637+ match self . line . cmp ( & other. line ) {
638+ Ordering :: Equal => match self . display . cmp ( & other. display ) {
639+ Ordering :: Equal => self . char . cmp ( & other. char ) ,
640+ c => c,
641+ } ,
642+ c => c,
643+ }
644+ }
645+ }
646+
647+ impl PartialOrd for Loc {
648+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
649+ Some ( self . cmp ( other) )
650+ }
651+ }
652+
619653struct CursorLines < ' a > ( & ' a str ) ;
620654
621655impl CursorLines < ' _ > {
0 commit comments