Skip to content

Commit 70af16f

Browse files
committed
rustfmt: set style_edition = "2024"
1 parent 13b27c9 commit 70af16f

37 files changed

+216
-240
lines changed

.rustfmt.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ error_on_line_overflow = true
88
# Override the default formatting style.
99
# See https://internals.rust-lang.org/t/running-rustfmt-on-rust-lang-rust-and-other-rust-lang-repositories/8732/81.
1010
use_small_heuristics = "Max"
11-
# This is the default of 2024 edition https://github.com/rust-lang/rust/pull/114764.
1211
# This is unstable (tracking issue: https://github.com/rust-lang/rustfmt/issues/3370)
1312
overflow_delimited_expr = true
1413
# This is unstable (tracking issue: https://github.com/rust-lang/rustfmt/issues/4991).
@@ -27,6 +26,7 @@ use_try_shorthand = true
2726
# Set the default settings again to always apply the proper formatting without
2827
# being affected by the editor settings.
2928
edition = "2021"
29+
style_edition = "2024"
3030
hard_tabs = false
3131
newline_style = "Unix"
3232
tab_spaces = 4

src/cargo.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use std::ffi::OsStr;
44

5-
use anyhow::{bail, Context as _, Result};
5+
use anyhow::{Context as _, Result, bail};
66
use camino::{Utf8Path, Utf8PathBuf};
77
use cargo_config2::Config;
88

