Skip to content

Commit

Permalink
cargo fmt with 2024 rustfmt edition (#22019)
Browse files Browse the repository at this point in the history
As of Rust 2024 Edition, `rustfmt` can be bumped to the new edition's
formatting rules before moving the crates' code to the new edition.

This PR does just that by adding a `rustfmt.toml` with the applicable
configuration.

This should help minimize `fmt`-related churn when porting crates to
2024 Edition.
  • Loading branch information
tdyas authored Feb 28, 2025
1 parent 6eabec7 commit 0be5c80
Show file tree
Hide file tree
Showing 127 changed files with 695 additions and 647 deletions.
2 changes: 1 addition & 1 deletion src/rust/engine/client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use nix::unistd::execv;
use strum::VariantNames;
use strum_macros::{AsRefStr, EnumString, VariantNames};

use options::{option_id, render_choice, Args, BuildRoot, Env, OptionParser};
use options::{Args, BuildRoot, Env, OptionParser, option_id, render_choice};
use pantsd::find_pantsd;

// TODO(John Sirois): Maybe consolidate with PythonLogLevel in src/rust/engine/logging/src/lib.rs.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2023 Pants project contributors (see CONTRIBUTORS.md).
// Licensed under the Apache License, Version 2.0 (see LICENSE).
use std::iter::{once, Once};
use std::iter::{Once, once};
use std::ops::Deref;
use std::option::Option;
use std::path::Path;
Expand Down
6 changes: 3 additions & 3 deletions src/rust/engine/dep_inference/src/javascript/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2023 Pants project contributors (see CONTRIBUTORS.md).
// Licensed under the Apache License, Version 2.0 (see LICENSE).
use std::iter::{once, Once};
use std::iter::{Once, once};
use std::path::{Path, PathBuf};

use fnv::{FnvBuildHasher, FnvHashMap as HashMap, FnvHashSet as HashSet};
Expand All @@ -10,10 +10,10 @@ use tree_sitter::{Node, Parser};

use crate::code;
use protos::gen::pants::cache::{
javascript_inference_metadata::ImportPattern, JavascriptInferenceMetadata,
JavascriptInferenceMetadata, javascript_inference_metadata::ImportPattern,
};

use crate::javascript::import_pattern::{imports_from_patterns, Import};
use crate::javascript::import_pattern::{Import, imports_from_patterns};
use crate::javascript::util::normalize_path;

mod import_pattern;
Expand Down
6 changes: 3 additions & 3 deletions src/rust/engine/dep_inference/src/javascript/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
use std::collections::{HashMap, HashSet};
use std::path::{Path, PathBuf};

use crate::javascript::import_pattern::{imports_from_patterns, Import, Pattern, StarMatch};
use crate::javascript::{get_dependencies, ImportCollector, JavascriptImportInfo};
use crate::javascript::import_pattern::{Import, Pattern, StarMatch, imports_from_patterns};
use crate::javascript::{ImportCollector, JavascriptImportInfo, get_dependencies};
use javascript_inference_metadata::ImportPattern;
use protos::gen::pants::cache::{javascript_inference_metadata, JavascriptInferenceMetadata};
use protos::gen::pants::cache::{JavascriptInferenceMetadata, javascript_inference_metadata};

fn assert_imports(code: &str, imports: &[&str]) {
let mut collector = ImportCollector::new(code);
Expand Down
2 changes: 1 addition & 1 deletion src/rust/engine/dep_inference/src/python/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2023 Pants project contributors (see CONTRIBUTORS.md).
// Licensed under the Apache License, Version 2.0 (see LICENSE).
use crate::python::{get_dependencies, ImportCollector};
use crate::python::{ImportCollector, get_dependencies};
use std::collections::{HashMap, HashSet};
use std::path::PathBuf;

Expand Down
6 changes: 3 additions & 3 deletions src/rust/engine/fs/brfs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::collections::{BTreeMap, HashMap};
use std::ffi::{OsStr, OsString};
use std::path::Path;
use std::sync::mpsc::{channel, Receiver, Sender};
use std::sync::Arc;
use std::sync::mpsc::{Receiver, Sender, channel};
use std::time;

use clap::{Arg, Command};
Expand All @@ -20,10 +20,10 @@ use parking_lot::Mutex;
use protos::gen::build::bazel::remote::execution::v2 as remexec;
use protos::require_digest;
use store::{RemoteProvider, RemoteStoreOptions, Store, StoreError};
use tokio::signal::unix::{signal, SignalKind};
use tokio::signal::unix::{SignalKind, signal};
use tokio::task;
use tokio_stream::wrappers::SignalStream;
use tokio_stream::StreamExt;
use tokio_stream::wrappers::SignalStream;

const TTL: time::Duration = time::Duration::from_secs(0);

Expand Down
12 changes: 7 additions & 5 deletions src/rust/engine/fs/brfs/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ async fn missing_digest() {
Store::local_only(runtime.clone(), store_dir.path()).expect("Error creating local store");

let _fs = mount(mount_dir.path(), store, runtime).expect("Mounting");
assert!(!&mount_dir
.path()
.join("digest")
.join(digest_to_filepath(&TestData::roland().digest()))
.exists());
assert!(
!&mount_dir
.path()
.join("digest")
.join(digest_to_filepath(&TestData::roland().digest()))
.exists()
);
}

#[tokio::test]
Expand Down
4 changes: 2 additions & 2 deletions src/rust/engine/fs/fs_util/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use fs::{
DirectoryDigest, GlobExpansionConjunction, GlobMatching, Permissions, PreparedPathGlobs,
RelativePath, StrictGlobMatching, SymlinkBehavior,
};
use futures::future::{self, BoxFuture};
use futures::FutureExt;
use futures::future::{self, BoxFuture};
use grpc_util::prost::MessageExt;
use grpc_util::tls::CertificateCheck;
use hashing::{Digest, Fingerprint};
Expand Down Expand Up @@ -650,7 +650,7 @@ async fn execute(top_match: &clap::ArgMatches) -> Result<(), ExitError> {
format => {
return Err(
format!("Unexpected value of --output-format arg: {format}").into()
)
);
}
};

Expand Down
16 changes: 11 additions & 5 deletions src/rust/engine/fs/src/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::path::{Component, Path, PathBuf};
use std::sync::Arc;
use std::sync::LazyLock;

use deepsize::{known_deep_size, DeepSizeOf};
use deepsize::{DeepSizeOf, known_deep_size};
use internment::Intern;
use itertools::Itertools;
use log::warn;
Expand All @@ -22,7 +22,7 @@ use hashing::{Digest, EMPTY_DIGEST};
use protos::gen::build::bazel::remote::execution::v2 as remexec;
use protos::require_digest;

use crate::{LinkDepth, PathStat, RelativePath, MAX_LINK_DEPTH};
use crate::{LinkDepth, MAX_LINK_DEPTH, PathStat, RelativePath};

pub static EMPTY_DIGEST_TREE: LazyLock<DigestTrie> = LazyLock::new(|| DigestTrie(vec![].into()));
pub static EMPTY_DIRECTORY_DIGEST: LazyLock<DirectoryDigest> = LazyLock::new(|| DirectoryDigest {
Expand Down Expand Up @@ -656,7 +656,10 @@ impl DigestTrie {
break;
}
}
warn!("Exceeded the maximum link depth while traversing link {:#?} to path {:#?}. Stopping traversal.", logical_path, s.target);
warn!(
"Exceeded the maximum link depth while traversing link {:#?} to path {:#?}. Stopping traversal.",
logical_path, s.target
);
return;
}
self.walk_helper(root, path.clone(), symlink_behavior, link_depth, f);
Expand Down Expand Up @@ -885,7 +888,7 @@ impl DigestTrie {
String::new()
},
format_entries(&extra_directories, &files, &symlinks),
))
));
}
(Some(d), true) => {
already_stripped = already_stripped.join(component_to_strip);
Expand Down Expand Up @@ -964,7 +967,10 @@ impl DigestTrie {

if let Some(Entry::Symlink(s)) = maybe_matching_entry {
if link_depth >= MAX_LINK_DEPTH {
warn!("Exceeded the maximum link depth while traversing link {:#?} to path {:#?}. Stopping traversal.", logical_path, s.target);
warn!(
"Exceeded the maximum link depth while traversing link {:#?} to path {:#?}. Stopping traversal.",
logical_path, s.target
);
return Ok(None);
}

Expand Down
2 changes: 1 addition & 1 deletion src/rust/engine/fs/src/directory_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

use std::collections::HashMap;

use crate::directory::{DigestTrie, Entry, Name, TypedPath};
use crate::MAX_LINK_DEPTH;
use crate::directory::{DigestTrie, Entry, Name, TypedPath};
use hashing::EMPTY_DIGEST;
use std::path::{Path, PathBuf};

Expand Down
10 changes: 3 additions & 7 deletions src/rust/engine/fs/src/glob_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use log::warn;
use parking_lot::Mutex;

use crate::{
Dir, GitignoreStyleExcludes, GlobExpansionConjunction, Link, LinkDepth, PathStat, Stat,
StrictGlobMatching, SymlinkBehavior, Vfs, MAX_LINK_DEPTH,
Dir, GitignoreStyleExcludes, GlobExpansionConjunction, Link, LinkDepth, MAX_LINK_DEPTH,
PathStat, Stat, StrictGlobMatching, SymlinkBehavior, Vfs,
};

static DOUBLE_STAR: &str = "**";
Expand Down Expand Up @@ -532,11 +532,7 @@ trait GlobMatchingImplementation<E: Display + Send + Sync + 'static>: Vfs<E> {
.zip(matched)
.filter_map(
|(source, matched)| {
if matched {
Some(source.clone())
} else {
None
}
if matched { Some(source.clone()) } else { None }
},
)
.collect::<HashSet<_>>();
Expand Down
42 changes: 21 additions & 21 deletions src/rust/engine/fs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ mod posixfs_tests;
mod testutil;

pub use crate::directory::{
DigestTrie, DirectoryDigest, Entry, SymlinkBehavior, TypedPath, EMPTY_DIGEST_TREE,
EMPTY_DIRECTORY_DIGEST,
DigestTrie, DirectoryDigest, EMPTY_DIGEST_TREE, EMPTY_DIRECTORY_DIGEST, Entry, SymlinkBehavior,
TypedPath,
};
pub use crate::gitignore::GitignoreStyleExcludes;
pub use crate::glob_matching::{
FilespecMatcher, GlobMatching, PathGlob, PreparedPathGlobs, DOUBLE_STAR_GLOB, SINGLE_STAR_GLOB,
DOUBLE_STAR_GLOB, FilespecMatcher, GlobMatching, PathGlob, PreparedPathGlobs, SINGLE_STAR_GLOB,
};

use std::cmp::min;
Expand Down Expand Up @@ -81,10 +81,10 @@ impl RelativePath {
for component in candidate.components() {
match component {
Component::Prefix(_) => {
return Err(format!("Windows paths are not allowed: {candidate:?}"))
return Err(format!("Windows paths are not allowed: {candidate:?}"));
}
Component::RootDir => {
return Err(format!("Absolute paths are not allowed: {candidate:?}"))
return Err(format!("Absolute paths are not allowed: {candidate:?}"));
}
Component::CurDir => continue,
Component::ParentDir => {
Expand Down Expand Up @@ -544,11 +544,11 @@ impl PosixFS {
};
if cfg!(debug_assertions) && !path_to_stat.is_absolute() {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
format!(
"Argument path_to_stat to PosixFS::stat_internal must be absolute path, got {path_to_stat:?}"
),
));
io::ErrorKind::InvalidInput,
format!(
"Argument path_to_stat to PosixFS::stat_internal must be absolute path, got {path_to_stat:?}"
),
));
}
let path = file_name.to_owned().into();
if file_type.is_symlink() {
Expand Down Expand Up @@ -579,11 +579,11 @@ impl PosixFS {
pub fn stat_sync(&self, relative_path: &Path) -> Result<Option<Stat>, io::Error> {
if cfg!(debug_assertions) && relative_path.is_absolute() {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
format!(
"Argument relative_path to PosixFS::stat_sync must be relative path, got {relative_path:?}"
),
));
io::ErrorKind::InvalidInput,
format!(
"Argument relative_path to PosixFS::stat_sync must be relative path, got {relative_path:?}"
),
));
}
let abs_path = self.root.0.join(relative_path);
let metadata = match self.symlink_behavior {
Expand Down Expand Up @@ -672,14 +672,14 @@ impl Vfs<String> for DigestTrie {
return Err(format!(
"Path `{}` was a file rather than a symlink.",
link.path.display()
))
));
}
directory::Entry::Symlink(s) => s.target(),
directory::Entry::Directory(_) => {
return Err(format!(
"Path `{}` was a directory rather than a symlink.",
link.path.display()
))
));
}
};
Ok(target.to_path_buf())
Expand All @@ -699,13 +699,13 @@ impl Vfs<String> for DigestTrie {
return Err(format!(
"Path `{}` was a file rather than a directory.",
dir.0.display()
))
));
}
directory::Entry::Symlink(_) => {
return Err(format!(
"Path `{}` was a symlink rather than a directory.",
dir.0.display()
))
));
}
directory::Entry::Directory(d) => d.tree().entries(),
}
Expand Down Expand Up @@ -861,10 +861,10 @@ pub fn increase_limits() -> Result<String, String> {
// If the limit is less than our target.
if cur < TARGET_NOFILE_LIMIT {
let err_suffix = format!(
"To avoid 'too many open file handle' errors, we recommend a limit of at least {TARGET_NOFILE_LIMIT}: \
"To avoid 'too many open file handle' errors, we recommend a limit of at least {TARGET_NOFILE_LIMIT}: \
please see https://www.pantsbuild.org/docs/troubleshooting#too-many-open-files-error \
for more information."
);
);
// If we might be able to increase the soft limit, try to.
if cur < max {
let target_soft_limit = std::cmp::min(max, TARGET_NOFILE_LIMIT);
Expand Down
2 changes: 1 addition & 1 deletion src/rust/engine/fs/store/benches/store.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2020 Pants project contributors (see CONTRIBUTORS.md).
// Licensed under the Apache License, Version 2.0 (see LICENSE).

use criterion::{criterion_group, criterion_main, Criterion};
use criterion::{Criterion, criterion_group, criterion_main};

use std::collections::{BTreeSet, HashSet};
use std::io::{BufRead, BufReader, BufWriter, Write};
Expand Down
4 changes: 2 additions & 2 deletions src/rust/engine/fs/store/src/immutable_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ impl ImmutableInputs {
cell.get_or_try_init(async {
let chroot = TempDir::new_in(self.0.workdir.path()).map_err(|e| {
format!(
"Failed to create a temporary directory for materialization of immutable input \
"Failed to create a temporary directory for materialization of immutable input \
digest {digest:?}: {e}"
)
)
})?;

let dest = chroot.path().join(digest.hash.to_hex());
Expand Down
34 changes: 17 additions & 17 deletions src/rust/engine/fs/store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ use async_oncecell::OnceCell;
use async_trait::async_trait;
use bytes::Bytes;
use fs::{
default_cache_path, directory, DigestEntry, DigestTrie, Dir, DirectoryDigest, File,
FileContent, FileEntry, Link, PathStat, Permissions, RelativePath, SymlinkBehavior,
SymlinkEntry, EMPTY_DIRECTORY_DIGEST,
DigestEntry, DigestTrie, Dir, DirectoryDigest, EMPTY_DIRECTORY_DIGEST, File, FileContent,
FileEntry, Link, PathStat, Permissions, RelativePath, SymlinkBehavior, SymlinkEntry,
default_cache_path, directory,
};
use futures::future::{self, BoxFuture, Either, FutureExt, TryFutureExt};
use grpc_util::prost::MessageExt;
Expand All @@ -50,7 +50,7 @@ use tokio::fs::copy;
use tokio::fs::hard_link;
use tokio::fs::symlink;
use tryfuture::try_future;
use workunit_store::{in_workunit, Level, Metric};
use workunit_store::{Level, Metric, in_workunit};

const KILOBYTES: usize = 1024;
const MEGABYTES: usize = 1024 * KILOBYTES;
Expand Down Expand Up @@ -717,15 +717,15 @@ impl Store {
.download_digest_to_local(self.local.clone(), digest, entry_type, f_remote)
.await?;

Ok(
self
.local
.load_bytes_with(entry_type, digest, f_local)
.await?
.ok_or_else(|| {
format!("After downloading {digest:?}, the local store claimed that it was not present.")
})??,
)
Ok(self
.local
.load_bytes_with(entry_type, digest, f_local)
.await?
.ok_or_else(|| {
format!(
"After downloading {digest:?}, the local store claimed that it was not present."
)
})??)
}

///
Expand Down Expand Up @@ -1043,11 +1043,11 @@ impl Store {
Ok(size) => {
if size > target_size_bytes {
log::warn!(
"Garbage collection attempted to shrink the store to {} bytes but {} bytes \
"Garbage collection attempted to shrink the store to {} bytes but {} bytes \
are currently in use.",
target_size_bytes,
size
)
target_size_bytes,
size
)
}
Ok(())
}
Expand Down
Loading

0 comments on commit 0be5c80

Please sign in to comment.