rust/library/alloc/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 Rename AllocRef to Allocator and (de)alloc to (de)allocate 2020-12-04 14:47:15 +01:00
collections Rollup merge of #87574 - cuviper:retain-examples, r=joshtriplett 2021-07-30 16:26:57 +09:00
prelude mv std libs to library/ 2020-07-27 19:51:13 -05:00
raw_vec Rename AllocRef to Allocator and (de)alloc to (de)allocate 2020-12-04 14:47:15 +01:00
rc Re-stabilize Weak::as_ptr &friends for unsized T 2021-01-06 19:30:22 -05:00
sync Rollup merge of #80764 - CAD97:weak-unsized-as-ptr-again, r=RalfJung 2021-01-16 17:29:56 +00:00
vec Auto merge of #87488 - kornelski:track-remove, r=dtolnay 2021-07-31 03:00:20 +00:00
alloc.rs alloc: Add unstable Cfg feature no-global_oom_handling 2021-05-05 16:49:04 -04:00
borrow.rs Added diagnostic items to structs and traits for Clippy 2021-07-15 23:57:02 +02:00
boxed.rs Remove alloc/malloc/calloc/realloc doc aliases 2021-06-30 19:59:39 +01:00
fmt.rs Fix may not to appropriate might not or must not 2021-07-29 01:15:20 -04:00
lib.rs Relocate Arc and Rc UnwindSafe impls 2021-07-31 03:57:49 -07:00
macros.rs Remove alloc/malloc/calloc/realloc doc aliases 2021-06-30 19:59:39 +01:00
raw_vec.rs alloc: RawVec<T, A>::shrink can be in no_global_oom_handling. 2021-06-30 19:42:41 +02:00
rc.rs Relocate Arc and Rc UnwindSafe impls 2021-07-31 03:57:49 -07:00
slice.rs Use HTTPS links where possible 2021-06-23 16:26:46 -04:00
str.rs Use HTTPS links where possible 2021-06-23 16:26:46 -04:00
string.rs Rollup merge of #87574 - cuviper:retain-examples, r=joshtriplett 2021-07-30 16:26:57 +09:00
sync.rs Relocate Arc and Rc UnwindSafe impls 2021-07-31 03:57:49 -07:00
task.rs Document From implementations for Waker and RawWaker 2021-04-22 14:16:33 -07:00
tests.rs Fix alloc::test::test_show 2021-04-21 15:45:41 +02:00