Skip to content

Commit

Permalink
Merge pull request rust-lang#299 from RalfJung/rustfmt
Browse files Browse the repository at this point in the history
rustfmt
  • Loading branch information
oli-obk authored Aug 10, 2017
2 parents 85fd3f8 + 1326aed commit 63c4843
Show file tree
Hide file tree
Showing 29 changed files with 2,663 additions and 1,265 deletions.
8 changes: 2 additions & 6 deletions benches/fibonacci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use helpers::*;

#[bench]
fn fib(bencher: &mut Bencher) {
bencher.iter(|| {
fibonacci_helper::main();
})
bencher.iter(|| { fibonacci_helper::main(); })
}

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

#[bench]
fn fib_iter(bencher: &mut Bencher) {
bencher.iter(|| {
fibonacci_helper_iterative::main();
})
bencher.iter(|| { fibonacci_helper_iterative::main(); })
}

#[bench]
Expand Down
6 changes: 1 addition & 5 deletions benches/helpers/fibonacci_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,5 @@ pub fn main() {
}

fn fib(n: usize) -> usize {
if n <= 2 {
1
} else {
fib(n - 1) + fib(n - 2)
}
if n <= 2 { 1 } else { fib(n - 1) + fib(n - 2) }
}
25 changes: 16 additions & 9 deletions benches/helpers/miri_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ fn find_sysroot() -> String {
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
match (home, toolchain) {
(Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain),
_ => option_env!("RUST_SYSROOT")
.expect("need to specify RUST_SYSROOT env var or use rustup or multirust")
.to_owned(),
_ => {
option_env!("RUST_SYSROOT")
.expect(
"need to specify RUST_SYSROOT env var or use rustup or multirust",
)
.to_owned()
}
}
}

Expand All @@ -30,7 +34,7 @@ pub fn run(filename: &str, bencher: &mut Bencher) {
"miri".to_string(),
format!("benches/helpers/{}.rs", filename),
"--sysroot".to_string(),
find_sysroot()
find_sysroot(),
];
let compiler_calls = &mut MiriCompilerCalls(Rc::new(RefCell::new(bencher)));
rustc_driver::run_compiler(args, compiler_calls, None, None);
Expand All @@ -40,7 +44,7 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls<'a> {
fn build_controller(
&mut self,
_: &Session,
_: &getopts::Matches
_: &getopts::Matches,
) -> driver::CompileController<'a> {
let mut control: driver::CompileController<'a> = driver::CompileController::basic();

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

let tcx = state.tcx.unwrap();
let (entry_node_id, _) = state.session.entry_fn.borrow()
.expect("no main or start function found");
let (entry_node_id, _) = state.session.entry_fn.borrow().expect(
"no main or start function found",
);
let entry_def_id = tcx.map.local_def_id(entry_node_id);

let memory_size = 100*1024*1024; // 100MB
let memory_size = 100 * 1024 * 1024; // 100MB
let step_limit = 1000_000;
let stack_limit = 100;
bencher.borrow_mut().iter(|| { eval_main(tcx, entry_def_id, memory_size, step_limit, stack_limit); });
bencher.borrow_mut().iter(|| {
eval_main(tcx, entry_def_id, memory_size, step_limit, stack_limit);
});

state.session.abort_if_errors();
});
Expand Down
3 changes: 1 addition & 2 deletions benches/helpers/smoke_helper.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#[inline(never)]
pub fn main() {
}
pub fn main() {}
4 changes: 1 addition & 3 deletions benches/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use helpers::*;

#[bench]
fn noop(bencher: &mut Bencher) {
bencher.iter(|| {
smoke_helper::main();
})
bencher.iter(|| { smoke_helper::main(); })
}

/*
Expand Down
66 changes: 49 additions & 17 deletions miri/bin/cargo-miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,43 +50,68 @@ fn main() {
let test = std::env::args().nth(2).map_or(false, |text| text == "test");
let skip = if test { 3 } else { 2 };

let manifest_path_arg = std::env::args().skip(skip).find(|val| val.starts_with("--manifest-path="));

let mut metadata = if let Ok(metadata) = cargo_metadata::metadata(manifest_path_arg.as_ref().map(AsRef::as_ref)) {
let manifest_path_arg = std::env::args().skip(skip).find(|val| {
val.starts_with("--manifest-path=")
});

let mut metadata = if let Ok(metadata) = cargo_metadata::metadata(
manifest_path_arg.as_ref().map(AsRef::as_ref),
)
{
metadata
} else {
let _ = std::io::stderr().write_fmt(format_args!("error: Could not obtain cargo metadata."));
let _ = std::io::stderr().write_fmt(format_args!(
"error: Could not obtain cargo metadata."
));
std::process::exit(101);
};

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

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

let package_index = metadata.packages
let package_index = metadata
.packages
.iter()
.position(|package| {
let package_manifest_path = Path::new(&package.manifest_path);
if let Some(ref manifest_path) = manifest_path {
package_manifest_path == manifest_path
} else {
let current_dir = current_dir.as_ref().expect("could not read current directory");
let package_manifest_directory = package_manifest_path.parent()
.expect("could not find parent directory of package manifest");
let current_dir = current_dir.as_ref().expect(
"could not read current directory",
);
let package_manifest_directory = package_manifest_path.parent().expect(
"could not find parent directory of package manifest",
);
package_manifest_directory == current_dir
}
})
.expect("could not find matching package");
let package = metadata.packages.remove(package_index);
for target in package.targets {
let args = std::env::args().skip(skip);
let kind = target.kind.get(0).expect("badly formatted cargo metadata: target::kind is an empty array");
let kind = target.kind.get(0).expect(
"badly formatted cargo metadata: target::kind is an empty array",
);
if test && kind == "test" {
if let Err(code) = process(vec!["--test".to_string(), target.name].into_iter().chain(args)) {
if let Err(code) = process(
vec!["--test".to_string(), target.name].into_iter().chain(
args,
),
)
{
std::process::exit(code);
}
} else if !test && kind == "bin" {
if let Err(code) = process(vec!["--bin".to_string(), target.name].into_iter().chain(args)) {
if let Err(code) = process(
vec!["--bin".to_string(), target.name].into_iter().chain(
args,
),
)
{
std::process::exit(code);
}
}
Expand Down Expand Up @@ -118,7 +143,11 @@ fn main() {
let mut args: Vec<String> = if std::env::args().any(|s| s == "--sysroot") {
std::env::args().skip(1).collect()
} else {
std::env::args().skip(1).chain(Some("--sysroot".to_owned())).chain(Some(sys_root)).collect()
std::env::args()
.skip(1)
.chain(Some("--sysroot".to_owned()))
.chain(Some(sys_root))
.collect()
};

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

match command.args(&args).status() {
Ok(exit) => if !exit.success() {
std::process::exit(exit.code().unwrap_or(42));
},
Ok(exit) => {
if !exit.success() {
std::process::exit(exit.code().unwrap_or(42));
}
}
Err(ref e) if miri_enabled => panic!("error during miri run: {:?}", e),
Err(ref e) => panic!("error during rustc call: {:?}", e),
}
}
}

fn process<I>(old_args: I) -> Result<(), i32>
where I: Iterator<Item = String>
where
I: Iterator<Item = String>,
{
let mut args = vec!["rustc".to_owned()];

Expand Down
Loading

0 comments on commit 63c4843

Please sign in to comment.