Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
34ff352
don't refer to async as 'generators'
SNCPlay42 Jul 21, 2020
5042dbd
add RegionNameHighlight::Occluded
SNCPlay42 Sep 8, 2020
301bb12
Enable LLVM Polly via llvm-args.
JRF63 Oct 30, 2020
1f5c655
Fix query cycle when tracing explicit_item_bounds
matthewjasper Oct 28, 2020
299a65f
Update chalk 0.32.0 -> 0.35.0
matthewjasper Oct 28, 2020
acb6a06
Fix various Chalk lowering bugs
matthewjasper Oct 28, 2020
4d60a80
Address review comment and update chalk to 0.36.0
matthewjasper Oct 29, 2020
3237b38
rustc_ast: Do not panic by default when visiting macro calls
petrochenkov Nov 3, 2020
90fafc8
rustc_ast: `visit_mac` -> `visit_mac_call`
petrochenkov Nov 3, 2020
53c1eb7
ci: demote i686-unknown-freebsd to tier 2 compiler target
pietroalbini Nov 4, 2020
3863dee
Infer the default host target from the host toolchain if possible
jyn514 Oct 29, 2020
f78f36c
Monomorphize a type argument of size-of operation during codegen
tmiasko Nov 7, 2020
103f7a4
fix `super_visit_with` for `Terminator`
lcnr Nov 7, 2020
d847299
Run tools builder on subtree changes
Mark-Simulacrum Nov 8, 2020
7ca6e8f
BTreeMap: fix pointer provenance rules, make borrowing explicit
ssomers Oct 28, 2020
b7f16c5
inliner: Make `inline_call` infallible
tmiasko Nov 6, 2020
dc4d74d
inliner: Break inlining cycles
tmiasko Nov 9, 2020
8d43b3c
Add `#[cfg(panic = "...")]`
davidhewitt Jul 25, 2020
61b52a3
use RegionNameHighlight for async fn and closure returns
SNCPlay42 Sep 8, 2020
46bce9f
Rollup merge of #74754 - davidhewitt:cfg-panic, r=ecstatic-morse
Dylan-DPC Nov 9, 2020
99f16e6
Rollup merge of #76468 - SNCPlay42:lifetime-names, r=Mark-Simulacrum
Dylan-DPC Nov 9, 2020
391136e
Rollup merge of #77016 - Mark-Simulacrum:clippy-tests, r=pietroalbini
Dylan-DPC Nov 9, 2020
2187f3c
Rollup merge of #78480 - ssomers:btree-alias, r=Mark-Simulacrum
Dylan-DPC Nov 9, 2020
0aed74a
Rollup merge of #78502 - matthewjasper:chalkup, r=nikomatsakis
Dylan-DPC Nov 9, 2020
62d3a4f
Rollup merge of #78513 - jyn514:rustup-toolchain, r=Mark-Simulacrum
Dylan-DPC Nov 9, 2020
7ac079f
Rollup merge of #78566 - JRF63:polly, r=Mark-Simulacrum
Dylan-DPC Nov 9, 2020
ee1fedf
Rollup merge of #78580 - tmiasko:inline-loop, r=oli-obk
Dylan-DPC Nov 9, 2020
8ebca24
Rollup merge of #78710 - petrochenkov:macvisit, r=davidtwco
Dylan-DPC Nov 9, 2020
4e0695b
Rollup merge of #78746 - pietroalbini:i686-freebsd, r=Mark-Simulacrum
Dylan-DPC Nov 9, 2020
7924ecc
Rollup merge of #78830 - lcnr:mir-folder, r=oli-obk
Dylan-DPC Nov 9, 2020
c150b93
Rollup merge of #78844 - tmiasko:monomorphize-sizeof, r=oli-obk
Dylan-DPC Nov 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add #[cfg(panic = "...")]
  • Loading branch information
davidhewitt committed Nov 9, 2020
commit 8d43b3cbb91b7327b42b0da721525e7ae2911f0b
3 changes: 3 additions & 0 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,9 @@ declare_features! (
/// Allows the use of destructuring assignments.
(active, destructuring_assignment, "1.49.0", Some(71126), None),

/// Enables `#[cfg(panic = "...")]` config key.
(active, cfg_panic, "1.49.0", Some(77443), None),

// -------------------------------------------------------------------------
// feature-group-end: actual feature gates
// -------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const GATED_CFGS: &[GatedCfg] = &[
),
(sym::sanitize, sym::cfg_sanitize, cfg_fn!(cfg_sanitize)),
(sym::version, sym::cfg_version, cfg_fn!(cfg_version)),
(sym::panic, sym::cfg_panic, cfg_fn!(cfg_panic)),
];

