Skip to content

Commit 5a17c17

Browse files
committed
treat test binaries like all others
1 parent 16c23ef commit 5a17c17

File tree

2 files changed

+9
-43
lines changed

2 files changed

+9
-43
lines changed

src/bin/cargo-miri.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,7 @@ fn main() {
249249
(MiriCommand::Test, "lib") => {
250250
// For libraries we call `cargo rustc -- --test <rustc args>`
251251
// Notice now that `--test` is a rustc arg rather than a cargo arg. This tells
252-
// rustc to build a test harness which calls all #[test] functions. We don't
253-
// use the harness since we execute each #[test] function's MIR ourselves before
254-
// compilation even completes, but this option is necessary to build the library.
252+
// rustc to build a test harness which calls all #[test] functions.
255253
if let Err(code) = process(
256254
vec!["--".to_string(), "--test".to_string()].into_iter().chain(
257255
args,
@@ -326,8 +324,9 @@ fn main() {
326324
};
327325

328326
args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-miri""#.to_owned()]);
327+
command.args(&args);
329328

330-
match command.args(&args).status() {
329+
match command.status() {
331330
Ok(exit) => {
332331
if !exit.success() {
333332
std::process::exit(exit.code().unwrap_or(42));

src/bin/miri.rs

+6-39
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ use rustc_metadata::cstore::CStore;
2323
use rustc_driver::{Compilation, CompilerCalls, RustcDefaultCalls};
2424
use rustc_driver::driver::{CompileState, CompileController};
2525
use rustc::session::config::{self, Input, ErrorOutputType};
26-
use rustc::hir::{self, itemlikevisit};
27-
use rustc::ty::TyCtxt;
2826
use rustc_codegen_utils::codegen_backend::CodegenBackend;
2927
use syntax::ast;
3028

@@ -115,43 +113,12 @@ fn after_analysis<'a, 'tcx>(
115113

116114
let tcx = state.tcx.unwrap();
117115

118-
if std::env::args().any(|arg| arg == "--test") {
119-
struct Visitor<'a, 'tcx: 'a> {
120-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
121-
state: &'a CompileState<'a, 'tcx>,
122-
validate: bool,
123-
};
124-
impl<'a, 'tcx: 'a, 'hir> itemlikevisit::ItemLikeVisitor<'hir> for Visitor<'a, 'tcx> {
125-
fn visit_item(&mut self, i: &'hir hir::Item) {
126-
if let hir::ItemKind::Fn(.., body_id) = i.node {
127-
if i.attrs.iter().any(|attr| {
128-
attr.name() == "test"
129-
})
130-
{
131-
let did = self.tcx.hir.body_owner_def_id(body_id);
132-
println!(
133-
"running test: {}",
134-
self.tcx.def_path_debug_str(did),
135-
);
136-
miri::eval_main(self.tcx, did, self.validate);
137-
self.state.session.abort_if_errors();
138-
}
139-
}
140-
}
141-
fn visit_trait_item(&mut self, _trait_item: &'hir hir::TraitItem) {}
142-
fn visit_impl_item(&mut self, _impl_item: &'hir hir::ImplItem) {}
143-
}
144-
state.hir_crate.unwrap().visit_all_item_likes(
145-
&mut Visitor { tcx, state, validate }
146-
);
147-
} else if let Some((entry_node_id, _, _)) = *state.session.entry_fn.borrow() {
148-
let entry_def_id = tcx.hir.local_def_id(entry_node_id);
149-
miri::eval_main(tcx, entry_def_id, validate);
150-
151-
state.session.abort_if_errors();
152-
} else {
153-
println!("no main function found, assuming auxiliary build");
154-
}
116+
let (entry_node_id, _, _) = state.session.entry_fn.borrow().expect("no main function found!");
117+
let entry_def_id = tcx.hir.local_def_id(entry_node_id);
118+
119+
miri::eval_main(tcx, entry_def_id, validate);
120+
121+
state.session.abort_if_errors();
155122
}
156123

157124
fn init_early_loggers() {

0 commit comments

Comments
 (0)