Skip to content

Commit 0be5c80

Browse files
authored
cargo fmt with 2024 rustfmt edition (#22019)
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.
1 parent 6eabec7 commit 0be5c80

File tree

127 files changed

+695
-647
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+695
-647
lines changed

src/rust/engine/client/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use nix::unistd::execv;
1313
use strum::VariantNames;
1414
use strum_macros::{AsRefStr, EnumString, VariantNames};
1515

16-
use options::{option_id, render_choice, Args, BuildRoot, Env, OptionParser};
16+
use options::{Args, BuildRoot, Env, OptionParser, option_id, render_choice};
1717
use pantsd::find_pantsd;
1818

1919
// TODO(John Sirois): Maybe consolidate with PythonLogLevel in src/rust/engine/logging/src/lib.rs.

src/rust/engine/dep_inference/src/javascript/import_pattern.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright 2023 Pants project contributors (see CONTRIBUTORS.md).
22
// Licensed under the Apache License, Version 2.0 (see LICENSE).
3-
use std::iter::{once, Once};
3+
use std::iter::{Once, once};
44
use std::ops::Deref;
55
use std::option::Option;
66
use std::path::Path;

src/rust/engine/dep_inference/src/javascript/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright 2023 Pants project contributors (see CONTRIBUTORS.md).
22
// Licensed under the Apache License, Version 2.0 (see LICENSE).
3-
use std::iter::{once, Once};
3+
use std::iter::{Once, once};
44
use std::path::{Path, PathBuf};
55

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

1111
use crate::code;
1212
use protos::gen::pants::cache::{
13-
javascript_inference_metadata::ImportPattern, JavascriptInferenceMetadata,
13+
JavascriptInferenceMetadata, javascript_inference_metadata::ImportPattern,
1414
};
1515

16-
use crate::javascript::import_pattern::{imports_from_patterns, Import};
16+
use crate::javascript::import_pattern::{Import, imports_from_patterns};
1717
use crate::javascript::util::normalize_path;
1818

1919
mod import_pattern;

src/rust/engine/dep_inference/src/javascript/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
use std::collections::{HashMap, HashSet};
55
use std::path::{Path, PathBuf};
66

7-
use crate::javascript::import_pattern::{imports_from_patterns, Import, Pattern, StarMatch};
8-
use crate::javascript::{get_dependencies, ImportCollector, JavascriptImportInfo};
7+
use crate::javascript::import_pattern::{Import, Pattern, StarMatch, imports_from_patterns};
8+
use crate::javascript::{ImportCollector, JavascriptImportInfo, get_dependencies};
99
use javascript_inference_metadata::ImportPattern;
10-
use protos::gen::pants::cache::{javascript_inference_metadata, JavascriptInferenceMetadata};
10+
use protos::gen::pants::cache::{JavascriptInferenceMetadata, javascript_inference_metadata};
1111

1212
fn assert_imports(code: &str, imports: &[&str]) {
1313
let mut collector = ImportCollector::new(code);

src/rust/engine/dep_inference/src/python/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright 2023 Pants project contributors (see CONTRIBUTORS.md).
22
// Licensed under the Apache License, Version 2.0 (see LICENSE).
3-
use crate::python::{get_dependencies, ImportCollector};
3+
use crate::python::{ImportCollector, get_dependencies};
44
use std::collections::{HashMap, HashSet};
55
use std::path::PathBuf;
66

src/rust/engine/fs/brfs/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use std::collections::hash_map::Entry::{Occupied, Vacant};
77
use std::collections::{BTreeMap, HashMap};
88
use std::ffi::{OsStr, OsString};
99
use std::path::Path;
10-
use std::sync::mpsc::{channel, Receiver, Sender};
1110
use std::sync::Arc;
11+
use std::sync::mpsc::{Receiver, Sender, channel};
1212
use std::time;
1313

1414
use clap::{Arg, Command};
@@ -20,10 +20,10 @@ use parking_lot::Mutex;
2020
use protos::gen::build::bazel::remote::execution::v2 as remexec;
2121
use protos::require_digest;
2222
use store::{RemoteProvider, RemoteStoreOptions, Store, StoreError};
23-
use tokio::signal::unix::{signal, SignalKind};
23+
use tokio::signal::unix::{SignalKind, signal};
2424
use tokio::task;
25-
use tokio_stream::wrappers::SignalStream;
2625
use tokio_stream::StreamExt;
26+
use tokio_stream::wrappers::SignalStream;
2727

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

src/rust/engine/fs/brfs/src/tests.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ async fn missing_digest() {
2121
Store::local_only(runtime.clone(), store_dir.path()).expect("Error creating local store");
2222

2323
let _fs = mount(mount_dir.path(), store, runtime).expect("Mounting");
24-
assert!(!&mount_dir
25-
.path()
26-
.join("digest")
27-
.join(digest_to_filepath(&TestData::roland().digest()))
28-
.exists());
24+
assert!(
25+
!&mount_dir
26+
.path()
27+
.join("digest")
28+
.join(digest_to_filepath(&TestData::roland().digest()))
29+
.exists()
30+
);
2931
}
3032

3133
#[tokio::test]

src/rust/engine/fs/fs_util/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use fs::{
1515
DirectoryDigest, GlobExpansionConjunction, GlobMatching, Permissions, PreparedPathGlobs,
1616
RelativePath, StrictGlobMatching, SymlinkBehavior,
1717
};
18-
use futures::future::{self, BoxFuture};
1918
use futures::FutureExt;
19+
use futures::future::{self, BoxFuture};
2020
use grpc_util::prost::MessageExt;
2121
use grpc_util::tls::CertificateCheck;
2222
use hashing::{Digest, Fingerprint};
@@ -650,7 +650,7 @@ async fn execute(top_match: &clap::ArgMatches) -> Result<(), ExitError> {
650650
format => {
651651
return Err(
652652
format!("Unexpected value of --output-format arg: {format}").into()
653-
)
653+
);
654654
}
655655
};
656656

src/rust/engine/fs/src/directory.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::path::{Component, Path, PathBuf};
1010
use std::sync::Arc;
1111
use std::sync::LazyLock;
1212

13-
use deepsize::{known_deep_size, DeepSizeOf};
13+
use deepsize::{DeepSizeOf, known_deep_size};
1414
use internment::Intern;
1515
use itertools::Itertools;
1616
use log::warn;
@@ -22,7 +22,7 @@ use hashing::{Digest, EMPTY_DIGEST};
2222
use protos::gen::build::bazel::remote::execution::v2 as remexec;
2323
use protos::require_digest;
2424

25-
use crate::{LinkDepth, PathStat, RelativePath, MAX_LINK_DEPTH};
25+
use crate::{LinkDepth, MAX_LINK_DEPTH, PathStat, RelativePath};
2626

2727
pub static EMPTY_DIGEST_TREE: LazyLock<DigestTrie> = LazyLock::new(|| DigestTrie(vec![].into()));
2828
pub static EMPTY_DIRECTORY_DIGEST: LazyLock<DirectoryDigest> = LazyLock::new(|| DirectoryDigest {
@@ -656,7 +656,10 @@ impl DigestTrie {
656656
break;
657657
}
658658
}
659-
warn!("Exceeded the maximum link depth while traversing link {:#?} to path {:#?}. Stopping traversal.", logical_path, s.target);
659+
warn!(
660+
"Exceeded the maximum link depth while traversing link {:#?} to path {:#?}. Stopping traversal.",
661+
logical_path, s.target
662+
);
660663
return;
661664
}
662665
self.walk_helper(root, path.clone(), symlink_behavior, link_depth, f);
@@ -885,7 +888,7 @@ impl DigestTrie {
885888
String::new()
886889
},
887890
format_entries(&extra_directories, &files, &symlinks),
888-
))
891+
));
889892
}
890893
(Some(d), true) => {
891894
already_stripped = already_stripped.join(component_to_strip);
@@ -964,7 +967,10 @@ impl DigestTrie {
964967

965968
if let Some(Entry::Symlink(s)) = maybe_matching_entry {
966969
if link_depth >= MAX_LINK_DEPTH {
967-
warn!("Exceeded the maximum link depth while traversing link {:#?} to path {:#?}. Stopping traversal.", logical_path, s.target);
970+
warn!(
971+
"Exceeded the maximum link depth while traversing link {:#?} to path {:#?}. Stopping traversal.",
972+
logical_path, s.target
973+
);
968974
return Ok(None);
969975
}
970976

src/rust/engine/fs/src/directory_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
use std::collections::HashMap;
55

6-
use crate::directory::{DigestTrie, Entry, Name, TypedPath};
76
use crate::MAX_LINK_DEPTH;
7+
use crate::directory::{DigestTrie, Entry, Name, TypedPath};
88
use hashing::EMPTY_DIGEST;
99
use std::path::{Path, PathBuf};
1010

src/rust/engine/fs/src/glob_matching.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use log::warn;
1717
use parking_lot::Mutex;
1818

1919
use crate::{
20-
Dir, GitignoreStyleExcludes, GlobExpansionConjunction, Link, LinkDepth, PathStat, Stat,
21-
StrictGlobMatching, SymlinkBehavior, Vfs, MAX_LINK_DEPTH,
20+
Dir, GitignoreStyleExcludes, GlobExpansionConjunction, Link, LinkDepth, MAX_LINK_DEPTH,
21+
PathStat, Stat, StrictGlobMatching, SymlinkBehavior, Vfs,
2222
};
2323

2424
static DOUBLE_STAR: &str = "**";
@@ -532,11 +532,7 @@ trait GlobMatchingImplementation<E: Display + Send + Sync + 'static>: Vfs<E> {
532532
.zip(matched)
533533
.filter_map(
534534
|(source, matched)| {
535-
if matched {
536-
Some(source.clone())
537-
} else {
538-
None
539-
}
535+
if matched { Some(source.clone()) } else { None }
540536
},
541537
)
542538
.collect::<HashSet<_>>();

src/rust/engine/fs/src/lib.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ mod posixfs_tests;
1414
mod testutil;
1515

1616
pub use crate::directory::{
17-
DigestTrie, DirectoryDigest, Entry, SymlinkBehavior, TypedPath, EMPTY_DIGEST_TREE,
18-
EMPTY_DIRECTORY_DIGEST,
17+
DigestTrie, DirectoryDigest, EMPTY_DIGEST_TREE, EMPTY_DIRECTORY_DIGEST, Entry, SymlinkBehavior,
18+
TypedPath,
1919
};
2020
pub use crate::gitignore::GitignoreStyleExcludes;
2121
pub use crate::glob_matching::{
22-
FilespecMatcher, GlobMatching, PathGlob, PreparedPathGlobs, DOUBLE_STAR_GLOB, SINGLE_STAR_GLOB,
22+
DOUBLE_STAR_GLOB, FilespecMatcher, GlobMatching, PathGlob, PreparedPathGlobs, SINGLE_STAR_GLOB,
2323
};
2424

2525
use std::cmp::min;
@@ -81,10 +81,10 @@ impl RelativePath {
8181
for component in candidate.components() {
8282
match component {
8383
Component::Prefix(_) => {
84-
return Err(format!("Windows paths are not allowed: {candidate:?}"))
84+
return Err(format!("Windows paths are not allowed: {candidate:?}"));
8585
}
8686
Component::RootDir => {
87-
return Err(format!("Absolute paths are not allowed: {candidate:?}"))
87+
return Err(format!("Absolute paths are not allowed: {candidate:?}"));
8888
}
8989
Component::CurDir => continue,
9090
Component::ParentDir => {
@@ -544,11 +544,11 @@ impl PosixFS {
544544
};
545545
if cfg!(debug_assertions) && !path_to_stat.is_absolute() {
546546
return Err(io::Error::new(
547-
io::ErrorKind::InvalidInput,
548-
format!(
549-
"Argument path_to_stat to PosixFS::stat_internal must be absolute path, got {path_to_stat:?}"
550-
),
551-
));
547+
io::ErrorKind::InvalidInput,
548+
format!(
549+
"Argument path_to_stat to PosixFS::stat_internal must be absolute path, got {path_to_stat:?}"
550+
),
551+
));
552552
}
553553
let path = file_name.to_owned().into();
554554
if file_type.is_symlink() {
@@ -579,11 +579,11 @@ impl PosixFS {
579579
pub fn stat_sync(&self, relative_path: &Path) -> Result<Option<Stat>, io::Error> {
580580
if cfg!(debug_assertions) && relative_path.is_absolute() {
581581
return Err(io::Error::new(
582-
io::ErrorKind::InvalidInput,
583-
format!(
584-
"Argument relative_path to PosixFS::stat_sync must be relative path, got {relative_path:?}"
585-
),
586-
));
582+
io::ErrorKind::InvalidInput,
583+
format!(
584+
"Argument relative_path to PosixFS::stat_sync must be relative path, got {relative_path:?}"
585+
),
586+
));
587587
}
588588
let abs_path = self.root.0.join(relative_path);
589589
let metadata = match self.symlink_behavior {
@@ -672,14 +672,14 @@ impl Vfs<String> for DigestTrie {
672672
return Err(format!(
673673
"Path `{}` was a file rather than a symlink.",
674674
link.path.display()
675-
))
675+
));
676676
}
677677
directory::Entry::Symlink(s) => s.target(),
678678
directory::Entry::Directory(_) => {
679679
return Err(format!(
680680
"Path `{}` was a directory rather than a symlink.",
681681
link.path.display()
682-
))
682+
));
683683
}
684684
};
685685
Ok(target.to_path_buf())
@@ -699,13 +699,13 @@ impl Vfs<String> for DigestTrie {
699699
return Err(format!(
700700
"Path `{}` was a file rather than a directory.",
701701
dir.0.display()
702-
))
702+
));
703703
}
704704
directory::Entry::Symlink(_) => {
705705
return Err(format!(
706706
"Path `{}` was a symlink rather than a directory.",
707707
dir.0.display()
708-
))
708+
));
709709
}
710710
directory::Entry::Directory(d) => d.tree().entries(),
711711
}
@@ -861,10 +861,10 @@ pub fn increase_limits() -> Result<String, String> {
861861
// If the limit is less than our target.
862862
if cur < TARGET_NOFILE_LIMIT {
863863
let err_suffix = format!(
864-
"To avoid 'too many open file handle' errors, we recommend a limit of at least {TARGET_NOFILE_LIMIT}: \
864+
"To avoid 'too many open file handle' errors, we recommend a limit of at least {TARGET_NOFILE_LIMIT}: \
865865
please see https://www.pantsbuild.org/docs/troubleshooting#too-many-open-files-error \
866866
for more information."
867-
);
867+
);
868868
// If we might be able to increase the soft limit, try to.
869869
if cur < max {
870870
let target_soft_limit = std::cmp::min(max, TARGET_NOFILE_LIMIT);

src/rust/engine/fs/store/benches/store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2020 Pants project contributors (see CONTRIBUTORS.md).
22
// Licensed under the Apache License, Version 2.0 (see LICENSE).
33

4-
use criterion::{criterion_group, criterion_main, Criterion};
4+
use criterion::{Criterion, criterion_group, criterion_main};
55

66
use std::collections::{BTreeSet, HashSet};
77
use std::io::{BufRead, BufReader, BufWriter, Write};

src/rust/engine/fs/store/src/immutable_inputs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ impl ImmutableInputs {
9696
cell.get_or_try_init(async {
9797
let chroot = TempDir::new_in(self.0.workdir.path()).map_err(|e| {
9898
format!(
99-
"Failed to create a temporary directory for materialization of immutable input \
99+
"Failed to create a temporary directory for materialization of immutable input \
100100
digest {digest:?}: {e}"
101-
)
101+
)
102102
})?;
103103

104104
let dest = chroot.path().join(digest.hash.to_hex());

src/rust/engine/fs/store/src/lib.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ use async_oncecell::OnceCell;
2929
use async_trait::async_trait;
3030
use bytes::Bytes;
3131
use fs::{
32-
default_cache_path, directory, DigestEntry, DigestTrie, Dir, DirectoryDigest, File,
33-
FileContent, FileEntry, Link, PathStat, Permissions, RelativePath, SymlinkBehavior,
34-
SymlinkEntry, EMPTY_DIRECTORY_DIGEST,
32+
DigestEntry, DigestTrie, Dir, DirectoryDigest, EMPTY_DIRECTORY_DIGEST, File, FileContent,
33+
FileEntry, Link, PathStat, Permissions, RelativePath, SymlinkBehavior, SymlinkEntry,
34+
default_cache_path, directory,
3535
};
3636
use futures::future::{self, BoxFuture, Either, FutureExt, TryFutureExt};
3737
use grpc_util::prost::MessageExt;
@@ -50,7 +50,7 @@ use tokio::fs::copy;
5050
use tokio::fs::hard_link;
5151
use tokio::fs::symlink;
5252
use tryfuture::try_future;
53-
use workunit_store::{in_workunit, Level, Metric};
53+
use workunit_store::{Level, Metric, in_workunit};
5454

5555
const KILOBYTES: usize = 1024;
5656
const MEGABYTES: usize = 1024 * KILOBYTES;
@@ -717,15 +717,15 @@ impl Store {
717717
.download_digest_to_local(self.local.clone(), digest, entry_type, f_remote)
718718
.await?;
719719

720-
Ok(
721-
self
722-
.local
723-
.load_bytes_with(entry_type, digest, f_local)
724-
.await?
725-
.ok_or_else(|| {
726-
format!("After downloading {digest:?}, the local store claimed that it was not present.")
727-
})??,
728-
)
720+
Ok(self
721+
.local
722+
.load_bytes_with(entry_type, digest, f_local)
723+
.await?
724+
.ok_or_else(|| {
725+
format!(
726+
"After downloading {digest:?}, the local store claimed that it was not present."
727+
)
728+
})??)
729729
}
730730

731731
///
@@ -1043,11 +1043,11 @@ impl Store {
10431043
Ok(size) => {
10441044
if size > target_size_bytes {
10451045
log::warn!(
1046-
"Garbage collection attempted to shrink the store to {} bytes but {} bytes \
1046+
"Garbage collection attempted to shrink the store to {} bytes but {} bytes \
10471047
are currently in use.",
1048-
target_size_bytes,
1049-
size
1050-
)
1048+
target_size_bytes,
1049+
size
1050+
)
10511051
}
10521052
Ok(())
10531053
}

0 commit comments

Comments
 (0)