Skip to content

Commit c6fefa5

Browse files
committed
Auto merge of #1801 - RalfJung:rustfmt, r=oli-obk
rustfmt I liberally applied `rustfmt::skip` where I really did not like the rustfmt formatting.
2 parents 6608d22 + d6fdfaa commit c6fefa5

39 files changed

+1006
-866
lines changed

benches/helpers/miri_helper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ extern crate rustc_driver;
22
extern crate rustc_hir;
33
extern crate rustc_interface;
44

5-
use rustc_hir::def_id::LOCAL_CRATE;
65
use rustc_driver::Compilation;
6+
use rustc_hir::def_id::LOCAL_CRATE;
77
use rustc_interface::{interface, Queries};
88

99
use crate::test::Bencher;

cargo-miri/bin.rs

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use std::env;
22
use std::ffi::OsString;
3+
use std::fmt::Write as _;
34
use std::fs::{self, File};
4-
use std::iter::TakeWhile;
55
use std::io::{self, BufRead, BufReader, BufWriter, Read, Write};
6+
use std::iter::TakeWhile;
67
use std::ops::Not;
78
use std::path::{Path, PathBuf};
89
use std::process::Command;
9-
use std::fmt::{Write as _};
1010

1111
use serde::{Deserialize, Serialize};
1212

@@ -95,7 +95,8 @@ fn show_version() {
9595
// Only use `option_env` on vergen variables to ensure the build succeeds
9696
// when vergen failed to find the git info.
9797
if let Some(sha) = option_env!("VERGEN_GIT_SHA_SHORT") {
98-
write!(&mut version, " ({} {})", sha, option_env!("VERGEN_GIT_COMMIT_DATE").unwrap()).unwrap();
98+
write!(&mut version, " ({} {})", sha, option_env!("VERGEN_GIT_COMMIT_DATE").unwrap())
99+
.unwrap();
99100
}
100101
println!("{}", version);
101102
}
@@ -168,8 +169,7 @@ fn forward_patched_extern_arg(args: &mut impl Iterator<Item = String>, cmd: &mut
168169
}
169170

170171
fn forward_miri_sysroot(cmd: &mut Command) {
171-
let sysroot =
172-
env::var_os("MIRI_SYSROOT").expect("the wrapper should have set MIRI_SYSROOT");
172+
let sysroot = env::var_os("MIRI_SYSROOT").expect("the wrapper should have set MIRI_SYSROOT");
173173
cmd.arg("--sysroot");
174174
cmd.arg(sysroot);
175175
}
@@ -471,7 +471,9 @@ fn phase_cargo_miri(mut args: env::Args) {
471471
Some("run") => MiriCommand::Run,
472472
Some("setup") => MiriCommand::Setup,
473473
// Invalid command.
474-
_ => show_error(format!("`cargo miri` supports the following subcommands: `run`, `test`, and `setup`.")),
474+
_ => show_error(format!(
475+
"`cargo miri` supports the following subcommands: `run`, `test`, and `setup`."
476+
)),
475477
};
476478
let verbose = has_arg_flag("-v");
477479

