Skip to content

Commit

Permalink
upgrade Rust to v1.67.0 (pantsbuild#18109)
Browse files Browse the repository at this point in the history
Upgrade Rust to v1.67.0.

Lots of changes due to clippy lints:
- `clippy::uninlined_format_args`: `format!("{}", err)` must now be `format!("{err}")`. These changes were made with `cargp clippy --fix`.
- `clippy::let_underscore_future`: Have to explicitly drop a future and not bind it to `_`.
- `clippy::needless_lifetimes`: One call site fixed.
  • Loading branch information
tdyas authored Jan 28, 2023
1 parent bb67f02 commit 8da1ced
Show file tree
Hide file tree
Showing 102 changed files with 616 additions and 940 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test-cron.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
uses: actions/cache@v3
with:
key: Linux-ARM64-rustup-${{ hashFiles('rust-toolchain') }}-v2
path: '~/.rustup/toolchains/1.66.1-*
path: '~/.rustup/toolchains/1.67.0-*
~/.rustup/update-hashes
Expand Down Expand Up @@ -134,7 +134,7 @@ jobs:
uses: actions/cache@v3
with:
key: Linux-x86_64-rustup-${{ hashFiles('rust-toolchain') }}-v2
path: '~/.rustup/toolchains/1.66.1-*
path: '~/.rustup/toolchains/1.67.0-*
~/.rustup/update-hashes
Expand Down Expand Up @@ -249,7 +249,7 @@ jobs:
uses: actions/cache@v3
with:
key: macOS11-x86_64-rustup-${{ hashFiles('rust-toolchain') }}-v2
path: '~/.rustup/toolchains/1.66.1-*
path: '~/.rustup/toolchains/1.67.0-*
~/.rustup/update-hashes
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
uses: actions/cache@v3
with:
key: Linux-ARM64-rustup-${{ hashFiles('rust-toolchain') }}-v2
path: '~/.rustup/toolchains/1.66.1-*
path: '~/.rustup/toolchains/1.67.0-*
~/.rustup/update-hashes
Expand Down Expand Up @@ -139,7 +139,7 @@ jobs:
uses: actions/cache@v3
with:
key: Linux-x86_64-rustup-${{ hashFiles('rust-toolchain') }}-v2
path: '~/.rustup/toolchains/1.66.1-*
path: '~/.rustup/toolchains/1.67.0-*
~/.rustup/update-hashes
Expand Down Expand Up @@ -256,7 +256,7 @@ jobs:
uses: actions/cache@v3
with:
key: macOS11-x86_64-rustup-${{ hashFiles('rust-toolchain') }}-v2
path: '~/.rustup/toolchains/1.66.1-*
path: '~/.rustup/toolchains/1.67.0-*
~/.rustup/update-hashes
Expand Down Expand Up @@ -488,7 +488,7 @@ jobs:
uses: actions/cache@v3
with:
key: macOS10-15-x86_64-rustup-${{ hashFiles('rust-toolchain') }}-v2
path: '~/.rustup/toolchains/1.66.1-*
path: '~/.rustup/toolchains/1.67.0-*
~/.rustup/update-hashes
Expand Down Expand Up @@ -557,7 +557,7 @@ jobs:
uses: actions/cache@v3
with:
key: macOS11-ARM64-rustup-${{ hashFiles('rust-toolchain') }}-v2
path: '~/.rustup/toolchains/1.66.1-*
path: '~/.rustup/toolchains/1.67.0-*
~/.rustup/update-hashes
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[toolchain]
channel = "1.66.1"
channel = "1.67.0"
components = [
"cargo",
"clippy",
Expand Down
1 change: 0 additions & 1 deletion src/rust/engine/async_value/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::AsyncValue;

use std::time::Duration;

use tokio;
use tokio::time::sleep;

#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion src/rust/engine/cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl PersistentCache {
lease_time,
shard_count,
)
.map_err(|err| format!("Could not initialize store for cache: {:?}", err))?;
.map_err(|err| format!("Could not initialize store for cache: {err:?}"))?;

Ok(Self { store })
}
Expand Down
4 changes: 2 additions & 2 deletions src/rust/engine/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub async fn execute_command(
"PANTSD_RUNTRACKER_CLIENT_START_TIME".to_owned(),
start
.duration_since(SystemTime::UNIX_EPOCH)
.map_err(|e| format!("Failed to determine current time: {err}", err = e))?
.map_err(|e| format!("Failed to determine current time: {e}"))?
.as_secs_f64()
.to_string(),
));
Expand Down Expand Up @@ -62,7 +62,7 @@ pub async fn execute_command(
if connection_settings.dynamic_ui {
if let Ok(path) = nix::unistd::ttyname(*raw_fd) {
env.push((
format!("NAILGUN_TTY_PATH_{fd}", fd = raw_fd),
format!("NAILGUN_TTY_PATH_{raw_fd}"),
path.display().to_string(),
));
}
Expand Down
6 changes: 3 additions & 3 deletions src/rust/engine/client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ async fn execute(start: SystemTime) -> Result<i32, String> {
})?;
env_logger::init_from_env(env_logger::Env::new().filter_or("__PANTS_LEVEL__", level.as_ref()));

let working_dir = env::current_dir()
.map_err(|e| format!("Could not detect current working directory: {err}", err = e))?;
let working_dir =
env::current_dir().map_err(|e| format!("Could not detect current working directory: {e}"))?;
let pantsd_settings = find_pantsd(&working_dir, &options_parser)?;
let env = env::vars().collect::<Vec<(_, _)>>();
let argv = env::args().collect::<Vec<_>>();
Expand Down Expand Up @@ -147,7 +147,7 @@ async fn main() {
let start = SystemTime::now();
match execute(start).await {
Err(err) => {
eprintln!("{}", err);
eprintln!("{err}");
// We use this exit code to indicate an error running pants via the nailgun protocol to
// differentiate from a successful nailgun protocol session.
std::process::exit(EX_TEMPFAIL);
Expand Down
13 changes: 5 additions & 8 deletions src/rust/engine/client/src/pantsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub(crate) struct Metadata {

impl Metadata {
pub(crate) fn mount<P: AsRef<Path>>(directory: P) -> Result<Metadata, String> {
let info = uname::uname().map_err(|e| format!("{}", e))?;
let info = uname::uname().map_err(|e| format!("{e}"))?;
let host_hash = Sha256::new()
.chain(&info.sysname)
.chain(&info.nodename)
Expand All @@ -28,7 +28,7 @@ impl Metadata {
const HOST_FINGERPRINT_LENGTH: usize = 12;
let mut hex_digest = String::with_capacity(HOST_FINGERPRINT_LENGTH);
for byte in host_hash {
fmt::Write::write_fmt(&mut hex_digest, format_args!("{:02x}", byte)).unwrap();
fmt::Write::write_fmt(&mut hex_digest, format_args!("{byte:02x}")).unwrap();
if hex_digest.len() >= HOST_FINGERPRINT_LENGTH {
break;
}
Expand Down Expand Up @@ -140,7 +140,7 @@ pub fn probe(working_dir: &Path, metadata_dir: &Path) -> Result<u16, String> {
// wrapped).
if std::mem::discriminant(&ProcessStatus::Zombie) == std::mem::discriminant(&process.status())
{
return Err(format!("The pantsd at pid {pid} is a zombie.", pid = pid));
return Err(format!("The pantsd at pid {pid} is a zombie."));
}
let expected_process_name_prefix = pantsd_metadata.process_name()?;
let actual_argv0 = {
Expand All @@ -158,11 +158,8 @@ pub fn probe(working_dir: &Path, metadata_dir: &Path) -> Result<u16, String> {
Err(format!(
"\
The process with pid {pid} is not pantsd. Expected a process name matching \
{expected_name} but is {actual_name}.\
",
pid = pid,
expected_name = expected_process_name_prefix,
actual_name = actual_argv0
{expected_process_name_prefix} but is {actual_argv0}.\
"
))
}
}
Expand Down
8 changes: 1 addition & 7 deletions src/rust/engine/client/src/pantsd_testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ pub(crate) fn launch_pantsd() -> (BuildRoot, TempDir) {
.stderr(Stdio::inherit());
let result = cmd
.output()
.map_err(|e| {
format!(
"Problem running command {command:?}: {err}",
command = cmd,
err = e
)
})
.map_err(|e| format!("Problem running command {cmd:?}: {e}"))
.unwrap();
assert_eq!(Some(0), result.status.code());
assert_eq!(
Expand Down
3 changes: 1 addition & 2 deletions src/rust/engine/concrete_time/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ impl TimeSpan {
duration: duration.into(),
}),
None => Err(format!(
"Got negative {} time: {:?} - {:?}",
time_span_description, end, start
"Got negative {time_span_description} time: {end:?} - {start:?}"
)),
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/rust/engine/fs/brfs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ pub fn digest_from_filepath(str: &str) -> Result<Digest, String> {
let mut parts = str.split('-');
let fingerprint_str = parts
.next()
.ok_or_else(|| format!("Invalid digest: {} wasn't of form fingerprint-size", str))?;
.ok_or_else(|| format!("Invalid digest: {str} wasn't of form fingerprint-size"))?;
let fingerprint = Fingerprint::from_hex_string(fingerprint_str)?;
let size_bytes = parts
.next()
.ok_or_else(|| format!("Invalid digest: {} wasn't of form fingerprint-size", str))?
.ok_or_else(|| format!("Invalid digest: {str} wasn't of form fingerprint-size"))?
.parse::<usize>()
.map_err(|err| format!("Invalid digest; size {} not a number: {}", str, err))?;
.map_err(|err| format!("Invalid digest; size {str} not a number: {err}"))?;
Ok(Digest::new(fingerprint, size_bytes))
}

Expand Down Expand Up @@ -799,7 +799,7 @@ async fn main() {
F: Fn() -> SignalKind,
{
SignalStream::new(
signal(install_fn()).unwrap_or_else(|_| panic!("Failed to install SIG{:?} handler", sig)),
signal(install_fn()).unwrap_or_else(|_| panic!("Failed to install SIG{sig:?} handler")),
)
.map(move |_| Some(sig))
}
Expand Down
49 changes: 17 additions & 32 deletions src/rust/engine/fs/fs_util/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,8 @@ async fn execute(top_match: &clap::ArgMatches) -> Result<(), ExitError> {
.unwrap_or_else(Store::default_path);
let runtime = task_executor::Executor::new();
let (store, store_has_remote) = {
let local_only = Store::local_only(runtime.clone(), &store_dir).map_err(|e| {
format!(
"Failed to open/create store for directory {:?}: {}",
store_dir, e
)
})?;
let local_only = Store::local_only(runtime.clone(), &store_dir)
.map_err(|e| format!("Failed to open/create store for directory {store_dir:?}: {e}"))?;
let (store_result, store_has_remote) = match top_match.value_of("server-address") {
Some(cas_address) => {
let chunk_size = top_match
Expand All @@ -353,7 +349,7 @@ async fn execute(top_match: &clap::ArgMatches) -> Result<(), ExitError> {
let root_ca_certs = if let Some(path) = top_match.value_of("root-ca-cert-file") {
Some(
std::fs::read(path)
.map_err(|err| format!("Error reading root CA certs file {}: {}", path, err))?,
.map_err(|err| format!("Error reading root CA certs file {path}: {err}"))?,
)
} else {
None
Expand All @@ -365,15 +361,11 @@ async fn execute(top_match: &clap::ArgMatches) -> Result<(), ExitError> {
) {
(Some(cert_chain_path), Some(key_path)) => {
let key = std::fs::read(key_path).map_err(|err| {
format!(
"Failed to read mtls-client-key-path from {:?}: {:?}",
key_path, err
)
format!("Failed to read mtls-client-key-path from {key_path:?}: {err:?}")
})?;
let cert_chain = std::fs::read(cert_chain_path).map_err(|err| {
format!(
"Failed to read mtls-client-certificate-chain-path from {:?}: {:?}",
cert_chain_path, err
"Failed to read mtls-client-certificate-chain-path from {cert_chain_path:?}: {err:?}"
)
})?;
Some(MtlsConfig { key, cert_chain })
Expand Down Expand Up @@ -403,17 +395,14 @@ async fn execute(top_match: &clap::ArgMatches) -> Result<(), ExitError> {
if let Some((key, value)) = h.split_once('=') {
headers.insert(key.to_owned(), value.to_owned());
} else {
panic!("Expected --header flag to contain = but was {}", h);
panic!("Expected --header flag to contain = but was {h}");
}
}
}

if let Some(oauth_path) = top_match.value_of("oauth-bearer-token-file") {
let token = std::fs::read_to_string(oauth_path).map_err(|err| {
format!(
"Error reading oauth bearer token from {:?}: {}",
oauth_path, err
)
format!("Error reading oauth bearer token from {oauth_path:?}: {err}")
})?;
headers.insert(
"authorization".to_owned(),
Expand Down Expand Up @@ -482,14 +471,14 @@ async fn execute(top_match: &clap::ArgMatches) -> Result<(), ExitError> {
runtime.clone(),
path
.canonicalize()
.map_err(|e| format!("Error canonicalizing path {:?}: {:?}", path, e))?
.map_err(|e| format!("Error canonicalizing path {path:?}: {e:?}"))?
.parent()
.ok_or_else(|| format!("File being saved must have parent but {:?} did not", path))?,
.ok_or_else(|| format!("File being saved must have parent but {path:?} did not"))?,
);
let file = posix_fs
.stat_sync(PathBuf::from(path.file_name().unwrap()))
.unwrap()
.ok_or_else(|| format!("Tried to save file {:?} but it did not exist", path))?;
.ok_or_else(|| format!("Tried to save file {path:?} but it did not exist"))?;
match file {
fs::Stat::File(f) => {
let digest =
Expand All @@ -505,13 +494,9 @@ async fn execute(top_match: &clap::ArgMatches) -> Result<(), ExitError> {

Ok(())
}
o => Err(
format!(
"Tried to save file {:?} but it was not a file, was a {:?}",
path, o
)
.into(),
),
o => {
Err(format!("Tried to save file {path:?} but it was not a file, was a {o:?}").into())
}
}
}
(_, _) => unimplemented!(),
Expand Down Expand Up @@ -590,7 +575,7 @@ async fn execute(top_match: &clap::ArgMatches) -> Result<(), ExitError> {
let paths = posix_fs
.expand_globs(path_globs, SymlinkBehavior::Oblivious, None)
.await
.map_err(|e| format!("Error expanding globs: {:?}", e))?;
.map_err(|e| format!("Error expanding globs: {e:?}"))?;

let snapshot = Snapshot::from_path_stats(
store::OneOffStoreFileByDigest::new(store_copy, posix_fs, false),
Expand Down Expand Up @@ -622,7 +607,7 @@ async fn execute(top_match: &clap::ArgMatches) -> Result<(), ExitError> {
digest,
SubsetParams {
globs: PreparedPathGlobs::create(
vec![format!("{}/**", prefix_to_strip)],
vec![format!("{prefix_to_strip}/**")],
StrictGlobMatching::Ignore,
GlobExpansionConjunction::AnyMatch,
)?,
Expand Down Expand Up @@ -656,7 +641,7 @@ async fn execute(top_match: &clap::ArgMatches) -> Result<(), ExitError> {
"recursive-file-list" => expand_files(store, digest.as_digest())
.await?
.into_iter()
.map(|(name, _digest)| format!("{}\n", name))
.map(|(name, _digest)| format!("{name}\n"))
.collect::<Vec<String>>()
.join("")
.into_bytes(),
Expand All @@ -668,7 +653,7 @@ async fn execute(top_match: &clap::ArgMatches) -> Result<(), ExitError> {
.join("")
.into_bytes(),
format => {
return Err(format!("Unexpected value of --output-format arg: {}", format).into())
return Err(format!("Unexpected value of --output-format arg: {format}").into())
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/rust/engine/fs/src/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ fn first_path_component_to_name(path: &Path) -> Result<Name, String> {
let name = first_path_component
.as_os_str()
.to_str()
.ok_or_else(|| format!("{:?} is not representable in UTF8", first_path_component))?;
.ok_or_else(|| format!("{first_path_component:?} is not representable in UTF8"))?;
Ok(Name(Intern::from(name)))
}

Expand Down
6 changes: 3 additions & 3 deletions src/rust/engine/fs/src/directory_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn make_tree(path_stats: Vec<TypedPath>) -> DigestTrie {
file_digests.extend(
path_stats
.iter()
.map(|path| (PathBuf::from(path.to_path_buf()), EMPTY_DIGEST)),
.map(|path| (path.to_path_buf(), EMPTY_DIGEST)),
);

DigestTrie::from_unique_paths(path_stats, &file_digests).unwrap()
Expand Down Expand Up @@ -278,14 +278,14 @@ fn assert_walk(tree: &DigestTrie, expected_filenames: Vec<String>, expected_dirn
filenames,
expected_filenames
.iter()
.map(|s| PathBuf::from(s))
.map(PathBuf::from)
.collect::<Vec<_>>()
);
assert_eq!(
dirnames,
expected_dirnames
.iter()
.map(|s| PathBuf::from(s))
.map(PathBuf::from)
.collect::<Vec<_>>()
);
}
Expand Down
Loading

0 comments on commit 8da1ced

Please sign in to comment.