File tree 3 files changed +181
-144
lines changed
3 files changed +181
-144
lines changed Original file line number Diff line number Diff line change 2
2
3
3
use std:: ops:: Range ;
4
4
5
+ #[ non_exhaustive]
5
6
#[ derive( Debug , thiserror:: Error ) ]
6
7
pub enum Error {
7
8
#[ error( "invalid range {0:?}, start is larger than end" ) ]
@@ -10,9 +11,7 @@ pub enum Error {
10
11
#[ error( "invalid range {0:?}, original data is only {1} byte long" ) ]
11
12
DataLengthExceeded ( Range < usize > , usize ) ,
12
13
13
- #[ error( "could not replace range {0:?}, maybe parts of it were already replaced?" ) ]
14
- MaybeAlreadyReplaced ( Range < usize > ) ,
15
-
14
+ #[ non_exhaustive] // There are plans to add fields to this variant at a later time.
16
15
#[ error( "cannot replace slice of data that was already replaced" ) ]
17
16
AlreadyReplaced ,
18
17
Original file line number Diff line number Diff line change @@ -243,9 +243,11 @@ impl CodeFix {
243
243
pub fn apply_solution ( & mut self , solution : & Solution ) -> Result < ( ) , Error > {
244
244
for r in & solution. replacements {
245
245
self . data
246
- . replace_range ( r. snippet . range . clone ( ) , r. replacement . as_bytes ( ) ) ? ;
247
- self . modified = true ;
246
+ . replace_range ( r. snippet . range . clone ( ) , r. replacement . as_bytes ( ) )
247
+ . inspect_err ( |_| self . data . restore ( ) ) ? ;
248
248
}
249
+ self . data . commit ( ) ;
250
+ self . modified = true ;
249
251
Ok ( ( ) )
250
252
}
251
253
You can’t perform that action at this time.
0 commit comments