Skip to content

Commit

Permalink
Merge pull request rust-lang#127 from oli-obk/print_panic
Browse files Browse the repository at this point in the history
ignore `print!`, turn `panic!` into a EvalError
  • Loading branch information
solson authored Feb 9, 2017
2 parents 2048679 + fb2d393 commit bc5d9b6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub enum EvalError<'tcx> {
ExpectedConcreteFunction(Function<'tcx>),
ExpectedDropGlue(Function<'tcx>),
ManuallyCalledDropGlue,
Panic,
}

pub type EvalResult<'tcx, T = ()> = Result<T, EvalError<'tcx>>;
Expand Down Expand Up @@ -134,6 +135,8 @@ impl<'tcx> Error for EvalError<'tcx> {
"tried to use non-drop-glue function as drop glue",
EvalError::ManuallyCalledDropGlue =>
"tried to manually invoke drop glue",
EvalError::Panic =>
"the evaluated program panicked",
}
}

Expand Down
20 changes: 19 additions & 1 deletion src/terminator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,25 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
}
}

let mir = self.load_mir(resolved_def_id)?;
let mir = match self.load_mir(resolved_def_id) {
Ok(mir) => mir,
Err(EvalError::NoMirFor(path)) => {
match &path[..] {
// let's just ignore all output for now
"std::io::_print" => {
self.goto_block(destination.unwrap().1);
return Ok(());
},
"std::thread::Builder::new" => return Err(EvalError::Unimplemented("miri does not support threading".to_owned())),
"std::env::args" => return Err(EvalError::Unimplemented("miri does not support program arguments".to_owned())),
"std::panicking::rust_panic_with_hook" |
"std::rt::begin_panic_fmt" => return Err(EvalError::Panic),
_ => {},
}
return Err(EvalError::NoMirFor(path));
},
Err(other) => return Err(other),
};
let (return_lvalue, return_to_block) = match destination {
Some((lvalue, block)) => (lvalue, StackPopCleanup::Goto(block)),
None => {
Expand Down
4 changes: 1 addition & 3 deletions tests/compile-fail/env_args.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//error-pattern: no mir for `std::env::args`

fn main() {
let x = std::env::args();
let x = std::env::args(); //~ ERROR miri does not support program arguments
assert_eq!(x.count(), 1);
}
5 changes: 5 additions & 0 deletions tests/compile-fail/panic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//error-pattern: the evaluated program panicked

fn main() {
assert_eq!(5, 6);
}
5 changes: 0 additions & 5 deletions tests/compile-fail/unimplemented.rs

This file was deleted.

0 comments on commit bc5d9b6

Please sign in to comment.