/// Find a gated cfg determined by the `pred`icate which is given the cfg's name.
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,9 @@ pub fn default_configuration(sess: &Session) -> CrateConfig {
}
}

let panic_strategy = sess.panic_strategy();
ret.insert((sym::panic, Some(panic_strategy.desc_symbol())));

for s in sess.opts.debugging_opts.sanitizer {
let symbol = Symbol::intern(&s.to_string());
ret.insert((sym::sanitize, Some(symbol)));
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ symbols! {
cfg_attr,
cfg_attr_multi,
cfg_doctest,
cfg_panic,
cfg_sanitize,
cfg_target_feature,
cfg_target_has_atomic,
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use crate::spec::abi::{lookup as lookup_abi, Abi};
use crate::spec::crt_objects::{CrtObjects, CrtObjectsFallback};
use rustc_serialize::json::{Json, ToJson};
use rustc_span::symbol::{sym, Symbol};
use std::collections::BTreeMap;
use std::ops::Deref;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -176,6 +177,13 @@ impl PanicStrategy {
PanicStrategy::Abort => "abort",
}
}

pub fn desc_symbol(&self) -> Symbol {
match *self {
PanicStrategy::Unwind => sym::unwind,
PanicStrategy::Abort => sym::abort,
}
}
}

impl ToJson for PanicStrategy {
Expand Down
38 changes: 38 additions & 0 deletions src/doc/unstable-book/src/language-features/cfg-panic.md
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 {
// ...
}
}
```
16 changes: 16 additions & 0 deletions src/test/ui/cfg/cfg-panic-abort.rs
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() { }
18 changes: 18 additions & 0 deletions src/test/ui/cfg/cfg-panic.rs
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() { }
6 changes: 3 additions & 3 deletions src/test/ui/consts/control-flow/assert.rs
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() {}
11 changes: 11 additions & 0 deletions src/test/ui/feature-gates/feature-gate-cfg-panic.rs
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());
}
21 changes: 21 additions & 0 deletions src/test/ui/feature-gates/feature-gate-cfg-panic.stderr
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`.
13 changes: 9 additions & 4 deletions src/test/ui/fmt/format-args-capture.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// run-pass
// ignore-wasm32
// ignore-wasm64
#![feature(format_args_capture)]
#![feature(cfg_panic)]

fn main() {
named_argument_takes_precedence_to_captured();
panic_with_single_argument_does_not_get_formatted();
panic_with_multiple_arguments_is_formatted();
formatting_parameters_can_be_captured();

#[cfg(panic = "unwind")]
{
panic_with_single_argument_does_not_get_formatted();
panic_with_multiple_arguments_is_formatted();
}
}

fn named_argument_takes_precedence_to_captured() {
Expand All @@ -22,6 +25,7 @@ fn named_argument_takes_precedence_to_captured() {
assert_eq!(&s, "positional-named-captured");
}

#[cfg(panic = "unwind")]
fn panic_with_single_argument_does_not_get_formatted() {
// panic! with a single argument does not perform string formatting.
// RFC #2795 suggests that this may need to change so that captured arguments are formatted.
Expand All @@ -34,6 +38,7 @@ fn panic_with_single_argument_does_not_get_formatted() {
assert_eq!(msg.downcast_ref::<&str>(), Some(&"{foo}"))
}

#[cfg(panic = "unwind")]
fn panic_with_multiple_arguments_is_formatted() {
let foo = "captured";

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-68696-catch-during-unwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
// entering the catch_unwind.
//
// run-pass
// ignore-wasm no panic support
// ignore-emscripten no panic support
#![feature(cfg_panic)]

use std::panic::catch_unwind;

Expand All @@ -19,6 +18,7 @@ impl Drop for Guard {
}

fn main() {
#[cfg(panic = "unwind")]
let _ = catch_unwind(|| {
let _guard = Guard::default();
panic!();
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/test-attrs/test-allow-fail-attr.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// run-pass
// ignore-wasm32-bare compiled with panic=abort by default
// compile-flags: --test
#![feature(allow_fail)]
#![feature(cfg_panic)]

#[test]
#[allow_fail]
fn test1() {
#[cfg(not(panic = "abort"))]
panic!();
}

Expand Down