Skip to content

Commit affd669

Browse files
committed
chore: update CI and fix clippy etc
1 parent 63d49f0 commit affd669

6 files changed

Lines changed: 67 additions & 50 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,22 @@ jobs:
1111
- name: Checkout
1212
uses: actions/checkout@v2
1313

14-
- name: Test
15-
run: cargo test --workspace
14+
- uses: dtolnay/rust-toolchain@stable
15+
with:
16+
components: clippy, rustfmt
17+
18+
- name: Format check
19+
shell: bash
20+
run: cargo fmt --all --check
1621

17-
- name: Test with serde
18-
run: cargo test --workspace --features serde
22+
- name: Clippy (pedantic)
23+
shell: bash
24+
run: cargo clippy -- --no-deps -Dclippy::pedantic -Dwarnings
1925

20-
- name: Test with features
21-
run: cargo test --workspace --features uuid,chrono,visitor
26+
- uses: taiki-e/install-action@cargo-hack
2227

23-
- name: Test with myers diff algo
24-
run: cargo test --workspace --no-default-features --features vec_diff_myers
28+
- name: Test
29+
run: cargo hack --each-feature test --workspace
2530

2631
- name: Run example
2732
run: cargo run --example visitor --features visitor

Cargo.lock

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

difficient-macros/Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ version = "0.1.0"
77
edition = "2024"
88

99
[dependencies]
10-
darling = "0.20.10"
10+
darling = "0.21.0"
1111
heck = "0.5.0"
12-
proc-macro2 = "1.0.86"
13-
quote = "1.0.36"
14-
syn = "2.0.72"
12+
proc-macro2 = "1.0.95"
13+
quote = "1.0.40"
14+
syn = "2.0.104"
1515

1616
[features]
1717
serde_impl = []
1818
visitor_impl = ["serde_impl"]
1919

2020
[dev-dependencies]
21-
pretty_assertions = "1.4.0"
22-
prettyplease = "0.2.20"
21+
pretty_assertions = "1.4.1"
22+
prettyplease = "0.2.36"

examples/visitor.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ impl difficient::Visitor for ChangeEmitter {
1616
self.location.pop().unwrap();
1717
}
1818
fn replaced<T: serde::Serialize>(&mut self, val: T) {
19-
use Enter::*;
2019
let mut path = String::new();
2120
for (ix, loc) in self.location.iter().enumerate() {
2221
match loc {
23-
NamedField { name, .. } => path.push_str(name),
24-
PositionalField(p) => path.push_str(&p.to_string()),
25-
Variant { name, .. } => path.push_str(name),
26-
MapKey(key) => path.push_str(&key),
27-
Index(key) => path.push_str(&key.to_string()),
22+
Enter::NamedField { name, .. } | Enter::Variant { name, .. } => path.push_str(name),
23+
Enter::PositionalField(p) => path.push_str(&p.to_string()),
24+
Enter::MapKey(key) => path.push_str(key),
25+
Enter::Index(key) => path.push_str(&key.to_string()),
2826
}
2927
if ix != self.location.len() - 1 {
3028
path.push('.');
@@ -83,6 +81,6 @@ fn main() {
8381

8482
println!("Changed paths:");
8583
for (path, val) in emitter.changes {
86-
println!("{path}: {val}")
84+
println!("{path}: {val}");
8785
}
8886
}

src/serde_visit.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ tuple_impl!(A 0);
162162

163163
macro_rules! kv_map_impl {
164164
($typ: ident, $bounds: ident) => {
165+
#[allow(
166+
clippy::implicit_hasher,
167+
reason = "Implementation is shared among HashMap and BTreeMap"
168+
)]
165169
impl<'a, K, V, U> AcceptVisitor for $typ<K, KvDiff<'a, V, U>>
166170
where
167171
K: $bounds + ToString + 'a,
@@ -200,7 +204,7 @@ pub mod tests {
200204
use serde::Serialize;
201205

202206
use super::*;
203-
use crate::{Diffable, Replace, tests::*};
207+
use crate::{tests::*, Diffable, Replace};
204208

205209
impl AcceptVisitor for ParentDiff<'_> {
206210
fn accept<V: Visitor>(&self, visitor: &mut V) {
@@ -337,7 +341,7 @@ pub mod tests {
337341
let loc = self.location.join(".");
338342
if let Ok(val) = serde_json::to_string(&val) {
339343
self.replaced_locs.push((loc, val));
340-
};
344+
}
341345
}
342346

343347
fn splice<T: serde::Serialize>(&mut self, from_index: usize, replace: usize, values: &[T]) {
@@ -355,14 +359,15 @@ pub mod tests {
355359
values,
356360
},
357361
));
358-
};
362+
}
359363
}
360364

