rust/library/alloc/src
Yuki Okushi c46f948a80
Rollup merge of #79208 - LeSeulArtichaut:stable-unsafe_op_in_unsafe_fn, r=nikomatsakis
Stabilize `unsafe_op_in_unsafe_fn` lint

This makes it possible to override the level of the `unsafe_op_in_unsafe_fn`, as proposed in https://github.com/rust-lang/rust/issues/71668#issuecomment-729770896.

Tracking issue: #71668
r? ```@nikomatsakis``` cc ```@SimonSapin``` ```@RalfJung```

# Stabilization report

This is a stabilization report for `#![feature(unsafe_block_in_unsafe_fn)]`.

## Summary

Currently, the body of unsafe functions is an unsafe block, i.e. you can perform unsafe operations inside.

The `unsafe_op_in_unsafe_fn` lint, stabilized here, can be used to change this behavior, so performing unsafe operations in unsafe functions requires an unsafe block.

For now, the lint is allow-by-default, which means that this PR does not change anything without overriding the lint level.

For more information, see [RFC 2585](https://github.com/rust-lang/rfcs/blob/master/text/2585-unsafe-block-in-unsafe-fn.md)

### Example

```rust
// An `unsafe fn` for demonstration purposes.
// Calling this is an unsafe operation.
unsafe fn unsf() {}

// #[allow(unsafe_op_in_unsafe_fn)] by default,
// the behavior of `unsafe fn` is unchanged
unsafe fn allowed() {
    // Here, no `unsafe` block is needed to
    // perform unsafe operations...
    unsf();

    // ...and any `unsafe` block is considered
    // unused and is warned on by the compiler.
    unsafe {
        unsf();
    }
}

#[warn(unsafe_op_in_unsafe_fn)]
unsafe fn warned() {
    // Removing this `unsafe` block will
    // cause the compiler to emit a warning.
    // (Also, no "unused unsafe" warning will be emitted here.)
    unsafe {
        unsf();
    }
}

#[deny(unsafe_op_in_unsafe_fn)]
unsafe fn denied() {
    // Removing this `unsafe` block will
    // cause a compilation error.
    // (Also, no "unused unsafe" warning will be emitted here.)
    unsafe {
        unsf();
    }
}
```
2021-03-10 08:01:25 +09:00
..
alloc Rename AllocRef to Allocator and (de)alloc to (de)allocate 2020-12-04 14:47:15 +01:00
collections Rollup merge of #81127 - hanmertens:binary_heap_sift_down_perf, r=dtolnay 2021-03-09 09:05:18 +00: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 Rollup merge of #82564 - WaffleLapkin:revert_spare_mut, r=RalfJung 2021-03-04 20:01:06 +09:00
alloc.rs move WriteCloneIntoRaw into alloc::alloc 2021-01-12 12:24:28 -08:00
borrow.rs a few more diagnostic items 2021-02-16 02:32:21 +00:00
boxed.rs Remove unnecessary lint allow attrs on example 2021-02-12 12:46:02 +03:00
fmt.rs Improve grammar in documentation of format strings 2021-01-01 23:07:35 +01:00
lib.rs Rollup merge of #79208 - LeSeulArtichaut:stable-unsafe_op_in_unsafe_fn, r=nikomatsakis 2021-03-10 08:01:25 +09:00
macros.rs Only define rustc_diagnostic_item format_macro in not(test). 2021-02-14 20:03:13 +01:00
raw_vec.rs Auto merge of #79113 - andjo403:raw_vec_ptr, r=m-ou-se 2021-01-26 02:56:37 +00:00
rc.rs Add docs for shared_from_slice From impls 2021-02-12 14:02:23 -07:00
slice.rs Convert primitives to use intra-doc links 2021-02-25 20:31:53 -05:00
str.rs Convert primitives to use intra-doc links 2021-02-25 20:31:53 -05:00
string.rs Add documentation for string->Cow conversions 2021-03-07 20:36:43 -07:00
sync.rs Add docs for shared_from_slice From impls 2021-02-12 14:02:23 -07:00
task.rs Update the bootstrap compiler 2021-02-20 17:19:30 -05:00
tests.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00