diff options
| author | Eval EXEC <execvy@gmail.com> | 2023-06-09 16:11:23 +0800 |
|---|---|---|
| committer | Eval EXEC <execvy@gmail.com> | 2023-06-09 20:41:18 +0800 |
| commit | 30f84c4d1755de683e565a03f269878796f71bdf (patch) | |
| tree | 814652feb18647e5b45796db1e83da5a1faba5b6 /compiler/rustc_lint/src | |
| parent | 9c843d9fa322596c7d525c78fa89731ecf7afbfe (diff) | |
| download | rust-30f84c4d1755de683e565a03f269878796f71bdf.tar.gz rust-30f84c4d1755de683e565a03f269878796f71bdf.zip | |
Improve document of `unsafe_code` lint
Signed-off-by: Eval EXEC <execvy@gmail.com>
Diffstat (limited to 'compiler/rustc_lint/src')
| -rw-r--r-- | compiler/rustc_lint/src/builtin.rs | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 8c0956a618d..ff2989112af 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -286,7 +286,9 @@ impl<'tcx> LateLintPass<'tcx> for NonShorthandFieldPatterns { } declare_lint! { - /// The `unsafe_code` lint catches usage of `unsafe` code. + /// The `unsafe_code` lint catches usage of `unsafe` code and other + /// potentially unsound constructs like `no_mangle`, `export_name`, + /// and `link_section`. /// /// ### Example /// @@ -297,17 +299,29 @@ declare_lint! { /// /// } /// } + /// + /// #[no_mangle] + /// fn func_0() { } + /// + /// #[export_name = "exported_symbol_name"] + /// pub fn name_in_rust() { } + /// + /// #[no_mangle] + /// #[link_section = ".example_section"] + /// pub static VAR1: u32 = 1; /// ``` /// /// {{produces}} /// /// ### Explanation /// - /// This lint is intended to restrict the usage of `unsafe`, which can be - /// difficult to use correctly. + /// This lint is intended to restrict the usage of `unsafe` blocks and other + /// constructs (including, but not limited to `no_mangle`, `link_section` + /// and `export_name` attributes) wrong usage of which causes undefined + /// behavior. UNSAFE_CODE, Allow, - "usage of `unsafe` code" + "usage of `unsafe` code and other potentially unsound constructs" } declare_lint_pass!(UnsafeCode => [UNSAFE_CODE]); |