361365
fn enter(&mut self, val: Enter) {
362366
match val {
363-
Enter::NamedField { name, .. } => self.location.push(name.into()),
364367
Enter::PositionalField(p) => self.location.push(p.to_string()),
365-
Enter::Variant { name, .. } => self.location.push(name.into()),
368+
Enter::NamedField { name, .. } | Enter::Variant { name, .. } => {
369+
self.location.push(name.into());
370+
}
366371
Enter::MapKey(k) => self.location.push(k),
367372
Enter::Index(ix) => self.location.push(ix.to_string()),
368373
}

src/vec.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
#[cfg(feature = "vec_diff_lcs")]
2-
use similar::algorithms::lcs as diff_algo;
3-
4-
#[cfg(feature = "vec_diff_myers")]
5-
use similar::algorithms::lcs as diff_algo;
6-
71
use similar::algorithms::{Capture, Compact, Replace as SimilarReplace};
82

93
use crate::{Apply, ApplyError, Diffable, Replace};
@@ -75,7 +69,7 @@ mod visitor_impls {
7569
Self::Unchanged => {}
7670
Self::Changed { changes } => {
7771
for chg in changes {
78-
chg.accept(visitor)
72+
chg.accept(visitor);
7973
}
8074
}
8175
Self::Replaced(r) => visitor.replaced(r),
@@ -90,7 +84,7 @@ mod visitor_impls {
9084
fn accept<V: crate::Visitor>(&self, visitor: &mut V) {
9185
match self {
9286
VecChange::Remove { at_index, count } => {
93-
visitor.splice::<T>(*at_index, *count, &[])
87+
visitor.splice::<T>(*at_index, *count, &[]);
9488
}
9589
VecChange::Insert { at_index, values } => visitor.splice(*at_index, 0, values),
9690
VecChange::Splice {
@@ -188,6 +182,7 @@ where
188182
{
189183
type Diff = VecDiff<'a, T, T::Diff>;
190184

185+
#[allow(clippy::too_many_lines)]
191186
fn diff(&self, other: &'a Self) -> Self::Diff {
192187
if self.is_empty() && other.is_empty() {
193188
// short circuit
@@ -205,7 +200,21 @@ where
205200
)]
206201
let rkeys: Vec<_> = other.iter().map(|v| v.key()).collect();
207202
let mut d = Compact::new(SimilarReplace::new(Capture::new()), &lkeys, &rkeys);
208-
diff_algo::diff(&mut d, &lkeys, 0..lkeys.len(), &rkeys, 0..rkeys.len()).unwrap();
203+
204+
if cfg!(feature = "vec_diff_myers") {
205+
similar::algorithms::myers::diff(
206+
&mut d,
207+
&lkeys,
208+
0..lkeys.len(),
209+
&rkeys,
210+
0..rkeys.len(),
211+
)
212+
.unwrap();
213+
} else {
214+
similar::algorithms::lcs::diff(&mut d, &lkeys, 0..lkeys.len(), &rkeys, 0..rkeys.len())
215+
.unwrap();
216+
}
217+
209218
let ops = d.into_inner().into_inner().into_ops();
210219
let n_ops = ops.len();
211220
let mut offset = 0isize;

0 commit comments

Comments
 (0)