@@ -97,102 +97,100 @@ impl Data {
97
97
// [^empty]: Leading and trailing ones might be empty if we replace
98
98
// the whole chunk. As an optimization and without loss of generality we
99
99
// don't add empty parts.
100
- let new_parts = {
101
- let Some ( index_of_part_to_split) = self . parts . iter ( ) . position ( |p| {
102
- !p. data . is_inserted ( ) && p. start <= range. start && p. end >= range. end
103
- } ) else {
104
- if tracing:: enabled!( tracing:: Level :: DEBUG ) {
105
- let slices = self
106
- . parts
107
- . iter ( )
108
- . map ( |p| {
109
- (
110
- p. start ,
111
- p. end ,
112
- match p. data {
113
- State :: Initial => "initial" ,
114
- State :: Replaced ( ..) => "replaced" ,
115
- State :: Inserted ( ..) => "inserted" ,
116
- } ,
117
- )
118
- } )
119
- . collect :: < Vec < _ > > ( ) ;
120
- tracing:: debug!(
121
- "no single slice covering {}..{}, current slices: {:?}" ,
122
- range. start,
123
- range. end,
124
- slices,
125
- ) ;
126
- }
100
+ let Some ( index_of_part_to_split) = self
101
+ . parts
102
+ . iter ( )
103
+ . position ( |p| !p. data . is_inserted ( ) && p. start <= range. start && p. end >= range. end )
104
+ else {
105
+ if tracing:: enabled!( tracing:: Level :: DEBUG ) {
106
+ let slices = self
107
+ . parts
108
+ . iter ( )
109
+ . map ( |p| {
110
+ (
111
+ p. start ,
112
+ p. end ,
113
+ match p. data {
114
+ State :: Initial => "initial" ,
115
+ State :: Replaced ( ..) => "replaced" ,
116
+ State :: Inserted ( ..) => "inserted" ,
117
+ } ,
118
+ )
119
+ } )
120
+ . collect :: < Vec < _ > > ( ) ;
121
+ tracing:: debug!(
122
+ "no single slice covering {}..{}, current slices: {:?}" ,
123
+ range. start,
124
+ range. end,
125
+ slices,
126
+ ) ;
127
+ }
127
128
128
- return Err ( Error :: MaybeAlreadyReplaced ( range) ) ;
129
- } ;
129
+ return Err ( Error :: MaybeAlreadyReplaced ( range) ) ;
130
+ } ;
130
131
131
- let part_to_split = & self . parts [ index_of_part_to_split] ;
132
-
133
- // If this replacement matches exactly the part that we would
134
- // otherwise split then we ignore this for now. This means that you
135
- // can replace the exact same range with the exact same content
136
- // multiple times and we'll process and allow it.
137
- //
138
- // This is currently done to alleviate issues like
139
- // rust-lang/rust#51211 although this clause likely wants to be
140
- // removed if that's fixed deeper in the compiler.
141
- if part_to_split. start == range. start && part_to_split. end == range. end {
142
- if let State :: Replaced ( ref replacement) = part_to_split. data {
143
- if & * * replacement == data {
144
- return Ok ( ( ) ) ;
145
- }
146
- }
147
- }
132
+ let part_to_split = & self . parts [ index_of_part_to_split] ;
148
133
149
- if part_to_split. data != State :: Initial {
150
- return Err ( Error :: AlreadyReplaced ) ;
134
+ // If this replacement matches exactly the part that we would
135
+ // otherwise split then we ignore this for now. This means that you
136
+ // can replace the exact same range with the exact same content
137
+ // multiple times and we'll process and allow it.
138
+ //
139
+ // This is currently done to alleviate issues like
140
+ // rust-lang/rust#51211 although this clause likely wants to be
141
+ // removed if that's fixed deeper in the compiler.
142
+ if part_to_split. start == range. start && part_to_split. end == range. end {
143
+ if let State :: Replaced ( ref replacement) = part_to_split. data {
144
+ if & * * replacement == data {
145
+ return Ok ( ( ) ) ;
146
+ }
151
147
}
148
+ }
152
149
153
- let mut new_parts = Vec :: with_capacity ( self . parts . len ( ) + 2 ) ;
150
+ if part_to_split. data != State :: Initial {
151
+ return Err ( Error :: AlreadyReplaced ) ;
152
+ }
154
153
155
- // Previous parts
156
- if let Some ( ps) = self . parts . get ( ..index_of_part_to_split) {
157
- new_parts. extend_from_slice ( ps) ;
158
- }
154
+ let mut new_parts = Vec :: with_capacity ( self . parts . len ( ) + 2 ) ;
159
155
160
- // Keep initial data on left side of part
161
- if range. start > part_to_split. start {
162
- new_parts. push ( Span {
163
- start : part_to_split. start ,
164
- end : range. start ,
165
- data : State :: Initial ,
166
- } ) ;
167
- }
156
+ // Previous parts
157
+ if let Some ( ps) = self . parts . get ( ..index_of_part_to_split) {
158
+ new_parts. extend_from_slice ( ps) ;
159
+ }
168
160
169
- // New part
161
+ // Keep initial data on left side of part
162
+ if range. start > part_to_split. start {
170
163
new_parts. push ( Span {
171
- start : range. start ,
172
- end : range. end ,
173
- data : if insert_only {
174
- State :: Inserted ( data. into ( ) )
175
- } else {
176
- State :: Replaced ( data. into ( ) )
177
- } ,
164
+ start : part_to_split. start ,
165
+ end : range. start ,
166
+ data : State :: Initial ,
178
167
} ) ;
168
+ }
179
169
180
- // Keep initial data on right side of part
181
- if range. end < part_to_split. end {
182
- new_parts. push ( Span {
183
- start : range. end ,
184
- end : part_to_split. end ,
185
- data : State :: Initial ,
186
- } ) ;
187
- }
188
-
189
- // Following parts
190
- if let Some ( ps) = self . parts . get ( index_of_part_to_split + 1 ..) {
191
- new_parts. extend_from_slice ( ps) ;
192
- }
170
+ // New part
171
+ new_parts. push ( Span {
172
+ start : range. start ,
173
+ end : range. end ,
174
+ data : if insert_only {
175
+ State :: Inserted ( data. into ( ) )
176
+ } else {
177
+ State :: Replaced ( data. into ( ) )
178
+ } ,
179
+ } ) ;
180
+
181
+ // Keep initial data on right side of part
182
+ if range. end < part_to_split. end {
183
+ new_parts. push ( Span {
184
+ start : range. end ,
185
+ end : part_to_split. end ,
186
+ data : State :: Initial ,
187
+ } ) ;
188
+ }
193
189
194
- new_parts
195
- } ;
190
+ // Following parts
191
+ if let Some ( ps) = self . parts . get ( index_of_part_to_split + 1 ..) {
192
+ new_parts. extend_from_slice ( ps) ;
193
+ }
196
194
197
195
self . parts = new_parts;
198
196
0 commit comments