rust/compiler
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
..
rustc Rollup merge of #82642 - sfackler:jemalloc-zone, r=pnkfelix 2021-03-08 13:13:22 +01:00
rustc_apfloat
rustc_arena Update the bootstrap compiler 2021-02-20 17:19:30 -05:00
rustc_ast Rollup merge of #82841 - hvdijk:x32, r=joshtriplett 2021-03-09 09:05:24 +00:00
rustc_ast_lowering Rollup merge of #82854 - estebank:issue-82827, r=oli-obk 2021-03-08 20:09:02 +01:00
rustc_ast_passes Add help for matches for if let in arm guard 2021-03-07 14:44:21 -08:00
rustc_ast_pretty Rollup merge of #82238 - petrochenkov:nocratemod, r=Aaron1011 2021-02-19 02:49:08 +01:00
rustc_attr Auto merge of #71481 - estebank:inherit-stability, r=nikomatsakis 2021-03-05 05:28:07 +00:00
rustc_builtin_macros Rollup merge of #82682 - petrochenkov:cfgeval, r=Aaron1011 2021-03-08 13:13:23 +01:00
rustc_codegen_cranelift Clean up todos 2021-03-09 19:31:31 +00:00
rustc_codegen_llvm Auto merge of #82285 - nhwn:nonzero-debug, r=nagisa 2021-03-07 20:23:23 +00:00
rustc_codegen_ssa Switch to changing cp_non_overlap in tform 2021-03-09 16:54:14 +00:00
rustc_data_structures Auto merge of #81635 - michaelwoerister:structured_def_path_hash, r=pnkfelix 2021-03-07 23:45:57 +00:00
rustc_driver Auto merge of #82304 - LeSeulArtichaut:unpretty-ast, r=spastorino 2021-03-04 05:46:43 +00:00
rustc_error_codes Rollup merge of #80527 - jyn514:rustdoc-lints, r=GuillaumeGomez 2021-03-04 20:01:01 +09:00
rustc_errors Change x64 size checks to not apply to x32. 2021-03-06 16:02:48 +00:00
rustc_expand Rollup merge of #82682 - petrochenkov:cfgeval, r=Aaron1011 2021-03-08 13:13:23 +01:00
rustc_feature Rollup merge of #79208 - LeSeulArtichaut:stable-unsafe_op_in_unsafe_fn, r=nikomatsakis 2021-03-10 08:01:25 +09:00
rustc_fs_util
rustc_graphviz
rustc_hir Rollup merge of #82841 - hvdijk:x32, r=joshtriplett 2021-03-09 09:05:24 +00:00
rustc_hir_pretty
rustc_incremental Print -Ztime-passes (and misc stats/logs) on stderr, not stdout. 2021-02-18 14:13:38 +02:00
rustc_index Miscellaneous inlining improvements 2021-02-26 00:00:00 +00:00
rustc_infer Change x64 size checks to not apply to x32. 2021-03-06 16:02:48 +00:00
rustc_interface Rollup merge of #82415 - petrochenkov:modin3, r=davidtwco 2021-03-08 13:13:19 +01:00
rustc_lexer
rustc_lint Rollup merge of #82048 - mark-i-m:or-pat-type-ascription, r=petrochenkov 2021-03-09 09:05:20 +00:00
rustc_lint_defs Rollup merge of #79208 - LeSeulArtichaut:stable-unsafe_op_in_unsafe_fn, r=nikomatsakis 2021-03-10 08:01:25 +09:00
rustc_llvm Schedule ThinLTOBuffer passes again after sanitizer passes 2021-03-03 20:48:37 +01:00
rustc_macros replaced some map_or with map_or_else 2021-02-24 02:43:35 +03:00
rustc_metadata Auto merge of #81635 - michaelwoerister:structured_def_path_hash, r=pnkfelix 2021-03-07 23:45:57 +00:00
rustc_middle Rollup merge of #79208 - LeSeulArtichaut:stable-unsafe_op_in_unsafe_fn, r=nikomatsakis 2021-03-10 08:01:25 +09:00
rustc_mir Rollup merge of #79208 - LeSeulArtichaut:stable-unsafe_op_in_unsafe_fn, r=nikomatsakis 2021-03-10 08:01:25 +09:00
rustc_mir_build Rollup merge of #82841 - hvdijk:x32, r=joshtriplett 2021-03-09 09:05:24 +00:00
rustc_parse Rollup merge of #82048 - mark-i-m:or-pat-type-ascription, r=petrochenkov 2021-03-09 09:05:20 +00:00
rustc_parse_format
rustc_passes Rollup merge of #82651 - jyn514:rustdoc-warnings, r=GuillaumeGomez 2021-03-07 10:41:13 +09:00
rustc_plugin_impl
rustc_privacy Rollup merge of #82066 - matthewjasper:trait-ref-fix, r=jackh726 2021-02-18 16:57:34 +01:00
rustc_query_impl Simplify hashing. 2021-02-21 12:22:22 +01:00
rustc_query_system Simplify hashing. 2021-02-21 12:22:22 +01:00
rustc_resolve diagnostics: Don't mention external crates when hitting import errors on crate imports in 2018 2021-03-07 15:15:19 -08:00
rustc_save_analysis
rustc_serialize Update the bootstrap compiler 2021-02-20 17:19:30 -05:00
rustc_session Rollup merge of #82415 - petrochenkov:modin3, r=davidtwco 2021-03-08 13:13:19 +01:00
rustc_span Rollup merge of #82682 - petrochenkov:cfgeval, r=Aaron1011 2021-03-08 13:13:23 +01:00
rustc_symbol_mangling
rustc_target Rollup merge of #77916 - QuiltOS:kernel-code-targets-os-none, r=joshtriplett 2021-03-07 10:41:04 +09:00
rustc_trait_selection Rollup merge of #82841 - hvdijk:x32, r=joshtriplett 2021-03-09 09:05:24 +00:00
rustc_traits Fix tests 2021-03-03 11:22:44 +01:00
rustc_ty_utils Auto merge of #82159 - BoxyUwU:uwu, r=varkor 2021-02-24 21:54:52 +00:00
rustc_type_ir New pass to deduplicate blocks 2021-02-21 21:51:54 +01:00
rustc_typeck Rollup merge of #82755 - osa1:confirm_builtin_call_refactor, r=petrochenkov 2021-03-08 13:13:25 +01:00