Skip to content

Commit 63c4843

Browse files
authored
Merge pull request #299 from RalfJung/rustfmt
rustfmt
2 parents 85fd3f8 + 1326aed commit 63c4843

29 files changed

+2663
-1265
lines changed

benches/fibonacci.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ use helpers::*;
77

88
#[bench]
99
fn fib(bencher: &mut Bencher) {
10-
bencher.iter(|| {
11-
fibonacci_helper::main();
12-
})
10+
bencher.iter(|| { fibonacci_helper::main(); })
1311
}
1412

1513
#[bench]
@@ -19,9 +17,7 @@ fn fib_miri(bencher: &mut Bencher) {
1917

2018
#[bench]
2119
fn fib_iter(bencher: &mut Bencher) {
22-
bencher.iter(|| {
23-
fibonacci_helper_iterative::main();
24-
})
20+
bencher.iter(|| { fibonacci_helper_iterative::main(); })
2521
}
2622

2723
#[bench]

benches/helpers/fibonacci_helper.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,5 @@ pub fn main() {
44
}
55

66
fn fib(n: usize) -> usize {
7-
if n <= 2 {
8-
1
9-
} else {
10-
fib(n - 1) + fib(n - 2)
11-
}
7+
if n <= 2 { 1 } else { fib(n - 1) + fib(n - 2) }
128
}

benches/helpers/miri_helper.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ fn find_sysroot() -> String {
1919
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
2020
match (home, toolchain) {
2121
(Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain),
22-
_ => option_env!("RUST_SYSROOT")
23-
.expect("need to specify RUST_SYSROOT env var or use rustup or multirust")
24-
.to_owned(),
22+
_ => {
23+
option_env!("RUST_SYSROOT")
24+
.expect(
25+
"need to specify RUST_SYSROOT env var or use rustup or multirust",
26+
)
27+
.to_owned()
28+
}
2529
}
2630
}
2731

@@ -30,7 +34,7 @@ pub fn run(filename: &str, bencher: &mut Bencher) {
3034
"miri".to_string(),
3135
format!("benches/helpers/{}.rs", filename),
3236
"--sysroot".to_string(),
33-
find_sysroot()
37+
find_sysroot(),
3438
];
3539
let compiler_calls = &mut MiriCompilerCalls(Rc::new(RefCell::new(bencher)));
3640
rustc_driver::run_compiler(args, compiler_calls, None, None);
@@ -40,7 +44,7 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls<'a> {
4044
fn build_controller(
4145
&mut self,
4246
_: &Session,
43-
_: &getopts::Matches
47+
_: &getopts::Matches,
4448
) -> driver::CompileController<'a> {
4549
let mut control: driver::CompileController<'a> = driver::CompileController::basic();
4650

@@ -51,14 +55,17 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls<'a> {
5155
state.session.abort_if_errors();
5256

5357
let tcx = state.tcx.unwrap();
54-
let (entry_node_id, _) = state.session.entry_fn.borrow()
55-
.expect("no main or start function found");
58+
let (entry_node_id, _) = state.session.entry_fn.borrow().expect(
59+
"no main or start function found",
60+
);
5661
let entry_def_id = tcx.map.local_def_id(entry_node_id);
5762

58-
let memory_size = 100*1024*1024; // 100MB
63+
let memory_size = 100 * 1024 * 1024; // 100MB
5964
let step_limit = 1000_000;
6065
let stack_limit = 100;
61-
bencher.borrow_mut().iter(|| { eval_main(tcx, entry_def_id, memory_size, step_limit, stack_limit); });
66+
bencher.borrow_mut().iter(|| {
67+
eval_main(tcx, entry_def_id, memory_size, step_limit, stack_limit);
68+
});
6269

6370
state.session.abort_if_errors();
6471
});

benches/helpers/smoke_helper.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
#[inline(never)]
2-
pub fn main() {
3-
}
2+
pub fn main() {}

benches/smoke.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ use helpers::*;
77

88
#[bench]
99
fn noop(bencher: &mut Bencher) {
10-
bencher.iter(|| {
11-
smoke_helper::main();
12-
})
10+
bencher.iter(|| { smoke_helper::main(); })
1311
}
1412

1513
/*

miri/bin/cargo-miri.rs

+49-17
Original file line numberDiff line numberDiff line change
@@ -50,43 +50,68 @@ fn main() {
5050
let test = std::env::args().nth(2).map_or(false, |text| text == "test");
5151
let skip = if test { 3 } else { 2 };
5252

53-
let manifest_path_arg = std::env::args().skip(skip).find(|val| val.starts_with("--manifest-path="));
54-
55-
let mut metadata = if let Ok(metadata) = cargo_metadata::metadata(manifest_path_arg.as_ref().map(AsRef::as_ref)) {
53+
let manifest_path_arg = std::env::args().skip(skip).find(|val| {
54+
val.starts_with("--manifest-path=")
55+
});
56+
57+
let mut metadata = if let Ok(metadata) = cargo_metadata::metadata(
58+
manifest_path_arg.as_ref().map(AsRef::as_ref),
59+
)
60+
{
5661
metadata
5762
} else {
58-
let _ = std::io::stderr().write_fmt(format_args!("error: Could not obtain cargo metadata."));
63+
let _ = std::io::stderr().write_fmt(format_args!(
64+
"error: Could not obtain cargo metadata."
65+
));
5966
std::process::exit(101);
6067
};
6168

62-
let manifest_path = manifest_path_arg.map(|arg| PathBuf::from(Path::new(&arg["--manifest-path=".len()..])));
69+
let manifest_path = manifest_path_arg.map(|arg| {
70+
PathBuf::from(Path::new(&arg["--manifest-path=".len()..]))
71+
});
6372

6473
let current_dir = std::env::current_dir();
6574

66-
let package_index = metadata.packages
75+
let package_index = metadata
76+
.packages
6777
.iter()
6878
.position(|package| {
6979
let package_manifest_path = Path::new(&package.manifest_path);
7080
if let Some(ref manifest_path) = manifest_path {
7181
package_manifest_path == manifest_path
7282
} else {
73-
let current_dir = current_dir.as_ref().expect("could not read current directory");
74-
let package_manifest_directory = package_manifest_path.parent()
75-
.expect("could not find parent directory of package manifest");
83+
let current_dir = current_dir.as_ref().expect(
84+
"could not read current directory",
85+
);
86+
let package_manifest_directory = package_manifest_path.parent().expect(
87+
"could not find parent directory of package manifest",
88+
);
7689
package_manifest_directory == current_dir
7790
}
7891
})
7992
.expect("could not find matching package");
8093
let package = metadata.packages.remove(package_index);
8194
for target in package.targets {
8295
let args = std::env::args().skip(skip);
83-
let kind = target.kind.get(0).expect("badly formatted cargo metadata: target::kind is an empty array");
96+
let kind = target.kind.get(0).expect(
97+
"badly formatted cargo metadata: target::kind is an empty array",
98+
);
8499
if test && kind == "test" {
85-
if let Err(code) = process(vec!["--test".to_string(), target.name].into_iter().chain(args)) {
100+
if let Err(code) = process(
101+
vec!["--test".to_string(), target.name].into_iter().chain(
102+
args,
103+
),
104+
)
105+
{
86106
std::process::exit(code);
87107
}
88108
} else if !test && kind == "bin" {
89-
if let Err(code) = process(vec!["--bin".to_string(), target.name].into_iter().chain(args)) {
109+
if let Err(code) = process(
110+
vec!["--bin".to_string(), target.name].into_iter().chain(
111+
args,
112+
),
113+
)
114+
{
90115
std::process::exit(code);
91116
}
92117
}
@@ -118,7 +143,11 @@ fn main() {
118143
let mut args: Vec<String> = if std::env::args().any(|s| s == "--sysroot") {
119144
std::env::args().skip(1).collect()
120145
} else {
121-
std::env::args().skip(1).chain(Some("--sysroot".to_owned())).chain(Some(sys_root)).collect()
146+
std::env::args()
147+
.skip(1)
148+
.chain(Some("--sysroot".to_owned()))
149+
.chain(Some(sys_root))
150+
.collect()
122151
};
123152

124153
// this check ensures that dependencies are built but not interpreted and the final crate is
@@ -137,17 +166,20 @@ fn main() {
137166
args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-miri""#.to_owned()]);
138167

139168
match command.args(&args).status() {
140-
Ok(exit) => if !exit.success() {
141-
std::process::exit(exit.code().unwrap_or(42));
142-
},
169+
Ok(exit) => {
170+
if !exit.success() {
171+
std::process::exit(exit.code().unwrap_or(42));
172+
}
173+
}
143174
Err(ref e) if miri_enabled => panic!("error during miri run: {:?}", e),
144175
Err(ref e) => panic!("error during rustc call: {:?}", e),
145176
}
146177
}
147178
}
148179

149180
fn process<I>(old_args: I) -> Result<(), i32>
150-
where I: Iterator<Item = String>
181+
where
182+
I: Iterator<Item = String>,
151183
{
152184
let mut args = vec!["rustc".to_owned()];
153185

0 commit comments

Comments
 (0)