Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions crates/uv-fs/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf, std::io::Error> {
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 {
Expand Down
12 changes: 6 additions & 6 deletions crates/uv-install-wheel/src/uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,12 +429,12 @@ pub struct Uninstall {
/// Source: <https://github.com/rust-lang/cargo/blob/b48c41aedbd69ee3990d62a0e2006edbb506a480/crates/cargo-util/src/paths.rs#L76C1-L109C2>
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 {
Expand Down
9 changes: 3 additions & 6 deletions crates/uv-resolver/src/lock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-workspace/src/pyproject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ impl TryFrom<SourcesWire> 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;
}
Expand Down
12 changes: 2 additions & 10 deletions crates/uv/src/commands/project/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/src/install_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion crates/uv/tests/it/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Loading