1+ use std:: ops;
2+
13use either:: Either ;
24use rustc_middle:: mir:: * ;
35use rustc_middle:: thir:: { self , * } ;
46use rustc_middle:: ty:: { self , Ty , TypeVisitableExt } ;
5- use std:: ops;
67
78use crate :: builder:: Builder ;
89use crate :: builder:: expr:: as_place:: { PlaceBase , PlaceBuilder } ;
@@ -58,9 +59,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
5859 ( ( prefix. len ( ) + suffix. len ( ) ) . try_into ( ) . unwrap ( ) , false )
5960 } ;
6061
61- tracing:: warn!( "Builder::prefix_slice_suffix: min_length: {}, exact_size: {} -> {:?}" , min_length, exact_size, top_pattern) ;
62- tracing:: warn!( "prefix: {:?}, suffix: {:?}" , prefix. len( ) , suffix. len( ) ) ;
63-
6462 if !prefix. is_empty ( ) {
6563 let bounds = Range :: from_start ( 0 ..prefix. len ( ) as u64 ) ;
6664 let subpattern = bounds. apply ( prefix) ;
@@ -110,7 +108,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
110108 } ;
111109
112110 match entry {
113- Either :: Right ( range) if range. end - range. start > 1 => {
111+ Either :: Right ( range) if range. end - range. start > 1 => {
114112 assert ! (
115113 ( range. start..range. end)
116114 . all( |idx| self . is_constant_pattern( & pattern[ idx as usize ] ) )
@@ -126,7 +124,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
126124 place. clone ( ) ,
127125 elem_ty,
128126 bounds. shift_range ( range) ,
129- true , // TODO: set false if only branch and only entry
127+ true , // TODO: set false if only branch and only entry
130128 )
131129 }
132130 Either :: Right ( range) => {
@@ -143,26 +141,26 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
143141 let mut entries = Vec :: new ( ) ;
144142 let mut current_seq_start = None ;
145143
146- let mut apply = |state : & mut _ , idx, b : bool | {
147- if let Some ( start) = * state {
148- * state = None ;
149- entries. push ( Either :: Right ( start..idx) ) ;
150- } else if !b {
151- entries. push ( Either :: Left ( idx) ) ;
152- }
153- } ;
154-
155144 for ( idx, pat) in pattern. iter ( ) . enumerate ( ) {
156145 if self . is_constant_pattern ( pat) {
157146 if current_seq_start. is_none ( ) {
158147 current_seq_start = Some ( idx as u64 ) ;
148+ } else {
149+ continue ;
159150 }
160151 } else {
161- apply ( & mut current_seq_start, idx as u64 , false ) ;
152+ if let Some ( start) = current_seq_start {
153+ entries. push ( Either :: Right ( start..idx as u64 ) ) ;
154+ current_seq_start = None ;
155+ }
156+ entries. push ( Either :: Left ( idx as u64 ) ) ;
162157 }
163158 }
164159
165- apply ( & mut current_seq_start, pattern. len ( ) as u64 , true ) ;
160+ if let Some ( start) = current_seq_start {
161+ entries. push ( Either :: Right ( start..pattern. len ( ) as u64 ) ) ;
162+ }
163+
166164 entries
167165 }
168166
0 commit comments