Skip to content
Merged
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
11 changes: 6 additions & 5 deletions crates/rustc_codegen_spirv/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::collections::VecDeque;
use std::error::Error;
use std::path::{Path, PathBuf};
use std::process::{Command, ExitCode};
use std::string::ToString;
use std::{env, fs, mem};

/// Current `rust-toolchain.toml` file
Expand All @@ -33,15 +34,15 @@ fn get_rustc_commit_hash() -> Result<String, Box<dyn Error>> {
rustc_output("-vV")?
.lines()
.find_map(|l| l.strip_prefix("commit-hash: "))
.map(|s| s.to_string())
.map(ToString::to_string)
Comment on lines -36 to +37
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apropos of nothing, Lean4 has a cute syntax for this I wish more languages had:

.map(·.to_string())

(based on a quick GitHub search, they literally have (·.toString) for their equivalent of the Rust |x| x.to_string())

There's a few others, I think Perl is one, but it's not as common as it could be.

.ok_or_else(|| "`commit-hash` not found in `rustc -vV` output".into())
}

fn get_required_commit_hash() -> Result<String, Box<dyn Error>> {
REQUIRED_RUST_TOOLCHAIN
.lines()
.find_map(|l| l.strip_prefix("# commit_hash = "))
.map(|s| s.to_string())
.map(ToString::to_string)
.ok_or_else(|| "`commit_hash` not found in `rust-toolchain.toml`".into())
}

Expand Down Expand Up @@ -72,16 +73,16 @@ fn check_toolchain_version() -> Result<(), Box<dyn Error>> {
let stripped_toolchain = REQUIRED_RUST_TOOLCHAIN
.lines()
.filter(|l| !l.trim().is_empty() && !l.starts_with("# "))
.map(|l| l.to_string())
.map(ToString::to_string)
.reduce(|a, b| a + "\n" + &b)
.unwrap_or_default();

return Err(format!(
r#"error: wrong toolchain detected (found commit hash `{current_hash}`, expected `{required_hash}`).
"error: wrong toolchain detected (found commit hash `{current_hash}`, expected `{required_hash}`).
Make sure your `rust-toolchain.toml` file contains the following:
-------------
{stripped_toolchain}
-------------"#
-------------"
).into());
}
}
Expand Down