@@ -515,13 +517,14 @@ fn phase_cargo_miri(mut args: env::Args) {
515517
// i.e., the first argument is `rustc` -- which is what we use in `main` to distinguish
516518
// the two codepaths. (That extra argument is why we prefer this over setting `RUSTC`.)
517519
if env::var_os("RUSTC_WRAPPER").is_some() {
518-
println!("WARNING: Ignoring `RUSTC_WRAPPER` environment variable, Miri does not support wrapping.");
520+
println!(
521+
"WARNING: Ignoring `RUSTC_WRAPPER` environment variable, Miri does not support wrapping."
522+
);
519523
}
520524
cmd.env("RUSTC_WRAPPER", &cargo_miri_path);
521525

522-
let runner_env_name = |triple: &str| {
523-
format!("CARGO_TARGET_{}_RUNNER", triple.to_uppercase().replace('-', "_"))
524-
};
526+
let runner_env_name =
527+
|triple: &str| format!("CARGO_TARGET_{}_RUNNER", triple.to_uppercase().replace('-', "_"));
525528
let host_runner_env_name = runner_env_name(&host);
526529
let target_runner_env_name = runner_env_name(target);
527530
// Set the target runner to us, so we can interpret the binaries.
@@ -628,7 +631,10 @@ fn phase_rustc(mut args: env::Args, phase: RustcPhase) {
628631
let runnable_crate = !print && is_runnable_crate();
629632

630633
if runnable_crate && target_crate {
631-
assert!(phase != RustcPhase::Setup, "there should be no interpretation during sysroot build");
634+
assert!(
635+
phase != RustcPhase::Setup,
636+
"there should be no interpretation during sysroot build"
637+
);
632638
let inside_rustdoc = phase == RustcPhase::Rustdoc;
633639
// This is the binary or test crate that we want to interpret under Miri.
634640
// But we cannot run it here, as cargo invoked us as a compiler -- our stdin and stdout are not
@@ -657,7 +663,10 @@ fn phase_rustc(mut args: env::Args, phase: RustcPhase) {
657663
cmd.env("MIRI_BE_RUSTC", "target");
658664

659665
if verbose {
660-
eprintln!("[cargo-miri rustc] captured input:\n{}", std::str::from_utf8(&env.stdin).unwrap());
666+
eprintln!(
667+
"[cargo-miri rustc] captured input:\n{}",
668+
std::str::from_utf8(&env.stdin).unwrap()
669+
);
661670
eprintln!("[cargo-miri rustc] {:?}", cmd);
662671
}
663672

@@ -715,7 +724,9 @@ fn phase_rustc(mut args: env::Args, phase: RustcPhase) {
715724
}
716725

717726
// During setup, patch the panic runtime for `libpanic_abort` (mirroring what bootstrap usually does).
718-
if phase == RustcPhase::Setup && get_arg_flag_value("--crate-name").as_deref() == Some("panic_abort") {
727+
if phase == RustcPhase::Setup
728+
&& get_arg_flag_value("--crate-name").as_deref() == Some("panic_abort")
729+
{
719730
cmd.arg("-C").arg("panic=abort");
720731
}
721732
} else {
@@ -765,12 +776,18 @@ fn phase_runner(binary: &Path, binary_args: env::Args, phase: RunnerPhase) {
765776
.unwrap_or_else(|_| show_error(format!("file {:?} not found or `cargo-miri` invoked incorrectly; please only invoke this binary through `cargo miri`", binary)));
766777
let file = BufReader::new(file);
767778

768-
let info = serde_json::from_reader(file)
769-
.unwrap_or_else(|_| show_error(format!("file {:?} contains outdated or invalid JSON; try `cargo clean`", binary)));
779+
let info = serde_json::from_reader(file).unwrap_or_else(|_| {
780+
show_error(format!(
781+
"file {:?} contains outdated or invalid JSON; try `cargo clean`",
782+
binary
783+
))
784+
});
770785
let info = match info {
771786
CrateRunInfo::RunWith(info) => info,
772787
CrateRunInfo::SkipProcMacroTest => {
773-
eprintln!("Running unit tests of `proc-macro` crates is not currently supported by Miri.");
788+
eprintln!(
789+
"Running unit tests of `proc-macro` crates is not currently supported by Miri."
790+
);
774791
return;
775792
}
776793
};
@@ -783,7 +800,10 @@ fn phase_runner(binary: &Path, binary_args: env::Args, phase: RunnerPhase) {
783800
if verbose {
784801
if let Some(old_val) = env::var_os(&name) {
785802
if old_val != val {
786-
eprintln!("[cargo-miri runner] Overwriting run-time env var {:?}={:?} with build-time value {:?}", name, old_val, val);
803+
eprintln!(
804+
"[cargo-miri runner] Overwriting run-time env var {:?}={:?} with build-time value {:?}",
805+
name, old_val, val
806+
);
787807
}
788808
}
789809
}
@@ -822,11 +842,7 @@ fn phase_runner(binary: &Path, binary_args: env::Args, phase: RunnerPhase) {
822842
// Respect `MIRIFLAGS`.
823843
if let Ok(a) = env::var("MIRIFLAGS") {
824844
// This code is taken from `RUSTFLAGS` handling in cargo.
825-
let args = a
826-
.split(' ')
827-
.map(str::trim)
828-
.filter(|s| !s.is_empty())
829-
.map(str::to_string);
845+
let args = a.split(' ').map(str::trim).filter(|s| !s.is_empty()).map(str::to_string);
830846
cmd.args(args);
831847
}
832848

@@ -845,12 +861,8 @@ fn phase_runner(binary: &Path, binary_args: env::Args, phase: RunnerPhase) {
845861
}
846862

847863
match phase {
848-
RunnerPhase::Rustdoc => {
849-
exec_with_pipe(cmd, &info.stdin)
850-
}
851-
RunnerPhase::Cargo => {
852-
exec(cmd)
853-
}
864+
RunnerPhase::Rustdoc => exec_with_pipe(cmd, &info.stdin),
865+
RunnerPhase::Cargo => exec(cmd),
854866
}
855867
}
856868

@@ -946,7 +958,10 @@ fn main() {
946958
if binary.exists() {
947959
phase_runner(binary, args, RunnerPhase::Rustdoc);
948960
} else {
949-
show_error(format!("`cargo-miri` called with non-existing path argument `{}` in rustdoc mode; please invoke this binary through `cargo miri`", arg));
961+
show_error(format!(
962+
"`cargo-miri` called with non-existing path argument `{}` in rustdoc mode; please invoke this binary through `cargo miri`",
963+
arg
964+
));
950965
}
951966
} else {
952967
phase_rustc(args, RustcPhase::Rustdoc);
@@ -977,9 +992,14 @@ fn main() {
977992
} else if arg.starts_with("--") {
978993
phase_rustdoc(arg, args);
979994
} else {
980-
show_error(format!("`cargo-miri` called with unexpected first argument `{}`; please only invoke this binary through `cargo miri`", arg));
995+
show_error(format!(
996+
"`cargo-miri` called with unexpected first argument `{}`; please only invoke this binary through `cargo miri`",
997+
arg
998+
));
981999
}
9821000
}
983-
_ => show_error(format!("`cargo-miri` called without first argument; please only invoke this binary through `cargo miri`")),
1001+
_ => show_error(format!(
1002+
"`cargo-miri` called without first argument; please only invoke this binary through `cargo miri`"
1003+
)),
9841004
}
9851005
}

rustfmt.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
use_small_heuristics = "Max"
21
version = "Two"
2+
use_small_heuristics = "Max"
33
match_arm_blocks = false
4+
match_arm_leading_pipes = "Preserve"

src/bin/miri.rs

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#![feature(rustc_private)]
22

3-
extern crate rustc_middle;
43
extern crate rustc_driver;
4+
extern crate rustc_errors;
55
extern crate rustc_hir;
66
extern crate rustc_interface;
7+
extern crate rustc_middle;
78
extern crate rustc_session;
8-
extern crate rustc_errors;
99

1010
use std::convert::TryFrom;
1111
use std::env;
@@ -14,11 +14,11 @@ use std::str::FromStr;
1414
use hex::FromHexError;
1515
use log::debug;
1616

17-
use rustc_session::{CtfeBacktrace, config::ErrorOutputType};
18-
use rustc_errors::emitter::{HumanReadableErrorType, ColorConfig};
1917
use rustc_driver::Compilation;
18+
use rustc_errors::emitter::{ColorConfig, HumanReadableErrorType};
2019
use rustc_hir::def_id::LOCAL_CRATE;
2120
use rustc_middle::ty::TyCtxt;
21+
use rustc_session::{config::ErrorOutputType, CtfeBacktrace};
2222

2323
struct MiriCompilerCalls {
2424
miri_config: miri::MiriConfig,
@@ -37,8 +37,13 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
3737
let (entry_def_id, _) = if let Some((entry_def, x)) = tcx.entry_fn(LOCAL_CRATE) {
3838
(entry_def, x)
3939
} else {
40-
let output_ty = ErrorOutputType::HumanReadable(HumanReadableErrorType::Default(ColorConfig::Auto));
41-
rustc_session::early_error(output_ty, "miri can only run programs that have a main function");
40+
let output_ty = ErrorOutputType::HumanReadable(HumanReadableErrorType::Default(
41+
ColorConfig::Auto,
42+
));
43+
rustc_session::early_error(
44+
output_ty,
45+
"miri can only run programs that have a main function",
46+
);
4247
};
4348
let mut config = self.miri_config.clone();
4449

@@ -249,28 +254,27 @@ fn main() {
249254
err => panic!("unknown error decoding -Zmiri-seed as hex: {:?}", err),
250255
});
251256
if seed_raw.len() > 8 {
252-
panic!(
253-
"-Zmiri-seed must be at most 8 bytes, was {}",
254-
seed_raw.len()
255-
);
257+
panic!("-Zmiri-seed must be at most 8 bytes, was {}", seed_raw.len());
256258
}
257259

258260
let mut bytes = [0; 8];
259261
bytes[..seed_raw.len()].copy_from_slice(&seed_raw);
260262
miri_config.seed = Some(u64::from_be_bytes(bytes));
261263
}
262264
arg if arg.starts_with("-Zmiri-env-exclude=") => {
263-
miri_config.excluded_env_vars
265+
miri_config
266+
.excluded_env_vars
264267
.push(arg.strip_prefix("-Zmiri-env-exclude=").unwrap().to_owned());
265268
}
266269
arg if arg.starts_with("-Zmiri-track-pointer-tag=") => {
267-
let id: u64 = match arg.strip_prefix("-Zmiri-track-pointer-tag=").unwrap().parse() {
268-
Ok(id) => id,
269-
Err(err) => panic!(
270-
"-Zmiri-track-pointer-tag requires a valid `u64` argument: {}",
271-
err
272-
),
273-
};
270+
let id: u64 =
271+
match arg.strip_prefix("-Zmiri-track-pointer-tag=").unwrap().parse() {
272+
Ok(id) => id,
273+
Err(err) => panic!(
274+
"-Zmiri-track-pointer-tag requires a valid `u64` argument: {}",
275+
err
276+
),
277+
};
274278
if let Some(id) = miri::PtrId::new(id) {
275279
miri_config.tracked_pointer_tag = Some(id);
276280
} else {
@@ -280,10 +284,8 @@ fn main() {
280284
arg if arg.starts_with("-Zmiri-track-call-id=") => {
281285
let id: u64 = match arg.strip_prefix("-Zmiri-track-call-id=").unwrap().parse() {
282286
Ok(id) => id,
283-
Err(err) => panic!(
284-
"-Zmiri-track-call-id requires a valid `u64` argument: {}",
285-
err
286-
),
287+
Err(err) =>
288+
panic!("-Zmiri-track-call-id requires a valid `u64` argument: {}", err),
287289
};
288290
if let Some(id) = miri::CallId::new(id) {
289291
miri_config.tracked_call_id = Some(id);
@@ -292,20 +294,28 @@ fn main() {
292294
}
293295
}
294296
arg if arg.starts_with("-Zmiri-track-alloc-id=") => {
295-
let id: u64 = match arg.strip_prefix("-Zmiri-track-alloc-id=").unwrap().parse() {
297+
let id: u64 = match arg.strip_prefix("-Zmiri-track-alloc-id=").unwrap().parse()
298+
{
296299
Ok(id) => id,
297-
Err(err) => panic!(
298-
"-Zmiri-track-alloc-id requires a valid `u64` argument: {}",
299-
err
300-
),
300+
Err(err) =>
301+
panic!("-Zmiri-track-alloc-id requires a valid `u64` argument: {}", err),
301302
};
302303
miri_config.tracked_alloc_id = Some(miri::AllocId(id));
303304
}
304305
arg if arg.starts_with("-Zmiri-compare-exchange-weak-failure-rate=") => {
305-
let rate = match arg.strip_prefix("-Zmiri-compare-exchange-weak-failure-rate=").unwrap().parse::<f64>() {
306+
let rate = match arg
307+
.strip_prefix("-Zmiri-compare-exchange-weak-failure-rate=")
308+
.unwrap()
309+
.parse::<f64>()
310+
{
306311
Ok(rate) if rate >= 0.0 && rate <= 1.0 => rate,
307-
Ok(_) => panic!("-Zmiri-compare-exchange-weak-failure-rate must be between `0.0` and `1.0`"),
308-
Err(err) => panic!("-Zmiri-compare-exchange-weak-failure-rate requires a `f64` between `0.0` and `1.0`: {}", err),
312+
Ok(_) => panic!(
313+
"-Zmiri-compare-exchange-weak-failure-rate must be between `0.0` and `1.0`"
314+
),
315+
Err(err) => panic!(
316+
"-Zmiri-compare-exchange-weak-failure-rate requires a `f64` between `0.0` and `1.0`: {}",
317+
err
318+
),
309319
};
310320
miri_config.cmpxchg_weak_failure_rate = rate;
311321
}
@@ -319,5 +329,9 @@ fn main() {
319329

320330
debug!("rustc arguments: {:?}", rustc_args);
321331
debug!("crate arguments: {:?}", miri_config.args);
322-
run_compiler(rustc_args, &mut MiriCompilerCalls { miri_config }, /* insert_default_args: */ true)
332+
run_compiler(
333+
rustc_args,
334+
&mut MiriCompilerCalls { miri_config },
335+
/* insert_default_args: */ true,
336+
)
323337
}

0 commit comments

Comments
 (0)