Skip to content

Commit

Permalink
clippy: Replace get(0) with first()
Browse files Browse the repository at this point in the history
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]: rust-lang/rust-clippy#11792

Signed-off-by: Michael Weiss <michael.weiss@atos.net>
  • Loading branch information
primeos-work committed Nov 16, 2023
1 parent 97a62ab commit bebe720
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/commands/endpoint_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/package/dependency/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/package/dependency/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/repository/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
6 changes: 3 additions & 3 deletions src/util/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit bebe720

Please sign in to comment.