Skip to content

Commit 1750a2f

Browse files
committed
Add tests for mixed panic mode restriction and lints
1 parent bc5afd9 commit 1750a2f

File tree

8 files changed

+90
-0
lines changed

8 files changed

+90
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// compile-flags:-C panic=abort
2+
// no-prefer-dynamic
3+
4+
#![crate_type = "rlib"]
5+
#![no_std]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// compile-flags:-C panic=unwind
2+
// no-prefer-dynamic
3+
4+
#![crate_type = "rlib"]
5+
#![no_std]
6+
#![feature(c_unwind)]
7+
8+
extern "C-unwind" fn foo() {}
9+
10+
fn bar() {
11+
let ptr: extern "C-unwind" fn() = foo;
12+
ptr();
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// build-fail
2+
// needs-unwind
3+
// error-pattern:is incompatible with this crate's strategy of `unwind`
4+
// aux-build:needs-abort.rs
5+
// ignore-wasm32-bare compiled with panic=abort by default
6+
7+
extern crate needs_abort;
8+
9+
fn main() {}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
error: the crate `needs_abort` requires panic strategy `abort` which is incompatible with this crate's strategy of `unwind`
2+
3+
error: aborting due to previous error
4+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// build-fail
2+
// error-pattern:is incompatible with this crate's strategy of `abort`
3+
// aux-build:needs-unwind.rs
4+
// compile-flags:-C panic=abort
5+
6+
extern crate needs_unwind;
7+
8+
fn main() {}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
error: the linked panic runtime `panic_unwind` is not compiled with this crate's panic strategy `abort`
2+
3+
error: the crate `needs_unwind` requires panic strategy `unwind` which is incompatible with this crate's strategy of `abort`
4+
5+
error: aborting due to 2 previous errors
6+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// build-pass
2+
3+
#![feature(c_unwind)]
4+
#![warn(ffi_unwind_calls)]
5+
6+
mod foo {
7+
#[no_mangle]
8+
pub extern "C-unwind" fn foo() {}
9+
}
10+
11+
extern "C-unwind" {
12+
fn foo();
13+
}
14+
15+
fn main() {
16+
// Call to Rust function is fine.
17+
foo::foo();
18+
// Call to foreign function should warn.
19+
unsafe { foo(); }
20+
//~^ WARNING call to foreign function with FFI-unwind ABI
21+
let ptr: extern "C-unwind" fn() = foo::foo;
22+
// Call to function pointer should also warn.
23+
ptr();
24+
//~^ WARNING call to function pointer with FFI-unwind ABI
25+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
warning: call to foreign function with FFI-unwind ABI
2+
--> $DIR/ffi-unwind-calls-lint.rs:19:14
3+
|
4+
LL | unsafe { foo(); }
5+
| ^^^^^ call to foreign function with FFI-unwind ABI
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/ffi-unwind-calls-lint.rs:4:9
9+
|
10+
LL | #![warn(ffi_unwind_calls)]
11+
| ^^^^^^^^^^^^^^^^
12+
13+
warning: call to function pointer with FFI-unwind ABI
14+
--> $DIR/ffi-unwind-calls-lint.rs:23:5
15+
|
16+
LL | ptr();
17+
| ^^^^^ call to function pointer with FFI-unwind ABI
18+
19+
warning: 2 warnings emitted
20+

0 commit comments

Comments
 (0)