From 4404a4e365fb7090585e23f9d54110f214888f39 Mon Sep 17 00:00:00 2001 From: Charisee Date: Fri, 4 Feb 2022 02:22:02 +0000 Subject: [PATCH 1/7] updating the feature-gate listing and do not require the feature-gate to use the feature --- compiler/rustc_feature/src/accepted.rs | 2 ++ compiler/rustc_feature/src/active.rs | 2 -- compiler/rustc_feature/src/builtin_attrs.rs | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_feature/src/accepted.rs b/compiler/rustc_feature/src/accepted.rs index 88edaec916972..edcbead731f68 100644 --- a/compiler/rustc_feature/src/accepted.rs +++ b/compiler/rustc_feature/src/accepted.rs @@ -70,6 +70,8 @@ declare_features! ( (accepted, cfg_attr_multi, "1.33.0", Some(54881), None), /// Allows the use of `#[cfg(doctest)]`, set when rustdoc is collecting doctests. (accepted, cfg_doctest, "1.40.0", Some(62210), None), + /// Enables `#[cfg(panic = "...")]` config key. + (accepted, cfg_panic, "1.60.0", Some(77443), None), /// Allows `cfg(target_feature = "...")`. (accepted, cfg_target_feature, "1.27.0", Some(29717), None), /// Allows `cfg(target_has_atomic = "...")`. diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index fab22e4e6cf32..e14b9a0ad709f 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -303,8 +303,6 @@ declare_features! ( (active, c_variadic, "1.34.0", Some(44930), None), /// Allows capturing disjoint fields in a closure/generator (RFC 2229). (incomplete, capture_disjoint_fields, "1.49.0", Some(53488), None), - /// Enables `#[cfg(panic = "...")]` config key. - (active, cfg_panic, "1.49.0", Some(77443), None), /// Allows the use of `#[cfg(sanitize = "option")]`; set when -Zsanitizer is used. (active, cfg_sanitize, "1.41.0", Some(39699), None), /// Allows `cfg(target_abi = "...")`. diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index 69ce21d231f27..cbc8aa8463a32 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -33,7 +33,6 @@ 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. From 5e6be7df942e984d3d5388eb04d2a40d49fb8473 Mon Sep 17 00:00:00 2001 From: Charisee Date: Fri, 4 Feb 2022 17:14:58 +0000 Subject: [PATCH 2/7] replace feature expression (cfg_panic) in lib and remove expression from tests Rebase commit --- library/core/tests/lib.rs | 2 +- src/test/ui/cfg/cfg-panic-abort.rs | 2 +- src/test/ui/cfg/cfg-panic.rs | 2 +- src/test/ui/fmt/format-args-capture.rs | 1 - src/test/ui/issues/issue-68696-catch-during-unwind.rs | 1 - 5 files changed, 3 insertions(+), 5 deletions(-) diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 1c512471c95cb..d439a8d7de4f9 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -6,7 +6,7 @@ #![feature(bool_to_option)] #![feature(box_syntax)] #![feature(cell_update)] -#![feature(cfg_panic)] +#![cfg_attr(bootstrap,feature(cfg_panic))] #![cfg_attr(bootstrap, feature(cfg_target_has_atomic))] #![feature(const_assume)] #![feature(const_black_box)] diff --git a/src/test/ui/cfg/cfg-panic-abort.rs b/src/test/ui/cfg/cfg-panic-abort.rs index 9b88eff12ed38..3853b598a7a79 100644 --- a/src/test/ui/cfg/cfg-panic-abort.rs +++ b/src/test/ui/cfg/cfg-panic-abort.rs @@ -1,7 +1,7 @@ // build-pass // compile-flags: -C panic=abort // no-prefer-dynamic -#![feature(cfg_panic)] + #[cfg(panic = "unwind")] pub fn bad() -> i32 { } diff --git a/src/test/ui/cfg/cfg-panic.rs b/src/test/ui/cfg/cfg-panic.rs index d2113e4f5ecc6..fb3e5059c8199 100644 --- a/src/test/ui/cfg/cfg-panic.rs +++ b/src/test/ui/cfg/cfg-panic.rs @@ -4,7 +4,7 @@ // 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 { } diff --git a/src/test/ui/fmt/format-args-capture.rs b/src/test/ui/fmt/format-args-capture.rs index d31d2a6c33657..560352b5cb958 100644 --- a/src/test/ui/fmt/format-args-capture.rs +++ b/src/test/ui/fmt/format-args-capture.rs @@ -1,5 +1,4 @@ // run-pass -#![feature(cfg_panic)] fn main() { named_argument_takes_precedence_to_captured(); diff --git a/src/test/ui/issues/issue-68696-catch-during-unwind.rs b/src/test/ui/issues/issue-68696-catch-during-unwind.rs index f25a78f59cd20..2b12a62d0eb25 100644 --- a/src/test/ui/issues/issue-68696-catch-during-unwind.rs +++ b/src/test/ui/issues/issue-68696-catch-during-unwind.rs @@ -4,7 +4,6 @@ // entering the catch_unwind. // // run-pass -#![feature(cfg_panic)] use std::panic::catch_unwind; From 962094b449df39e22179846e551683f917981448 Mon Sep 17 00:00:00 2001 From: Charisee Date: Fri, 4 Feb 2022 18:34:10 +0000 Subject: [PATCH 3/7] Rebase --- .../feature-gates/feature-gate-cfg-panic.rs | 11 ---------- .../feature-gate-cfg-panic.stderr | 21 ------------------- 2 files changed, 32 deletions(-) delete mode 100644 src/test/ui/feature-gates/feature-gate-cfg-panic.rs delete mode 100644 src/test/ui/feature-gates/feature-gate-cfg-panic.stderr diff --git a/src/test/ui/feature-gates/feature-gate-cfg-panic.rs b/src/test/ui/feature-gates/feature-gate-cfg-panic.rs deleted file mode 100644 index 1508374d94266..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-cfg-panic.rs +++ /dev/null @@ -1,11 +0,0 @@ -#[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()); -} diff --git a/src/test/ui/feature-gates/feature-gate-cfg-panic.stderr b/src/test/ui/feature-gates/feature-gate-cfg-panic.stderr deleted file mode 100644 index ea5cd54fa90f0..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-cfg-panic.stderr +++ /dev/null @@ -1,21 +0,0 @@ -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 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 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`. From 46ec73ac3af3948af873e5157a5d807ff1a7ee73 Mon Sep 17 00:00:00 2001 From: Charisee Date: Fri, 4 Feb 2022 18:36:31 +0000 Subject: [PATCH 4/7] remove reference of cfg-panic from the unstable book --- .../src/language-features/cfg-panic.md | 38 ------------------- 1 file changed, 38 deletions(-) delete mode 100644 src/doc/unstable-book/src/language-features/cfg-panic.md diff --git a/src/doc/unstable-book/src/language-features/cfg-panic.md b/src/doc/unstable-book/src/language-features/cfg-panic.md deleted file mode 100644 index f5b73128ad6c2..0000000000000 --- a/src/doc/unstable-book/src/language-features/cfg-panic.md +++ /dev/null @@ -1,38 +0,0 @@ -# `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 { - // ... - } -} -``` From d018a8b6248a15e871c2220296c1fa639d6267c6 Mon Sep 17 00:00:00 2001 From: Charisee Date: Fri, 4 Feb 2022 19:55:55 +0000 Subject: [PATCH 5/7] remove mention of cfg_panic from library tests --- library/core/tests/array.rs | 3 --- library/core/tests/iter/adapters/zip.rs | 1 - library/core/tests/mem.rs | 2 -- 3 files changed, 6 deletions(-) diff --git a/library/core/tests/array.rs b/library/core/tests/array.rs index a778779c0fd88..ee8435e6d6c6f 100644 --- a/library/core/tests/array.rs +++ b/library/core/tests/array.rs @@ -392,7 +392,6 @@ fn array_try_from_fn() { assert_eq!(another_array, Err(SomeError::Foo)); } -#[cfg(not(panic = "abort"))] #[test] fn array_try_from_fn_drops_inserted_elements_on_err() { static DROP_COUNTER: AtomicUsize = AtomicUsize::new(0); @@ -416,7 +415,6 @@ fn array_try_from_fn_drops_inserted_elements_on_err() { assert_eq!(DROP_COUNTER.load(Ordering::SeqCst), 2); } -#[cfg(not(panic = "abort"))] #[test] fn array_try_from_fn_drops_inserted_elements_on_panic() { static DROP_COUNTER: AtomicUsize = AtomicUsize::new(0); @@ -440,7 +438,6 @@ fn array_try_from_fn_drops_inserted_elements_on_panic() { assert_eq!(DROP_COUNTER.load(Ordering::SeqCst), 2); } -#[cfg(not(panic = "abort"))] // https://stackoverflow.com/a/59211505 fn catch_unwind_silent(f: F) -> std::thread::Result where diff --git a/library/core/tests/iter/adapters/zip.rs b/library/core/tests/iter/adapters/zip.rs index 585cfbb90e40c..58563e2061ca3 100644 --- a/library/core/tests/iter/adapters/zip.rs +++ b/library/core/tests/iter/adapters/zip.rs @@ -233,7 +233,6 @@ fn test_zip_trusted_random_access_composition() { } #[test] -#[cfg(panic = "unwind")] fn test_zip_trusted_random_access_next_back_drop() { use std::panic::catch_unwind; use std::panic::AssertUnwindSafe; diff --git a/library/core/tests/mem.rs b/library/core/tests/mem.rs index 3b13dc0832fa4..f878017c97798 100644 --- a/library/core/tests/mem.rs +++ b/library/core/tests/mem.rs @@ -1,6 +1,5 @@ use core::mem::*; -#[cfg(panic = "unwind")] use std::rc::Rc; #[test] @@ -190,7 +189,6 @@ fn uninit_write_slice_cloned_panic_gt() { } #[test] -#[cfg(panic = "unwind")] fn uninit_write_slice_cloned_mid_panic() { use std::panic; From a889079b29ee8204ea4cf19842bc759e676a2937 Mon Sep 17 00:00:00 2001 From: Charisee Date: Fri, 4 Feb 2022 21:55:22 +0000 Subject: [PATCH 6/7] add cfg_panic bootstrap --- library/core/tests/array.rs | 3 +++ library/core/tests/iter/adapters/zip.rs | 1 + library/core/tests/mem.rs | 2 ++ 3 files changed, 6 insertions(+) diff --git a/library/core/tests/array.rs b/library/core/tests/array.rs index ee8435e6d6c6f..a778779c0fd88 100644 --- a/library/core/tests/array.rs +++ b/library/core/tests/array.rs @@ -392,6 +392,7 @@ fn array_try_from_fn() { assert_eq!(another_array, Err(SomeError::Foo)); } +#[cfg(not(panic = "abort"))] #[test] fn array_try_from_fn_drops_inserted_elements_on_err() { static DROP_COUNTER: AtomicUsize = AtomicUsize::new(0); @@ -415,6 +416,7 @@ fn array_try_from_fn_drops_inserted_elements_on_err() { assert_eq!(DROP_COUNTER.load(Ordering::SeqCst), 2); } +#[cfg(not(panic = "abort"))] #[test] fn array_try_from_fn_drops_inserted_elements_on_panic() { static DROP_COUNTER: AtomicUsize = AtomicUsize::new(0); @@ -438,6 +440,7 @@ fn array_try_from_fn_drops_inserted_elements_on_panic() { assert_eq!(DROP_COUNTER.load(Ordering::SeqCst), 2); } +#[cfg(not(panic = "abort"))] // https://stackoverflow.com/a/59211505 fn catch_unwind_silent(f: F) -> std::thread::Result where diff --git a/library/core/tests/iter/adapters/zip.rs b/library/core/tests/iter/adapters/zip.rs index 58563e2061ca3..585cfbb90e40c 100644 --- a/library/core/tests/iter/adapters/zip.rs +++ b/library/core/tests/iter/adapters/zip.rs @@ -233,6 +233,7 @@ fn test_zip_trusted_random_access_composition() { } #[test] +#[cfg(panic = "unwind")] fn test_zip_trusted_random_access_next_back_drop() { use std::panic::catch_unwind; use std::panic::AssertUnwindSafe; diff --git a/library/core/tests/mem.rs b/library/core/tests/mem.rs index f878017c97798..3b13dc0832fa4 100644 --- a/library/core/tests/mem.rs +++ b/library/core/tests/mem.rs @@ -1,5 +1,6 @@ use core::mem::*; +#[cfg(panic = "unwind")] use std::rc::Rc; #[test] @@ -189,6 +190,7 @@ fn uninit_write_slice_cloned_panic_gt() { } #[test] +#[cfg(panic = "unwind")] fn uninit_write_slice_cloned_mid_panic() { use std::panic; From dbeab9c532080a52f5cc86fbb4ca679581b866fd Mon Sep 17 00:00:00 2001 From: Charisee Date: Thu, 10 Feb 2022 22:30:51 +0000 Subject: [PATCH 7/7] added space --- library/core/tests/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index d439a8d7de4f9..cc628aa746346 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -6,7 +6,7 @@ #![feature(bool_to_option)] #![feature(box_syntax)] #![feature(cell_update)] -#![cfg_attr(bootstrap,feature(cfg_panic))] +#![cfg_attr(bootstrap, feature(cfg_panic))] #![cfg_attr(bootstrap, feature(cfg_target_has_atomic))] #![feature(const_assume)] #![feature(const_black_box)]