mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
Add tests for mixed panic mode restriction and lints
This commit is contained in:
parent
bc5afd9e34
commit
1750a2f723
5
src/test/ui/panic-runtime/auxiliary/needs-abort.rs
Normal file
5
src/test/ui/panic-runtime/auxiliary/needs-abort.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// compile-flags:-C panic=abort
|
||||||
|
// no-prefer-dynamic
|
||||||
|
|
||||||
|
#![crate_type = "rlib"]
|
||||||
|
#![no_std]
|
13
src/test/ui/panic-runtime/auxiliary/needs-unwind.rs
Normal file
13
src/test/ui/panic-runtime/auxiliary/needs-unwind.rs
Normal 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();
|
||||||
|
}
|
9
src/test/ui/panic-runtime/need-abort-got-unwind.rs
Normal file
9
src/test/ui/panic-runtime/need-abort-got-unwind.rs
Normal 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() {}
|
4
src/test/ui/panic-runtime/need-abort-got-unwind.stderr
Normal file
4
src/test/ui/panic-runtime/need-abort-got-unwind.stderr
Normal 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
|
||||||
|
|
8
src/test/ui/panic-runtime/need-unwind-got-abort.rs
Normal file
8
src/test/ui/panic-runtime/need-unwind-got-abort.rs
Normal 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() {}
|
6
src/test/ui/panic-runtime/need-unwind-got-abort.stderr
Normal file
6
src/test/ui/panic-runtime/need-unwind-got-abort.stderr
Normal 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
|
||||||
|
|
25
src/test/ui/unwind-abis/ffi-unwind-calls-lint.rs
Normal file
25
src/test/ui/unwind-abis/ffi-unwind-calls-lint.rs
Normal 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
|
||||||
|
}
|
20
src/test/ui/unwind-abis/ffi-unwind-calls-lint.stderr
Normal file
20
src/test/ui/unwind-abis/ffi-unwind-calls-lint.stderr
Normal 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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user