rust/compiler/rustc_middle/src/mir
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
..
interpret Change x64 size checks to not apply to x32. 2021-03-06 16:02:48 +00:00
abstract_const.rs support const_evaluatable_checked across crate boundaries 2020-09-18 17:11:34 +02:00
coverage.rs New pass to deduplicate blocks 2021-02-21 21:51:54 +01:00
graph_cyclic_cache.rs Cache result of 2020-12-20 10:29:26 +01:00
mod.rs Switch to changing cp_non_overlap in tform 2021-03-09 16:54:14 +00:00
mono.rs Only store a LocalDefId in hir::Item. 2021-02-15 19:32:10 +01:00
predecessors.rs words 2020-11-16 22:42:09 +01:00
query.rs Rollup merge of #79208 - LeSeulArtichaut:stable-unsafe_op_in_unsafe_fn, r=nikomatsakis 2021-03-10 08:01:25 +09:00
tcx.rs Rollup merge of #82841 - hvdijk:x32, r=joshtriplett 2021-03-09 09:05:24 +00:00
terminator.rs New mir-opt pass to simplify gotos with const values 2021-02-22 21:03:57 +01:00
traversal.rs mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
type_foldable.rs Shrink the size of Rvalue by 16 bytes 2021-03-05 09:33:01 +00:00
visit.rs Update cranelift 2021-03-09 16:54:14 +00:00