Add tests for mixed panic mode restriction and lints

This commit is contained in:
Gary Guo 2022-05-20 21:52:00 +01:00
parent bc5afd9e34
commit 1750a2f723
8 changed files with 90 additions and 0 deletions

View File

@ -0,0 +1,5 @@
// compile-flags:-C panic=abort
// no-prefer-dynamic
#![crate_type = "rlib"]
#![no_std]

View File

@ -0,0 +1,13 @@
// compile-flags:-C panic=unwind
// no-prefer-dynamic
#![crate_type = "rlib"]
#![no_std]
#![feature(c_unwind)]
extern "C-unwind" fn foo() {}
fn bar() {
let ptr: extern "C-unwind" fn() = foo;
ptr();
}

View File

@ -0,0 +1,9 @@
// build-fail
// needs-unwind
// error-pattern:is incompatible with this crate's strategy of `unwind`
// aux-build:needs-abort.rs
// ignore-wasm32-bare compiled with panic=abort by default
extern crate needs_abort;
fn main() {}

View File

@ -0,0 +1,4 @@
error: the crate `needs_abort` requires panic strategy `abort` which is incompatible with this crate's strategy of `unwind`
error: aborting due to previous error

View File

@ -0,0 +1,8 @@
// build-fail
// error-pattern:is incompatible with this crate's strategy of `abort`
// aux-build:needs-unwind.rs
// compile-flags:-C panic=abort
extern crate needs_unwind;
fn main() {}

View File

@ -0,0 +1,6 @@
error: the linked panic runtime `panic_unwind` is not compiled with this crate's panic strategy `abort`
error: the crate `needs_unwind` requires panic strategy `unwind` which is incompatible with this crate's strategy of `abort`
error: aborting due to 2 previous errors

View File

@ -0,0 +1,25 @@
// build-pass
#![feature(c_unwind)]
#![warn(ffi_unwind_calls)]
mod foo {
#[no_mangle]
pub extern "C-unwind" fn foo() {}
}
extern "C-unwind" {
fn foo();
}
fn main() {
// Call to Rust function is fine.
foo::foo();
// Call to foreign function should warn.
unsafe { foo(); }
//~^ WARNING call to foreign function with FFI-unwind ABI
let ptr: extern "C-unwind" fn() = foo::foo;
// Call to function pointer should also warn.
ptr();
//~^ WARNING call to function pointer with FFI-unwind ABI
}

View File

@ -0,0 +1,20 @@
warning: call to foreign function with FFI-unwind ABI
--> $DIR/ffi-unwind-calls-lint.rs:19:14
|
LL | unsafe { foo(); }
| ^^^^^ call to foreign function with FFI-unwind ABI
|
note: the lint level is defined here
--> $DIR/ffi-unwind-calls-lint.rs:4:9
|
LL | #![warn(ffi_unwind_calls)]
| ^^^^^^^^^^^^^^^^
warning: call to function pointer with FFI-unwind ABI
--> $DIR/ffi-unwind-calls-lint.rs:23:5
|
LL | ptr();
| ^^^^^ call to function pointer with FFI-unwind ABI
warning: 2 warnings emitted