Skip to content

Commit f73b1d8

Browse files
committed
add transactional semantics to rustfix
1 parent 06e0ef4 commit f73b1d8

File tree

6 files changed

+184
-147
lines changed

6 files changed

+184
-147
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ rand = "0.8.5"
8181
regex = "1.10.5"
8282
rusqlite = { version = "0.32.0", features = ["bundled"] }
8383
rustc-hash = "2.0.0"
84-
rustfix = { version = "0.8.2", path = "crates/rustfix" }
84+
rustfix = { version = "0.9.0", path = "crates/rustfix" }
8585
same-file = "1.0.6"
8686
schemars = "0.8.21"
8787
security-framework = "2.11.1"

crates/rustfix/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rustfix"
3-
version = "0.8.8"
3+
version = "0.9.0"
44
authors = [
55
"Pascal Hertleif <[email protected]>",
66
"Oliver Schneider <[email protected]>",

crates/rustfix/src/error.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use std::ops::Range;
44

5+
#[non_exhaustive]
56
#[derive(Debug, thiserror::Error)]
67
pub enum Error {
78
#[error("invalid range {0:?}, start is larger than end")]
@@ -10,9 +11,7 @@ pub enum Error {
1011
#[error("invalid range {0:?}, original data is only {1} byte long")]
1112
DataLengthExceeded(Range<usize>, usize),
1213

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.
1615
#[error("cannot replace slice of data that was already replaced")]
1716
AlreadyReplaced,
1817

crates/rustfix/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,11 @@ impl CodeFix {
243243
pub fn apply_solution(&mut self, solution: &Solution) -> Result<(), Error> {
244244
for r in &solution.replacements {
245245
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())?;
248248
}
249+
self.data.commit();
250+
self.modified = true;
249251
Ok(())
250252
}
251253

0 commit comments

Comments
 (0)