EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust
Never crash: raster and path crates without expect()/unwrap()/unreachable!()
Brandon Thomas786e4e8b979c
diff --git a/clippy.toml b/clippy.tomlnew file mode 100644index 000000000..4b6c79f55--- /dev/null+++ b/clippy.toml@@ -0,0 +1,4 @@+allow-unwrap-in-tests = true+allow-expect-in-tests = true+allow-panic-in-tests = true+allow-indexing-slicing-in-tests = truediff --git a/crates/path/src/fit.rs b/crates/path/src/fit.rsindex b9dbced10..337acc908 100644--- a/crates/path/src/fit.rs+++ b/crates/path/src/fit.rs@@ -72,8 +72,7 @@ fn bern(t: f64) -> [f64; 4] {/// Solve the 2x2 normal equations for the handle lengths along the fixed tangents.fn generate(pts: &[Point], u: &[f64], t0: Vec2, t1: Vec2) -> CubicBez {- let p0 = pts[0];- let p3 = *pts.last().unwrap();+ let (Some(&p0), Some(&p3)) = (pts.first(), pts.last()) else { return CubicBez::new(Point::ZERO, Point::ZERO, Point::ZERO, Point::ZERO) };let dir_in = -t1; // handle at the end points backwardslet (mut c00, mut c01, mut c11, mut x0, mut x1) = (0.0, 0.0, 0.0, 0.0, 0.0);for (p, &t) in pts.iter().zip(u) {diff --git a/crates/path/src/lib.rs b/crates/path/src/lib.rsindex 169a7428c..249eb9fdd 100644--- a/crates/path/src/lib.rs+++ b/crates/path/src/lib.rs@@ -5,6 +5,8 @@//! pucker & bloat, zig zag, twist, wiggle, offset, merge) live in [`ops`]; curve-preserving booleans//! (for Merge Paths) in [`boolean`] and curve offsetting in [`offset`].+#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]+pub mod boolean;pub mod feather;mod fit;diff --git a/crates/path/src/ops.rs b/crates/path/src/ops.rsindex 33537ba04..ec6e18604 100644--- a/crates/path/src/ops.rs+++ b/crates/path/src/ops.rs@@ -651,7 +651,8 @@ pub fn merge(paths: &[BezPath], mode: MergeMode) -> BezPath {MergeMode::Subtract => crate::boolean::boolean_n(&inputs, |m| m[0] && !m[1..].iter().any(|&b| b)),MergeMode::Intersect => crate::boolean::boolean_n(&inputs, |m| m.iter().all(|&b| b)),MergeMode::Exclude => crate::boolean::boolean_n(&inputs, |m| m.iter().filter(|&&b| b).count() % 2 == 1),- MergeMode::Merge => unreachable!(),+ // Handled above (no boolean operation).+ MergeMode::Merge => crate::boolean::boolean_n(&inputs, |m| m.iter().any(|&b| b)),}}diff --git a/crates/raster/src/inpaint.rs b/crates/raster/src/inpaint.rsindex a4ae40cec..15bdaa0dd 100644--- a/crates/raster/src/inpaint.rs+++ b/crates/raster/src/inpaint.rs@@ -497,7 +497,7 @@ pub fn patch_fill(img: &Image, hole: &[bool], init: Option<&Image>, patch: usize// Pyramid: stop while the image is still a few patches across.let mut levels = vec![fine];while levels.len() < 6 {- let last = levels.last().expect("level");+ let Some(last) = levels.last() else { break };if last.w.min(last.h) / 2 < patch * 4 || !last.hole.iter().any(|b| *b) {break;}@@ -774,7 +774,11 @@ pub fn fill_sequence(input: &FillInput, o: &FillOpts, progress: &mut dyn FnMut(uout[t] = Some(img.clone());} else {// Warp the previous result here along the backward flow (t → t − 1).- let prev = out[t - 1].as_ref().expect("previous frame");+ // Frames after `t0` are filled in order, so the previous one is set.+ let Some(prev) = out[t - 1].as_ref() else {+ out[t] = Some(patch_fill(img, left, None, o.patch, o.seed));+ continue;+ };let mut warped = img.clone();for i in 0..w * h {if left[i] {diff --git a/crates/raster/src/lib.rs b/crates/raster/src/lib.rsindex f3e64695e..f17602829 100644--- a/crates/raster/src/lib.rs+++ b/crates/raster/src/lib.rs@@ -3,6 +3,8 @@//! [`Image`] stores premultiplied RGBA in `f32` (values may exceed 1.0 in 32 bpc projects). Every//! heavy operation is row-parallel with rayon.+#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]+pub mod blur;pub mod channels3d;pub mod cuts;