1- use std:: {
2- num:: NonZeroU16 ,
3- ops:: Range ,
4- sync:: { Arc , LazyLock } ,
5- } ;
1+ use std:: { num:: NonZeroU16 , ops:: Range , sync:: Arc } ;
62
73use context_error:: * ;
84use itertools:: Itertools ;
@@ -142,22 +138,23 @@ impl SimpleModificationInner {
142138 }
143139}
144140
141+ type SliceWithRange < ' a > = ( & ' a str , Range < usize > ) ;
142+
145143fn tokenise_mod (
146144 text : & str ,
147145 range : Range < usize > ,
148146) -> (
149- ( & str , Range < usize > ) ,
150- Option < ( & str , Range < usize > ) > ,
151- Option < ( & str , Range < usize > ) > ,
152- Option < ( & str , Range < usize > ) > ,
147+ SliceWithRange < ' _ > ,
148+ Option < SliceWithRange < ' _ > > ,
149+ Option < SliceWithRange < ' _ > > ,
150+ Option < SliceWithRange < ' _ > > ,
153151) {
154152 // ^(([^:#]*)(?::([^#]+))?)(?:#([0-9A-Za-z]+)(?:\((\d+\.\d+)\))?)?$
155153 // text(:text)?(#label(score)?)?
156154
157155 let ( m, label) = text[ range. clone ( ) ]
158156 . split_once ( '#' )
159- . map ( |( m, l) | ( m, Some ( l) ) )
160- . unwrap_or ( ( & text[ range. clone ( ) ] , None ) ) ;
157+ . map_or_else ( || ( & text[ range. clone ( ) ] , None ) , |( m, l) | ( m, Some ( l) ) ) ;
161158 let ( tag, name) =
162159 m. split_once ( ':' )
163160 . map_or ( ( ( m, range. start ..range. start + m. len ( ) ) , None ) , |( t, n) | {
@@ -322,7 +319,7 @@ fn parse_single_modification<'error, const STRICT: bool>(
322319
323320 let mut errors = Vec :: new ( ) ;
324321 let ( head, tail, label, score) = tokenise_mod ( line, range. clone ( ) ) ;
325- let full = ( & line[ range. clone ( ) ] , range. clone ( ) ) ;
322+ let full = ( & line[ range. clone ( ) ] , range) ;
326323
327324 let modification = if let Some ( tail) = tail {
328325 let basic_error = BoxedError :: new (
@@ -580,7 +577,7 @@ fn parse_single_modification<'error, const STRICT: bool>(
580577 BasicKind :: Error ,
581578 "Invalid branch definition" ,
582579 "A branch definition has to be identical at both sites, or only defined at one site." ,
583- base_context. clone( ) . add_highlight( ( 0 , full. 1 . clone ( ) ) ) ,
580+ base_context. clone( ) . add_highlight( ( 0 , full. 1 ) ) ,
584581 ) ] ) ;
585582 }
586583 cross_link_lookup[ index] . 1 = Some ( linker) ;
@@ -611,7 +608,7 @@ fn parse_single_modification<'error, const STRICT: bool>(
611608 BasicKind :: Error ,
612609 "Invalid cross-link definition" ,
613610 "A cross-link definition has to be identical at both sites, or only defined at one site." ,
614- base_context. clone( ) . add_highlight( ( 0 , full. 1 . clone ( ) ) ) ,
611+ base_context. clone( ) . add_highlight( ( 0 , full. 1 ) ) ,
615612 ) ] ) ;
616613 }
617614 cross_link_lookup[ index] . 1 = Some ( linker) ;
@@ -624,7 +621,7 @@ fn parse_single_modification<'error, const STRICT: bool>(
624621 ) )
625622 } else {
626623 let score = match score. map ( |s| {
627- s. 0 . parse :: < f64 > ( ) . map_err ( |err | {
624+ s. 0 . parse :: < f64 > ( ) . map_err ( |_ | {
628625 BoxedError :: new (
629626 BasicKind :: Error ,
630627 "Invalid modification localisation score" ,
@@ -646,7 +643,7 @@ fn parse_single_modification<'error, const STRICT: bool>(
646643 group,
647644 score,
648645 ambiguous_lookup,
649- base_context. clone ( ) . add_highlight ( ( 0 , full. 1 . clone ( ) ) ) ,
646+ base_context. clone ( ) . add_highlight ( ( 0 , full. 1 ) ) ,
650647 )
651648 . map ( |( m, w) | {
652649 combine_errors ( & mut errors, w) ;
@@ -668,7 +665,7 @@ fn parse_single_modification<'error, const STRICT: bool>(
668665/// If the content of the ambiguous modification was already defined
669666fn handle_ambiguous_modification < ' a > (
670667 modification : Option < SimpleModification > ,
671- group : ( & str , Range < usize > ) ,
668+ group : SliceWithRange < ' a > ,
672669 localisation_score : Option < OrderedFloat < f64 > > ,
673670 ambiguous_lookup : & mut AmbiguousLookup ,
674671 context : Context < ' a > ,
0 commit comments