Skip to content

Commit bde3111

Browse files
committed
test windows panic message
1 parent 0f1713f commit bde3111

File tree

6 files changed

+45
-6
lines changed

6 files changed

+45
-6
lines changed

src/shims/foreign_items.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
132132
// This matches calls to the foreign item `panic_impl`.
133133
// The implementation is provided by the function with the `#[panic_handler]` attribute.
134134
"panic_impl" => {
135-
// Make sure panicking actually works on this platform.
136-
match this.tcx.sess.target.target.target_os.as_str() {
137-
"linux" | "macos" => {},
138-
_ => throw_unsup_format!("panicking is not supported on this platform"),
139-
}
140-
135+
this.check_panic_supported()?;
141136
let panic_impl_id = this.tcx.lang_items().panic_impl().unwrap();
142137
let panic_impl_instance = ty::Instance::mono(*this.tcx, panic_impl_id);
143138
return Ok(Some(&*this.load_mir(panic_impl_instance.def, None)?));

src/shims/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
4242
return this.emulate_foreign_item(instance.def_id(), args, ret, unwind);
4343
}
4444

45+
// Better error message for panics on Windows.
46+
let def_id = instance.def_id();
47+
if Some(def_id) == this.tcx.lang_items().begin_panic_fn() ||
48+
Some(def_id) == this.tcx.lang_items().panic_impl()
49+
{
50+
this.check_panic_supported()?;
51+
}
52+
4553
// Otherwise, load the MIR.
4654
Ok(Some(&*this.load_mir(instance.def, None)?))
4755
}

src/shims/panic.rs

+8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ pub struct CatchUnwindData<'tcx> {
3232

3333
impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
3434
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
35+
/// Check if panicking is supported on this platform, and give a good error otherwise.
36+
fn check_panic_supported(&self) -> InterpResult<'tcx> {
37+
match self.eval_context_ref().tcx.sess.target.target.target_os.as_str() {
38+
"linux" | "macos" => Ok(()),
39+
_ => throw_unsup_format!("panicking is not supported on this platform"),
40+
}
41+
}
42+
3543
/// Handles the special `miri_start_panic` intrinsic, which is called
3644
/// by libpanic_unwind to delegate the actual unwinding process to Miri.
3745
fn handle_miri_start_panic(

tests/compile-fail/panic/windows1.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// ignore-linux
2+
// ignore-macos
3+
4+
// Test that panics on Windows give a reasonable error message.
5+
6+
// error-pattern: panicking is not supported on this platform
7+
fn main() {
8+
core::panic!("this is {}", "Windows");
9+
}

tests/compile-fail/panic/windows2.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// ignore-linux
2+
// ignore-macos
3+
4+
// Test that panics on Windows give a reasonable error message.
5+
6+
// error-pattern: panicking is not supported on this platform
7+
fn main() {
8+
std::panic!("this is Windows");
9+
}

tests/compile-fail/panic/windows3.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// ignore-linux
2+
// ignore-macos
3+
4+
// Test that panics on Windows give a reasonable error message.
5+
6+
// error-pattern: panicking is not supported on this platform
7+
#[allow(unconditional_panic)]
8+
fn main() {
9+
let _val = 1/0;
10+
}

0 commit comments

Comments
 (0)