@@ -51,7 +51,9 @@ impl Workspace {
5151
let metadata = Metadata::new(current_manifest.as_std_path(), config.cargo())?;
5252
let mut target_for_config = config.build_target_for_config(target)?;
5353
if target_for_config.len() != 1 {
54-
bail!("cargo-llvm-cov doesn't currently supports multi-target builds: {target_for_config:?}");
54+
bail!(
55+
"cargo-llvm-cov doesn't currently supports multi-target builds: {target_for_config:?}"
56+
);
5557
}
5658
let target_for_config = target_for_config.pop().unwrap();
5759
let target_for_cli = config.build_target_for_cli(target)?.pop();
@@ -61,10 +63,14 @@ impl Workspace {
6163
rustc_version.nightly || env::var_os("RUSTC_BOOTSTRAP").unwrap_or_default() == "1";
6264

6365
if doctests && !rustc_version.nightly {
64-
warn!("--doctests flag requires nightly toolchain; consider using `cargo +nightly llvm-cov`");
66+
warn!(
67+
"--doctests flag requires nightly toolchain; consider using `cargo +nightly llvm-cov`"
68+
);
6569
}
6670
if branch && !rustc_version.nightly {
67-
warn!("--branch flag requires nightly toolchain; consider using `cargo +nightly llvm-cov`");
71+
warn!(
72+
"--branch flag requires nightly toolchain; consider using `cargo +nightly llvm-cov`"
73+
);
6874
}
6975
if mcdc && !rustc_version.nightly {
7076
warn!(

src/cli.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use std::{ffi::OsString, mem, str::FromStr};
44

5-
use anyhow::{bail, format_err, Error, Result};
5+
use anyhow::{Error, Result, bail, format_err};
66
use camino::{Utf8Path, Utf8PathBuf};
77
use lexopt::{
88
Arg::{Long, Short, Value},
@@ -1208,7 +1208,9 @@ impl Args {
12081208
cargo_args.push(profile);
12091209
}
12101210
if nextest_archive_file.is_some() {
1211-
bail!("'--nextest-archive-file' is report-specific option; did you mean '--archive-file'?");
1211+
bail!(
1212+
"'--nextest-archive-file' is report-specific option; did you mean '--archive-file'?"
1213+
);
12121214
}
12131215
nextest_archive_file = archive_file;
12141216
if let Subcommand::Nextest { archive_file: f } = &mut subcommand {
@@ -1221,15 +1223,21 @@ impl Args {
12211223
cargo_profile = profile;
12221224
if let Subcommand::Report { nextest_archive_file: f } = &mut subcommand {
12231225
if archive_file.is_some() {
1224-
bail!("'--archive-file' is nextest-specific option; did you mean '--nextest-archive-file'?");
1226+
bail!(
1227+
"'--archive-file' is nextest-specific option; did you mean '--nextest-archive-file'?"
1228+
);
12251229
}
12261230
*f = nextest_archive_file.is_some();
12271231
} else {
12281232
if archive_file.is_some() {
1229-
bail!("'--archive-file' is nextest-specific option and not supported for this subcommand");
1233+
bail!(
1234+
"'--archive-file' is nextest-specific option and not supported for this subcommand"
1235+
);
12301236
}
12311237
if nextest_archive_file.is_some() {
1232-
bail!("'--nextest-archive-file' is report-specific option and not supported for this subcommand");
1238+
bail!(
1239+
"'--nextest-archive-file' is report-specific option and not supported for this subcommand"
1240+
);
12331241
}
12341242
}
12351243
}

src/context.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
path::PathBuf,
77
};
88

9-
use anyhow::{bail, Result};
9+
use anyhow::{Result, bail};
1010
use camino::Utf8PathBuf;
1111

1212
use crate::{
@@ -135,9 +135,13 @@ impl Context {
135135
(Some(llvm_cov), Some(llvm_profdata)) => (llvm_cov, llvm_profdata),
136136
(llvm_cov_env, llvm_profdata_env) => {
137137
if llvm_cov_env.is_some() {
138-
warn!("setting only LLVM_COV environment variable may not work properly; consider setting both LLVM_COV and LLVM_PROFDATA environment variables");
138+
warn!(
139+
"setting only LLVM_COV environment variable may not work properly; consider setting both LLVM_COV and LLVM_PROFDATA environment variables"
140+
);
139141
} else if llvm_profdata_env.is_some() {
140-
warn!("setting only LLVM_PROFDATA environment variable may not work properly; consider setting both LLVM_COV and LLVM_PROFDATA environment variables");
142+
warn!(
143+
"setting only LLVM_PROFDATA environment variable may not work properly; consider setting both LLVM_COV and LLVM_PROFDATA environment variables"
144+
);
141145
}
142146
// --print target-libdir (without --target flag) returns $sysroot/lib/rustlib/$host_triple/lib
143147
// llvm-tools exists in $sysroot/lib/rustlib/$host_triple/bin
@@ -220,7 +224,9 @@ impl Context {
220224
if llvm_profdata_flags.is_none() {
221225
llvm_profdata_flags = env::var("CARGO_LLVM_PROFDATA_FLAGS")?;
222226
if llvm_profdata_flags.is_some() {
223-
warn!("CARGO_LLVM_PROFDATA_FLAGS is deprecated; consider using LLVM_PROFDATA_FLAGS instead");
227+
warn!(
228+
"CARGO_LLVM_PROFDATA_FLAGS is deprecated; consider using LLVM_PROFDATA_FLAGS instead"
229+
);
224230
}
225231
}
226232

@@ -234,7 +240,9 @@ impl Context {
234240
Ok(exe) => exe,
235241
Err(e) => {
236242
let exe = format!("cargo-llvm-cov{}", env::consts::EXE_SUFFIX);
237-
warn!("failed to get current executable, assuming {exe} in PATH as current executable: {e}");
243+
warn!(
244+
"failed to get current executable, assuming {exe} in PATH as current executable: {e}"
245+
);
238246
exe.into()
239247
}
240248
},

src/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
pub(crate) use std::fs::Metadata;
44
use std::{ffi::OsStr, io, path::Path};
55

6-
pub(crate) use fs_err::{create_dir_all, read_dir, symlink_metadata, write, File};
6+
pub(crate) use fs_err::{File, create_dir_all, read_dir, symlink_metadata, write};
77

88
/// Removes a file from the filesystem **if exists**. (Similar to `rm -f`)
99
pub(crate) fn remove_file(path: impl AsRef<Path>) -> io::Result<()> {

src/main.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::{
1717
time::SystemTime,
1818
};
1919

20-
use anyhow::{bail, Context as _, Result};
20+
use anyhow::{Context as _, Result, bail};
2121
use camino::{Utf8Path, Utf8PathBuf};
2222
use cargo_config2::Flags;
2323
use cargo_llvm_cov::json::{CodeCovJsonExport, CoverageKind, LlvmCovJsonExport};
@@ -786,19 +786,27 @@ fn object_files(cx: &Context) -> Result<Vec<OsString>> {
786786
if binaries_metadata.rust_build_meta.base_output_directories.len() == 1 =>
787787
{
788788
if cx.args.target.is_some() {
789-
info!("--target flag is no longer needed because detection from nextest archive is now supported");
789+
info!(
790+
"--target flag is no longer needed because detection from nextest archive is now supported"
791+
);
790792
}
791793
if cx.args.release {
792-
info!("--release flag is no longer needed because detection from nextest archive is now supported");
794+
info!(
795+
"--release flag is no longer needed because detection from nextest archive is now supported"
796+
);
793797
}
794798
if cx.args.cargo_profile.is_some() {
795-
info!("--cargo-profile flag is no longer needed because detection from nextest archive is now supported");
799+
info!(
800+
"--cargo-profile flag is no longer needed because detection from nextest archive is now supported"
801+
);
796802
}
797803
target_dir.push(&binaries_metadata.rust_build_meta.base_output_directories[0]);
798804
auto_detect_profile = true;
799805
}
800806
res => {
801-
warn!("found binaries-metadata.json in nextest archive {archive_file:?}, but has unsupported or incompatible format: {res:?}");
807+
warn!(
808+
"found binaries-metadata.json in nextest archive {archive_file:?}, but has unsupported or incompatible format: {res:?}"
809+
);
802810
}
803811
}
804812
}
@@ -1212,8 +1220,12 @@ fn ignore_filename_regex(cx: &Context, object_files: &[OsString]) -> Result<Opti
12121220
if let Some(dep) = &cx.args.cov.dep_coverage {
12131221
let format = Format::Json;
12141222
let json = format.get_json(cx, object_files, None).context("failed to get json")?;
1215-
let crates_io_re = Regex::new(&format!("{SEPARATOR}registry{SEPARATOR}src{SEPARATOR}index\\.crates\\.io-[0-9a-f]+{SEPARATOR}[0-9A-Za-z-_]+-[0-9]+\\.[0-9]+\\.[0-9]+(-[0-9A-Za-z\\.-]+)?(\\+[0-9A-Za-z\\.-]+)?{SEPARATOR}"))?;
1216-
let dep_re = Regex::new(&format!("{SEPARATOR}registry{SEPARATOR}src{SEPARATOR}index\\.crates\\.io-[0-9a-f]+{SEPARATOR}{dep}-[0-9]+\\.[0-9]+\\.[0-9]+(-[0-9A-Za-z\\.-]+)?(\\+[0-9A-Za-z\\.-]+)?{SEPARATOR}"))?;
1223+
let crates_io_re = Regex::new(&format!(
1224+
"{SEPARATOR}registry{SEPARATOR}src{SEPARATOR}index\\.crates\\.io-[0-9a-f]+{SEPARATOR}[0-9A-Za-z-_]+-[0-9]+\\.[0-9]+\\.[0-9]+(-[0-9A-Za-z\\.-]+)?(\\+[0-9A-Za-z\\.-]+)?{SEPARATOR}"
1225+
))?;
1226+
let dep_re = Regex::new(&format!(
1227+
"{SEPARATOR}registry{SEPARATOR}src{SEPARATOR}index\\.crates\\.io-[0-9a-f]+{SEPARATOR}{dep}-[0-9]+\\.[0-9]+\\.[0-9]+(-[0-9A-Za-z\\.-]+)?(\\+[0-9A-Za-z\\.-]+)?{SEPARATOR}"
1228+
))?;
12171229
let mut set = BTreeSet::new();
12181230
for data in &json.data {
12191231
for file in &data.files {
@@ -1264,11 +1276,7 @@ fn ignore_filename_regex(cx: &Context, object_files: &[OsString]) -> Result<Opti
12641276
}
12651277
}
12661278

1267-
if out.0.is_empty() {
1268-
Ok(None)
1269-
} else {
1270-
Ok(Some(out.0))
1271-
}
1279+
if out.0.is_empty() { Ok(None) } else { Ok(Some(out.0)) }
12721280
}
12731281

12741282
fn resolve_excluded_paths(cx: &Context) -> Vec<Utf8PathBuf> {

src/metadata.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use std::{collections::HashMap, ffi::OsStr, path::Path};
66

7-
use anyhow::{format_err, Context as _, Result};
7+
use anyhow::{Context as _, Result, format_err};
88
use camino::Utf8PathBuf;
99
use serde_json::{Map, Value};
1010

@@ -118,18 +118,10 @@ impl Target {
118118
// }
119119

120120
fn into_string<S: From<String>>(value: Value) -> Option<S> {
121-
if let Value::String(string) = value {
122-
Some(string.into())
123-
} else {
124-
None
125-
}
121+
if let Value::String(string) = value { Some(string.into()) } else { None }
126122
}
127123
fn into_array(value: Value) -> Option<Vec<Value>> {
128-
if let Value::Array(array) = value {
129-
Some(array)
130-
} else {
131-
None
132-
}
124+
if let Value::Array(array) = value { Some(array) } else { None }
133125
}
134126
// fn into_object(value: Value) -> Option<Object> {
135127
// if let Value::Object(object) = value {

tests/auxiliary/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,7 @@ pub(crate) fn perturb_one_header(workspace_root: &Path) -> Option<PathBuf> {
139139
let target_dir = workspace_root.join("target").join("llvm-cov-target");
140140
let path = fs::read_dir(target_dir).unwrap().find_map(|entry| {
141141
let path = entry.ok().unwrap().path();
142-
if path.extension() == Some(OsStr::new("profraw")) {
143-
Some(path)
144-
} else {
145-
None
146-
}
142+
if path.extension() == Some(OsStr::new("profraw")) { Some(path) } else { None }
147143
});
148144
if let Some(path) = &path {
149145
perturb_header(path);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"coverage":{"src/lib.rs":{"1":"1/1","2":"1/1","3":"0/1","5":"1/1","7":"1/1","10":"1/1","11":"1/1","12":"1/1","15":"1/1"}}}
1+
{"coverage":{"src/lib.rs":{"1":"1/1","2":"2/3","3":"1/1","6":"1/1","7":"1/1","8":"1/1","11":"1/1"}}}
Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
1| 1|fn func(x: i32) -> bool {
2-
2| 1| if x < 0 {
3-
3| 0| true
4-
4| | } else {
5-
5| 1| false
6-
6| | }
7-
7| 1|}
8-
8| |
9-
9| |#[test]
10-
10| 1|fn test() {
11-
11| 1| #[cfg(a)]
12-
12| 1| assert!(!func(1));
13-
13| | #[cfg(not(a))]
14-
14| | assert!(func(-1));
15-
15| 1|}
2+
2| 1| if x < 0 { true } else { false }
3+
^0
4+
3| 1|}
5+
4| |
6+
5| |#[test]
7+
6| 1|fn test() {
8+
7| 1| #[cfg(a)]
9+
8| 1| assert!(!func(1));
10+
9| | #[cfg(not(a))]
11+
10| | assert!(func(-1));
12+
11| 1|}

0 commit comments

Comments
 (0)