diff --git a/crates/turborepo-wax/src/capture.rs b/crates/turborepo-wax/src/capture.rs index 93184d6e722df..5ca4080998621 100644 --- a/crates/turborepo-wax/src/capture.rs +++ b/crates/turborepo-wax/src/capture.rs @@ -30,7 +30,11 @@ impl<'t> From> for OwnedText { impl<'m, 't> From<&'m BorrowedText<'t>> for OwnedText { fn from(captures: &'m BorrowedText<'t>) -> Self { - let matched = captures.get(0).unwrap().as_str().into(); + let matched = captures + .get(0) + .expect("captures have no complete text") + .as_str() + .into(); let ranges = captures .iter() .skip(1) diff --git a/crates/turborepo-wax/src/lib.rs b/crates/turborepo-wax/src/lib.rs index f333a3608cc5a..00da445ae6e90 100644 --- a/crates/turborepo-wax/src/lib.rs +++ b/crates/turborepo-wax/src/lib.rs @@ -32,7 +32,7 @@ clippy::unreadable_literal, clippy::unused_self )] -#![allow(clippy::expect_used, clippy::unwrap_used)] +#![allow(clippy::expect_used)] mod capture; mod diagnostics; diff --git a/crates/turborepo-wax/src/rule.rs b/crates/turborepo-wax/src/rule.rs index a1e716fb676b0..da3c7ddef6ae9 100644 --- a/crates/turborepo-wax/src/rule.rs +++ b/crates/turborepo-wax/src/rule.rs @@ -140,13 +140,10 @@ trait SliceExt { impl SliceExt for [T] { fn terminals(&self) -> Option> { - match self.len() { - 0 => None, - 1 => Some(Terminals::Only(self.first().unwrap())), - _ => Some(Terminals::StartEnd( - self.first().unwrap(), - self.last().unwrap(), - )), + match self { + [] => None, + [only] => Some(Terminals::Only(only)), + [first, .., last] => Some(Terminals::StartEnd(first, last)), } } } diff --git a/crates/turborepo-wax/src/token/mod.rs b/crates/turborepo-wax/src/token/mod.rs index 999172261c3b7..82b9404ec888e 100644 --- a/crates/turborepo-wax/src/token/mod.rs +++ b/crates/turborepo-wax/src/token/mod.rs @@ -919,14 +919,9 @@ impl<'i, 't> LiteralSequence<'i, 't> { } pub fn text(&self) -> Cow<'t, str> { - if self.literals().len() == 1 { - self.literals().first().unwrap().text.clone() - } else { - self.literals() - .iter() - .map(|literal| &literal.text) - .join("") - .into() + match self.literals() { + [literal] => literal.text.clone(), + literals => literals.iter().map(|literal| &literal.text).join("").into(), } } diff --git a/crates/turborepo-wax/src/walk/mod.rs b/crates/turborepo-wax/src/walk/mod.rs index 2bc8e1fdd1fb2..84b84da127c1c 100644 --- a/crates/turborepo-wax/src/walk/mod.rs +++ b/crates/turborepo-wax/src/walk/mod.rs @@ -128,7 +128,9 @@ trait SplitAtDepth { impl SplitAtDepth for Path { fn split_at_depth(&self, depth: usize) -> (&Path, &Path) { let ancestor = self.ancestors().nth(depth).unwrap_or(Path::new("")); - let descendant = self.strip_prefix(ancestor).unwrap(); + let descendant = self + .strip_prefix(ancestor) + .expect("path ancestor is not a prefix"); (ancestor, descendant) } }