1
Fork 0

Rollup merge of #112260 - eval-exec:exec/fix-unsafe_code_lint, r=WaffleLapkin

Improve document of `unsafe_code` lint

This PR add another `unsafe_code` lint example, want to close #111967
This commit is contained in:
Guillaume Gomez 2023-06-09 16:29:01 +02:00 committed by GitHub
commit a7f46af369
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -286,7 +286,9 @@ impl<'tcx> LateLintPass<'tcx> for NonShorthandFieldPatterns {
} }
declare_lint! { 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 /// ### 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}} /// {{produces}}
/// ///
/// ### Explanation /// ### Explanation
/// ///
/// This lint is intended to restrict the usage of `unsafe`, which can be /// This lint is intended to restrict the usage of `unsafe` blocks and other
/// difficult to use correctly. /// constructs (including, but not limited to `no_mangle`, `link_section`
/// and `export_name` attributes) wrong usage of which causes undefined
/// behavior.
UNSAFE_CODE, UNSAFE_CODE,
Allow, Allow,
"usage of `unsafe` code" "usage of `unsafe` code and other potentially unsound constructs"
} }
declare_lint_pass!(UnsafeCode => [UNSAFE_CODE]); declare_lint_pass!(UnsafeCode => [UNSAFE_CODE]);