diff --git a/crates/uv-fs/src/path.rs b/crates/uv-fs/src/path.rs index 2e58930e6ab..8e6eded8f94 100644 --- a/crates/uv-fs/src/path.rs +++ b/crates/uv-fs/src/path.rs @@ -174,12 +174,12 @@ pub fn normalize_url_path(path: &str) -> Cow<'_, str> { /// For example, `./a/../../b` cannot be normalized because it escapes the base directory. pub fn normalize_absolute_path(path: &Path) -> Result { let mut components = path.components().peekable(); - let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().copied() { - components.next(); - PathBuf::from(c.as_os_str()) - } else { - PathBuf::new() - }; + let mut ret = components + .next_if_map_mut(|component| match component { + Component::Prefix(..) => Some(PathBuf::from(component.as_os_str())), + _ => None, + }) + .unwrap_or_default(); for component in components { match component { diff --git a/crates/uv-install-wheel/src/uninstall.rs b/crates/uv-install-wheel/src/uninstall.rs index 6853bb951c8..22db0f96a84 100644 --- a/crates/uv-install-wheel/src/uninstall.rs +++ b/crates/uv-install-wheel/src/uninstall.rs @@ -429,12 +429,12 @@ pub struct Uninstall { /// Source: fn normalize_path(path: &Path) -> PathBuf { let mut components = path.components().peekable(); - let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().copied() { - components.next(); - PathBuf::from(c.as_os_str()) - } else { - PathBuf::new() - }; + let mut ret = components + .next_if_map_mut(|component| match component { + Component::Prefix(..) => Some(PathBuf::from(component.as_os_str())), + _ => None, + }) + .unwrap_or_default(); for component in components { match component { diff --git a/crates/uv-resolver/src/lock/mod.rs b/crates/uv-resolver/src/lock/mod.rs index c1c5d17f55f..5fc0c3e1668 100644 --- a/crates/uv-resolver/src/lock/mod.rs +++ b/crates/uv-resolver/src/lock/mod.rs @@ -504,8 +504,7 @@ impl Lock { // check for duplicates. for package in &mut packages { package.dependencies.sort(); - for windows in package.dependencies.windows(2) { - let (dep1, dep2) = (&windows[0], &windows[1]); + for [dep1, dep2] in package.dependencies.array_windows() { if dep1 == dep2 { return Err(LockErrorKind::DuplicateDependency { id: package.id.clone(), @@ -518,8 +517,7 @@ impl Lock { // Perform the same validation for optional dependencies. for (extra, dependencies) in &mut package.optional_dependencies { dependencies.sort(); - for windows in dependencies.windows(2) { - let (dep1, dep2) = (&windows[0], &windows[1]); + for [dep1, dep2] in dependencies.array_windows() { if dep1 == dep2 { return Err(LockErrorKind::DuplicateOptionalDependency { id: package.id.clone(), @@ -534,8 +532,7 @@ impl Lock { // Perform the same validation for dev dependencies. for (group, dependencies) in &mut package.dependency_groups { dependencies.sort(); - for windows in dependencies.windows(2) { - let (dep1, dep2) = (&windows[0], &windows[1]); + for [dep1, dep2] in dependencies.array_windows() { if dep1 == dep2 { return Err(LockErrorKind::DuplicateDevDependency { id: package.id.clone(), diff --git a/crates/uv-workspace/src/pyproject.rs b/crates/uv-workspace/src/pyproject.rs index 11db8a05cb9..4e5322acb60 100644 --- a/crates/uv-workspace/src/pyproject.rs +++ b/crates/uv-workspace/src/pyproject.rs @@ -1141,7 +1141,7 @@ impl TryFrom for Sources { match wire { SourcesWire::One(source) => Ok(Self(vec![source])), SourcesWire::Many(sources) => { - for (lhs, rhs) in sources.iter().zip(sources.iter().skip(1)) { + for [lhs, rhs] in sources.array_windows() { if lhs.extra() != rhs.extra() { continue; } diff --git a/crates/uv/src/commands/project/lock.rs b/crates/uv/src/commands/project/lock.rs index 6e919334c85..22d47a4ca5a 100644 --- a/crates/uv/src/commands/project/lock.rs +++ b/crates/uv/src/commands/project/lock.rs @@ -584,11 +584,7 @@ async fn do_lock( // Ensure that the environments are disjoint. if let Some(environments) = &environments { - for (lhs, rhs) in environments - .as_markers() - .iter() - .zip(environments.as_markers().iter().skip(1)) - { + for [lhs, rhs] in environments.as_markers().array_windows() { if !lhs.is_disjoint(*rhs) { let mut hint = lhs.negate(); hint.and(*rhs); @@ -618,11 +614,7 @@ async fn do_lock( let required_environments = if let Some(required_environments) = target.required_environments() { // Ensure that the environments are disjoint. - for (lhs, rhs) in required_environments - .as_markers() - .iter() - .zip(required_environments.as_markers().iter().skip(1)) - { + for [lhs, rhs] in required_environments.as_markers().array_windows() { if !lhs.is_disjoint(*rhs) { let mut hint = lhs.negate(); hint.and(*rhs); diff --git a/crates/uv/src/install_source.rs b/crates/uv/src/install_source.rs index ab0e9c168d8..2001e64f7c1 100644 --- a/crates/uv/src/install_source.rs +++ b/crates/uv/src/install_source.rs @@ -25,8 +25,8 @@ impl InstallSource { let formula = OsStr::new("uv"); if components - .windows(2) - .any(|window| window[0] == cellar && window[1] == formula) + .array_windows() + .any(|[component, next]| component == cellar && next == formula) { return Some(Self::Homebrew); } diff --git a/crates/uv/tests/it/network.rs b/crates/uv/tests/it/network.rs index c3d8773bd86..aca9f66472f 100644 --- a/crates/uv/tests/it/network.rs +++ b/crates/uv/tests/it/network.rs @@ -44,7 +44,10 @@ fn start_connect_tunnel_proxy() -> std::net::SocketAddr { Ok(n) => n, }; total_read += n; - if buf[..total_read].windows(4).any(|w| w == b"\r\n\r\n") { + if buf[..total_read] + .array_windows() + .any(|window| window == b"\r\n\r\n") + { break; } }