Skip to content

Commit

Permalink
make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
Emilgardis committed Jan 10, 2024
1 parent a3dd37b commit cabfc3b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 40 deletions.
6 changes: 3 additions & 3 deletions src/docker/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl PossibleImage {
}
} else {
let platform = if self.toolchain.len() == 1 {
self.toolchain.get(0).expect("should contain at least one")
self.toolchain.first().expect("should contain at least one")
} else {
let same_arch = self
.toolchain
Expand All @@ -48,7 +48,7 @@ impl PossibleImage {

if same_arch.len() == 1 {
// pick the platform with the same architecture
same_arch.get(0).expect("should contain one element")
same_arch.first().expect("should contain one element")
} else if let Some(platform) = same_arch
.iter()
.find(|platform| &platform.os == engine.os.as_ref().unwrap_or(&Os::Linux))
Expand All @@ -62,7 +62,7 @@ impl PossibleImage {
} else {
let platform = self
.toolchain
.get(0)
.first()
.expect("should be at least one platform");
// FIXME: Don't throw away
msg_info.warn(
Expand Down
4 changes: 2 additions & 2 deletions src/docker/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@ pub fn get_image_name(
};

Ok(compatible
.get(0)
.first()
.expect("should not be empty")
.image_name(CROSS_IMAGE, version))
}
Expand Down Expand Up @@ -1316,7 +1316,7 @@ pub fn get_image(

let pick = if compatible.len() == 1 {
// If only one match, use that
compatible.get(0).expect("should not be empty")
compatible.first().expect("should not be empty")
} else if compatible
.iter()
.filter(|provided| provided.sub.is_none())
Expand Down
9 changes: 5 additions & 4 deletions src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,9 @@ pub fn default_ident() -> usize {

#[must_use]
pub fn indent(message: &str, spaces: usize) -> String {
message
.lines()
.map(|s| format!("{:spaces$}{s}", ""))
.collect()
use std::fmt::Write as _;
message.lines().fold(String::new(), |mut string, line| {
let _ = write!(string, "{:spaces$}{line}", "");
string
})
}
6 changes: 3 additions & 3 deletions xtask/src/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl IdType {

impl cmp::PartialOrd for IdType {
fn partial_cmp(&self, other: &IdType) -> Option<cmp::Ordering> {
self.max_number().partial_cmp(&other.max_number())
Some(self.cmp(other))
}
}

Expand Down Expand Up @@ -141,7 +141,7 @@ impl ChangelogType {

impl cmp::PartialOrd for ChangelogType {
fn partial_cmp(&self, other: &ChangelogType) -> Option<cmp::Ordering> {
self.sort_by().partial_cmp(&other.sort_by())
Some(self.cmp(other))
}
}

Expand Down Expand Up @@ -171,7 +171,7 @@ impl ChangelogContents {

impl cmp::PartialOrd for ChangelogContents {
fn partial_cmp(&self, other: &ChangelogContents) -> Option<cmp::Ordering> {
self.sort_by().partial_cmp(&other.sort_by())
Some(self.cmp(other))
}
}

Expand Down
4 changes: 2 additions & 2 deletions xtask/src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ fn python_lint(flake8: Option<&str>, msg_info: &mut MessageInfo) -> cross::Resul
.map(parse_command)
.unwrap_or_else(|| Ok(vec!["flake8".to_owned()]))?;
let mut cmd = Command::new(
args.get(0)
args.first()
.ok_or_else(|| eyre::eyre!("empty string provided for flake8 command"))?,
);
cmd.args(&args[1..]);
Expand All @@ -160,7 +160,7 @@ fn python_test(tox: Option<&str>, msg_info: &mut MessageInfo) -> cross::Result<(
.map(parse_command)
.unwrap_or_else(|| Ok(vec!["tox".to_owned()]))?;
let mut cmd = Command::new(
args.get(0)
args.first()
.ok_or_else(|| eyre::eyre!("empty string provided for tox command"))?,
);
cmd.args(&args[1..]);
Expand Down
52 changes: 26 additions & 26 deletions xtask/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,32 @@ pub fn read_dockerfiles(msg_info: &mut MessageInfo) -> cross::Result<Vec<(PathBu
Ok(dockerfiles)
}

pub fn write_to_string(path: &Path, contents: &str) -> cross::Result<()> {
let mut file = fs::OpenOptions::new()
.write(true)
.truncate(true)
.create(true)
.open(path)?;
writeln!(file, "{}", contents)?;
Ok(())
}

// https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#environment-files
pub fn write_to_gha_env_file(env_name: &str, contents: &str) -> cross::Result<()> {
let path = if let Ok(path) = env::var(env_name) {
PathBuf::from(path)
} else {
eyre::ensure!(
env::var("GITHUB_ACTIONS").is_err(),
"expected GHA envfile to exist"
);
return Ok(());
};
let mut file = fs::OpenOptions::new().append(true).open(path)?;
writeln!(file, "{}", contents)?;
Ok(())
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -416,29 +442,3 @@ mod tests {
}
}
}

pub fn write_to_string(path: &Path, contents: &str) -> cross::Result<()> {
let mut file = fs::OpenOptions::new()
.write(true)
.truncate(true)
.create(true)
.open(path)?;
writeln!(file, "{}", contents)?;
Ok(())
}

// https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#environment-files
pub fn write_to_gha_env_file(env_name: &str, contents: &str) -> cross::Result<()> {
let path = if let Ok(path) = env::var(env_name) {
PathBuf::from(path)
} else {
eyre::ensure!(
env::var("GITHUB_ACTIONS").is_err(),
"expected GHA envfile to exist"
);
return Ok(());
};
let mut file = fs::OpenOptions::new().append(true).open(path)?;
writeln!(file, "{}", contents)?;
Ok(())
}

0 comments on commit cabfc3b

Please sign in to comment.