From bebe72095b18c5824e9774672fac79cd32a83ab4 Mon Sep 17 00:00:00 2001 From: Michael Weiss Date: Thu, 16 Nov 2023 18:31:45 +0100 Subject: [PATCH] clippy: Replace `get(0)` with `first()` This got detected and "fixed" (improved) by clippy's `get_first` [0] lint (beta toolchain version 1.75.0-beta.1). Clippy currently shows two more warnings from the `map_identity` [1] lint but those are false positives and a fix was already merged [2]. [0]: https://rust-lang.github.io/rust-clippy/master/index.html#/get_first [1]: https://rust-lang.github.io/rust-clippy/master/index.html#/map_identity [2]: https://github.com/rust-lang/rust-clippy/pull/11792 Signed-off-by: Michael Weiss --- src/commands/build.rs | 2 +- src/commands/endpoint_container.rs | 2 +- src/package/dependency/build.rs | 6 +++--- src/package/dependency/runtime.rs | 8 ++++---- src/repository/repository.rs | 6 +++--- src/util/filters.rs | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/commands/build.rs b/src/commands/build.rs index 46bca724..41cc135f 100644 --- a/src/commands/build.rs +++ b/src/commands/build.rs @@ -157,7 +157,7 @@ pub async fn build( )); } let package = *packages - .get(0) + .first() .ok_or_else(|| anyhow!("Found no package."))?; let release_stores = config diff --git a/src/commands/endpoint_container.rs b/src/commands/endpoint_container.rs index b7c6882e..0e102a45 100644 --- a/src/commands/endpoint_container.rs +++ b/src/commands/endpoint_container.rs @@ -52,7 +52,7 @@ pub async fn container( } let relevant_endpoint = relevant_endpoints - .get(0) + .first() .ok_or_else(|| anyhow!("Found no container for id {}", container_id))?; let container = relevant_endpoint diff --git a/src/package/dependency/build.rs b/src/package/dependency/build.rs index 678c5646..ad2440eb 100644 --- a/src/package/dependency/build.rs +++ b/src/package/dependency/build.rs @@ -128,7 +128,7 @@ mod tests { let s: TestSettings = toml::from_str(r#"settings = [{ name = "foo", condition = { in_image = "bar"} }]"#) .expect("Parsing TestSetting failed"); - match s.settings.get(0).expect("Has not one dependency") { + match s.settings.first().expect("Has not one dependency") { BuildDependency::Conditional { name, condition } => { assert_eq!(name, "foo", "Expected 'foo', got {name}"); assert_eq!(*condition.has_env(), None); @@ -152,7 +152,7 @@ mod tests { let s: TestSettings = toml::from_str(pretty).expect("Parsing TestSetting failed"); - match s.settings.get(0).expect("Has not one dependency") { + match s.settings.first().expect("Has not one dependency") { BuildDependency::Conditional { name, condition } => { assert_eq!(name, "foo", "Expected 'foo', got {name}"); assert_eq!(*condition.has_env(), None); @@ -176,7 +176,7 @@ mod tests { let s: TestSettings = toml::from_str(pretty).expect("Parsing TestSetting failed"); - match s.settings.get(0).expect("Has not one dependency") { + match s.settings.first().expect("Has not one dependency") { BuildDependency::Conditional { name, condition } => { assert_eq!(name, "foo", "Expected 'foo', got {name}"); assert_eq!(*condition.has_env(), None); diff --git a/src/package/dependency/runtime.rs b/src/package/dependency/runtime.rs index f077e57f..75708acb 100644 --- a/src/package/dependency/runtime.rs +++ b/src/package/dependency/runtime.rs @@ -142,7 +142,7 @@ mod tests { let s: TestSettings = toml::from_str(r#"settings = [{ name = "foo", condition = { in_image = "bar"} }]"#) .expect("Parsing TestSetting failed"); - match s.settings.get(0).expect("Has not one dependency") { + match s.settings.first().expect("Has not one dependency") { Dependency::Conditional { name, condition } => { assert_eq!(name, "foo", "Expected 'foo', got {name}"); assert_eq!(*condition.has_env(), None); @@ -166,7 +166,7 @@ mod tests { let s: TestSettings = toml::from_str(pretty).expect("Parsing TestSetting failed"); - match s.settings.get(0).expect("Has not one dependency") { + match s.settings.first().expect("Has not one dependency") { Dependency::Conditional { name, condition } => { assert_eq!(name, "foo", "Expected 'foo', got {name}"); assert_eq!(*condition.has_env(), None); @@ -190,7 +190,7 @@ mod tests { let s: TestSettings = toml::from_str(pretty).expect("Parsing TestSetting failed"); - match s.settings.get(0).expect("Has not one dependency") { + match s.settings.first().expect("Has not one dependency") { Dependency::Conditional { name, condition } => { assert_eq!(name, "foo", "Expected 'foo', got {name}"); assert_eq!(*condition.has_env(), None); @@ -218,7 +218,7 @@ mod tests { let s: TestSettings = toml::from_str(pretty).expect("Parsing TestSetting failed"); - match s.settings.get(0).expect("Has not one dependencies") { + match s.settings.first().expect("Has not one dependencies") { Dependency::Conditional { name, condition } => { assert_eq!(name, "foo", "Expected 'foo', got {name}"); assert_eq!(*condition.has_env(), None); diff --git a/src/repository/repository.rs b/src/repository/repository.rs index 87294ade..208ba262 100644 --- a/src/repository/repository.rs +++ b/src/repository/repository.rs @@ -205,7 +205,7 @@ pub mod tests { let ps = repo.find_by_name(&pname("a")); assert_eq!(ps.len(), 1); - let p = ps.get(0).unwrap(); + let p = ps.first().unwrap(); assert_eq!(*p.name(), pname("a")); assert_eq!(*p.version(), pversion("1")); assert!(!p.version_is_semver()); @@ -233,7 +233,7 @@ pub mod tests { let ps = repo.find(&pname("a"), &pversion("2")); assert_eq!(ps.len(), 1); - let p = ps.get(0).unwrap(); + let p = ps.first().unwrap(); assert_eq!(*p.name(), pname("a")); assert_eq!(*p.version(), pversion("2")); assert!(!p.version_is_semver()); @@ -269,7 +269,7 @@ pub mod tests { let ps = repo.find_with_version(&pname("a"), &constraint); assert_eq!(ps.len(), 1); - let p = ps.get(0).unwrap(); + let p = ps.first().unwrap(); assert_eq!(*p.name(), pname("a")); assert_eq!(*p.version(), pversion("2")); assert!(!p.version_is_semver()); diff --git a/src/util/filters.rs b/src/util/filters.rs index 7002b896..dca693ee 100644 --- a/src/util/filters.rs +++ b/src/util/filters.rs @@ -191,7 +191,7 @@ mod tests { .unwrap(); assert_eq!(found.len(), 1); - let p = found.get(0).unwrap(); + let p = found.first().unwrap(); assert_eq!(*p.name(), pname("a")); assert_eq!( *p.dependencies().runtime(), @@ -289,7 +289,7 @@ mod tests { .unwrap(); assert_eq!(found.len(), 1); - let p = found.get(0).unwrap(); + let p = found.first().unwrap(); assert_eq!(*p.name(), pname("a")); assert_eq!( *p.dependencies().runtime(), @@ -346,7 +346,7 @@ mod tests { assert_eq!(found.len(), 2); { - let p = found.get(0).unwrap(); + let p = found.first().unwrap(); assert_eq!(*p.name(), pname("a")); assert_eq!( *p.dependencies().runtime(),