Skip to content

Commit e5a0e18

Browse files
authored
Use Rust 1.94.0 features (#19612)
Following #19600
1 parent f69c1b2 commit e5a0e18

7 files changed

Lines changed: 24 additions & 32 deletions

File tree

crates/uv-fs/src/path.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@ pub fn normalize_url_path(path: &str) -> Cow<'_, str> {
174174
/// For example, `./a/../../b` cannot be normalized because it escapes the base directory.
175175
pub fn normalize_absolute_path(path: &Path) -> Result<PathBuf, std::io::Error> {
176176
let mut components = path.components().peekable();
177-
let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().copied() {
178-
components.next();
179-
PathBuf::from(c.as_os_str())
180-
} else {
181-
PathBuf::new()
182-
};
177+
let mut ret = components
178+
.next_if_map_mut(|component| match component {
179+
Component::Prefix(..) => Some(PathBuf::from(component.as_os_str())),
180+
_ => None,
181+
})
182+
.unwrap_or_default();
183183

184184
for component in components {
185185
match component {

crates/uv-install-wheel/src/uninstall.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -429,12 +429,12 @@ pub struct Uninstall {
429429
/// Source: <https://github.com/rust-lang/cargo/blob/b48c41aedbd69ee3990d62a0e2006edbb506a480/crates/cargo-util/src/paths.rs#L76C1-L109C2>
430430
fn normalize_path(path: &Path) -> PathBuf {
431431
let mut components = path.components().peekable();
432-
let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().copied() {
433-
components.next();
434-
PathBuf::from(c.as_os_str())
435-
} else {
436-
PathBuf::new()
437-
};
432+
let mut ret = components
433+
.next_if_map_mut(|component| match component {
434+
Component::Prefix(..) => Some(PathBuf::from(component.as_os_str())),
435+
_ => None,
436+
})
437+
.unwrap_or_default();
438438

439439
for component in components {
440440
match component {

crates/uv-resolver/src/lock/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,7 @@ impl Lock {
504504
// check for duplicates.
505505
for package in &mut packages {
506506
package.dependencies.sort();
507-
for windows in package.dependencies.windows(2) {
508-
let (dep1, dep2) = (&windows[0], &windows[1]);
507+
for [dep1, dep2] in package.dependencies.array_windows() {
509508
if dep1 == dep2 {
510509
return Err(LockErrorKind::DuplicateDependency {
511510
id: package.id.clone(),
@@ -518,8 +517,7 @@ impl Lock {
518517
// Perform the same validation for optional dependencies.
519518
for (extra, dependencies) in &mut package.optional_dependencies {
520519
dependencies.sort();
521-
for windows in dependencies.windows(2) {
522-
let (dep1, dep2) = (&windows[0], &windows[1]);
520+
for [dep1, dep2] in dependencies.array_windows() {
523521
if dep1 == dep2 {
524522
return Err(LockErrorKind::DuplicateOptionalDependency {
525523
id: package.id.clone(),
@@ -534,8 +532,7 @@ impl Lock {
534532
// Perform the same validation for dev dependencies.
535533
for (group, dependencies) in &mut package.dependency_groups {
536534
dependencies.sort();
537-
for windows in dependencies.windows(2) {
538-
let (dep1, dep2) = (&windows[0], &windows[1]);
535+
for [dep1, dep2] in dependencies.array_windows() {
539536
if dep1 == dep2 {
540537
return Err(LockErrorKind::DuplicateDevDependency {
541538
id: package.id.clone(),

crates/uv-workspace/src/pyproject.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@ impl TryFrom<SourcesWire> for Sources {
11411141
match wire {
11421142
SourcesWire::One(source) => Ok(Self(vec![source])),
11431143
SourcesWire::Many(sources) => {
1144-
for (lhs, rhs) in sources.iter().zip(sources.iter().skip(1)) {
1144+
for [lhs, rhs] in sources.array_windows() {
11451145
if lhs.extra() != rhs.extra() {
11461146
continue;
11471147
}

crates/uv/src/commands/project/lock.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -584,11 +584,7 @@ async fn do_lock(
584584

585585
// Ensure that the environments are disjoint.
586586
if let Some(environments) = &environments {
587-
for (lhs, rhs) in environments
588-
.as_markers()
589-
.iter()
590-
.zip(environments.as_markers().iter().skip(1))
591-
{
587+
for [lhs, rhs] in environments.as_markers().array_windows() {
592588
if !lhs.is_disjoint(*rhs) {
593589
let mut hint = lhs.negate();
594590
hint.and(*rhs);
@@ -618,11 +614,7 @@ async fn do_lock(
618614
let required_environments = if let Some(required_environments) = target.required_environments()
619615
{
620616
// Ensure that the environments are disjoint.
621-
for (lhs, rhs) in required_environments
622-
.as_markers()
623-
.iter()
624-
.zip(required_environments.as_markers().iter().skip(1))
625-
{
617+
for [lhs, rhs] in required_environments.as_markers().array_windows() {
626618
if !lhs.is_disjoint(*rhs) {
627619
let mut hint = lhs.negate();
628620
hint.and(*rhs);

crates/uv/src/install_source.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ impl InstallSource {
2525
let formula = OsStr::new("uv");
2626

2727
if components
28-
.windows(2)
29-
.any(|window| window[0] == cellar && window[1] == formula)
28+
.array_windows()
29+
.any(|[component, next]| component == cellar && next == formula)
3030
{
3131
return Some(Self::Homebrew);
3232
}

crates/uv/tests/it/network.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ fn start_connect_tunnel_proxy() -> std::net::SocketAddr {
4444
Ok(n) => n,
4545
};
4646
total_read += n;
47-
if buf[..total_read].windows(4).any(|w| w == b"\r\n\r\n") {
47+
if buf[..total_read]
48+
.array_windows()
49+
.any(|window| window == b"\r\n\r\n")
50+
{
4851
break;
4952
}
5053
}

0 commit comments

Comments
 (0)