rust/library/core/src
bors f381e77d35 Auto merge of #84662 - dtolnay:unwindsafe, r=Amanieu
Move UnwindSafe, RefUnwindSafe, AssertUnwindSafe to core

They were previously only available in std::panic, not core::panic.

- https://doc.rust-lang.org/1.51.0/std/panic/trait.UnwindSafe.html
- https://doc.rust-lang.org/1.51.0/std/panic/trait.RefUnwindSafe.html
- https://doc.rust-lang.org/1.51.0/std/panic/struct.AssertUnwindSafe.html

Where this is relevant: trait objects! Inside a `#![no_std]` library it's otherwise impossible to have a struct holding a trait object, and at the same time can be used from downstream std crates in a way that doesn't interfere with catch_unwind.

```rust
// common library

#![no_std]

pub struct Thing {
    pub(crate) x: &'static (dyn SomeTrait + Send + Sync),
}

pub(crate) trait SomeTrait {...}
```

```rust
// downstream application

fn main() {
    let thing: library::Thing = ...;
    let _ = std::panic::catch_unwind(|| { let _ = thing; });  // does not work :(
}
```

See a4131708e2/src/gradient.rs (L7-L15) for a real life example of needing to work around this problem. In particular that workaround would not even be viable if implementors of the trait were provided externally by a caller, as the `feature = "std"` would become non-additive in that case.

What happens without the UnwindSafe constraints:

```rust
fn main() {
    let gradient = colorous::VIRIDIS;
    let _ = std::panic::catch_unwind(|| { let _ = gradient; });
}
```

```console
error[E0277]: the type `(dyn colorous::gradient::EvalGradient + Send + Sync + 'static)` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary
   --> src/main.rs:3:13
    |
3   |     let _ = std::panic::catch_unwind(|| { let _ = gradient; });
    |             ^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn colorous::gradient::EvalGradient + Send + Sync + 'static)` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary
    |
   ::: .rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:430:40
    |
430 | pub fn catch_unwind<F: FnOnce() -> R + UnwindSafe, R>(f: F) -> Result<R> {
    |                                        ---------- required by this bound in `catch_unwind`
    |
    = help: within `Gradient`, the trait `RefUnwindSafe` is not implemented for `(dyn colorous::gradient::EvalGradient + Send + Sync + 'static)`
    = note: required because it appears within the type `&'static (dyn colorous::gradient::EvalGradient + Send + Sync + 'static)`
    = note: required because it appears within the type `Gradient`
    = note: required because of the requirements on the impl of `UnwindSafe` for `&Gradient`
    = note: required because it appears within the type `[closure@src/main.rs:3:38: 3:62]`
```
2021-08-01 02:53:13 +00:00
..
alloc Fix may not to appropriate might not or must not 2021-07-29 01:15:20 -04:00
array Add docs about performance and Iterator::map to [T; N]::map 2021-07-30 00:08:48 +02:00
char Add missing links for core::char types 2021-07-29 14:13:41 +02:00
convert Added diagnostic items to structs and traits for Clippy 2021-07-15 23:57:02 +02:00
fmt Rollup merge of #87052 - phlopsi:patch-1, r=jyn514 2021-07-30 16:26:52 +09:00
future Fix may not to appropriate might not or must not 2021-07-29 01:15:20 -04:00
hash Add tracking issue and rename to hash_one 2021-06-24 01:30:48 -07:00
iter Fix may not to appropriate might not or must not 2021-07-29 01:16:53 -04:00
macros Extend documentation of const_format_args!(). 2021-07-28 16:18:38 +02:00
mem Auto merge of #87445 - amalik18:issue-83584-fix, r=kennytm 2021-07-30 04:34:13 +00:00
num Rollup merge of #87522 - frogtd:patch-1, r=yaahc 2021-07-30 16:26:53 +09:00
ops Fix may not to appropriate might not or must not 2021-07-29 01:15:20 -04:00
panic Fix unused sync::atomic import on targets without atomics 2021-07-31 17:27:29 -07:00
prelude Move asm! and global_asm! to core::arch 2021-07-18 18:30:58 -04:00
ptr Rollup merge of #87547 - GuillaumeGomez:nonnull-examples, r=kennytm 2021-07-31 04:09:26 +09:00
slice Auto merge of #87387 - the8472:slice-iter-advance_by, r=scottmcm 2021-07-31 05:22:13 +00:00
str Fix may not to appropriate might not or must not 2021-07-29 01:15:20 -04:00
stream Remove Stream::next 2021-01-23 16:54:56 +01:00
sync Fix may not to appropriate might not or must not 2021-07-29 01:15:20 -04:00
task Update stable version of ready!() macro. 2021-07-28 16:56:12 +02:00
unicode Use HTTPS links where possible 2021-06-23 16:26:46 -04:00
any.rs Added diagnostic items to structs and traits for Clippy 2021-07-15 23:57:02 +02:00
ascii.rs Replace all fmt.pad with debug_struct 2021-04-21 14:38:24 +02:00
bool.rs Fix tracking issue for bool_to_option 2021-07-10 18:43:52 -04:00
borrow.rs Fix borrow and deref 2021-03-03 11:23:29 +01:00
cell.rs fix typo: whenver -> whenever 2021-07-26 22:12:35 +01:00
clone.rs Updates Clone docs for Copy comparison. 2021-06-10 11:28:26 -04:00
cmp.rs Added diagnostic items to functions for Clippy 2021-07-15 23:47:03 +02:00
default.rs Permit deriving default on enums with #[default] 2021-07-27 15:47:47 -04:00
ffi.rs Replace all fmt.pad with debug_struct 2021-04-21 14:38:24 +02:00
hint.rs Auto merge of #84725 - sebpop:arm64-isb, r=joshtriplett 2021-05-02 04:54:31 +00:00
internal_macros.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
intrinsics.rs Stabilize const_fn_transmute 2021-07-27 16:03:09 -04:00
lazy.rs Capitalize safety comments 2020-09-08 22:26:44 -04:00
lib.rs Auto merge of #86998 - m-ou-se:const-panic-fmt-as-str, r=oli-obk 2021-07-29 07:12:07 +00:00
marker.rs Rename variable 2021-06-29 20:26:37 -04:00
option.rs Auto merge of #87196 - oxalica:option-insert-must-use, r=joshtriplett 2021-07-19 07:03:36 +00:00
panic.rs Move UnwindSafe, RefUnwindSafe, AssertUnwindSafe to core 2021-07-30 10:42:15 -07:00
panicking.rs Improve comments about const panic handling 2021-07-28 16:18:38 +02:00
pin.rs Fix may not to appropriate might not or must not 2021-07-29 01:15:20 -04:00
primitive.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
result.rs Auto merge of #86211 - tlyu:option-result-overviews, r=joshtriplett 2021-07-14 05:10:57 +00:00
time.rs Added diagnostic items to structs and traits for Clippy 2021-07-15 23:57:02 +02:00
tuple.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
unit.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00