rust/compiler/rustc_middle/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
..
dep_graph Access the session directly from DepContext. 2021-02-20 22:53:46 +01:00
hir Auto merge of #81611 - cjgillot:meowner, r=estebank 2021-02-16 22:14:32 +00:00
ich Only store a LocalDefId in hir::Item. 2021-02-15 19:32:10 +01:00
infer Move a few more types to rustc_type_ir 2021-01-18 21:06:12 +01:00
middle Enforce that query results implement Debug 2021-01-16 17:53:02 -05:00
mir Rollup merge of #79208 - LeSeulArtichaut:stable-unsafe_op_in_unsafe_fn, r=nikomatsakis 2021-03-10 08:01:25 +09:00
query Rollup merge of #82510 - jyn514:fix-typo, r=Dylan-DPC 2021-02-25 16:06:26 -05:00
traits Change x64 size checks to not apply to x32. 2021-03-06 16:02:48 +00:00
ty Change x64 size checks to not apply to x32. 2021-03-06 16:02:48 +00:00
util Make panic/assert calls in rustc compatible with Rust 2021. 2021-02-03 22:42:53 +01:00
arena.rs Combination of commits 2020-12-03 09:50:10 -08:00
lib.rs Split DepKindStruct in two. 2021-02-19 17:51:56 +01:00
lint.rs Rollup merge of #81713 - estebank:unstable-assoc-item-lint, r=oli-obk 2021-02-25 14:33:53 +01:00
macros.rs Auto merge of #78779 - LeSeulArtichaut:ty-visitor-return, r=oli-obk 2020-11-17 12:24:34 +00:00
tests.rs mv compiler to compiler/ 2020-08-30 18:45:07 +03:00