-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
25f6938
commit 8d43b3c
Showing
15 changed files
with
136 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# `cfg_panic` | ||
|
||
The tracking issue for this feature is: [#77443] | ||
|
||
[#77443]: https://github.com/rust-lang/rust/issues/77443 | ||
|
||
------------------------ | ||
|
||
The `cfg_panic` feature makes it possible to execute different code | ||
depending on the panic strategy. | ||
|
||
Possible values at the moment are `"unwind"` or `"abort"`, although | ||
it is possible that new panic strategies may be added to Rust in the | ||
future. | ||
|
||
## Examples | ||
|
||
```rust | ||
#![feature(cfg_panic)] | ||
|
||
#[cfg(panic = "unwind")] | ||
fn a() { | ||
// ... | ||
} | ||
|
||
#[cfg(not(panic = "unwind"))] | ||
fn a() { | ||
// ... | ||
} | ||
|
||
fn b() { | ||
if cfg!(panic = "abort") { | ||
// ... | ||
} else { | ||
// ... | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// build-pass | ||
// compile-flags: -C panic=abort | ||
// no-prefer-dynamic | ||
#![feature(cfg_panic)] | ||
|
||
#[cfg(panic = "unwind")] | ||
pub fn bad() -> i32 { } | ||
|
||
#[cfg(not(panic = "abort"))] | ||
pub fn bad() -> i32 { } | ||
|
||
#[cfg(panic = "some_imaginary_future_panic_handler")] | ||
pub fn bad() -> i32 { } | ||
|
||
#[cfg(panic = "abort")] | ||
pub fn main() { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// build-pass | ||
// compile-flags: -C panic=unwind | ||
// ignore-emscripten no panic_unwind implementation | ||
// ignore-wasm32 no panic_unwind implementation | ||
// ignore-wasm64 no panic_unwind implementation | ||
#![feature(cfg_panic)] | ||
|
||
#[cfg(panic = "abort")] | ||
pub fn bad() -> i32 { } | ||
|
||
#[cfg(not(panic = "unwind"))] | ||
pub fn bad() -> i32 { } | ||
|
||
#[cfg(panic = "some_imaginary_future_panic_handler")] | ||
pub fn bad() -> i32 { } | ||
|
||
#[cfg(panic = "unwind")] | ||
pub fn main() { } |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
// Test that `assert` works when `const_panic` is enabled. | ||
|
||
// revisions: stock panic | ||
// revisions: stock const_panic | ||
|
||
#![cfg_attr(panic, feature(const_panic))] | ||
#![cfg_attr(const_panic, feature(const_panic))] | ||
|
||
const _: () = assert!(true); | ||
//[stock]~^ ERROR panicking in constants is unstable | ||
|
||
const _: () = assert!(false); | ||
//[stock]~^ ERROR panicking in constants is unstable | ||
//[panic]~^^ ERROR any use of this value will cause an error | ||
//[const_panic]~^^ ERROR any use of this value will cause an error | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#[cfg(panic = "unwind")] | ||
//~^ ERROR `cfg(panic)` is experimental and subject to change | ||
fn foo() -> bool { true } | ||
#[cfg(not(panic = "unwind"))] | ||
//~^ ERROR `cfg(panic)` is experimental and subject to change | ||
fn foo() -> bool { false } | ||
|
||
|
||
fn main() { | ||
assert!(foo()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
error[E0658]: `cfg(panic)` is experimental and subject to change | ||
--> $DIR/feature-gate-cfg-panic.rs:1:7 | ||
| | ||
LL | #[cfg(panic = "unwind")] | ||
| ^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #77443 <https://github.com/rust-lang/rust/issues/77443> for more information | ||
= help: add `#![feature(cfg_panic)]` to the crate attributes to enable | ||
|
||
error[E0658]: `cfg(panic)` is experimental and subject to change | ||
--> $DIR/feature-gate-cfg-panic.rs:4:11 | ||
| | ||
LL | #[cfg(not(panic = "unwind"))] | ||
| ^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #77443 <https://github.com/rust-lang/rust/issues/77443> for more information | ||
= help: add `#![feature(cfg_panic)]` to the crate attributes to enable | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters