Skip to content

Commit 30f84c4

Browse files
committed
Improve document of unsafe_code lint
Signed-off-by: Eval EXEC <[email protected]>
1 parent 9c843d9 commit 30f84c4

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

Diff for: compiler/rustc_lint/src/builtin.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,9 @@ impl<'tcx> LateLintPass<'tcx> for NonShorthandFieldPatterns {
286286
}
287287

288288
declare_lint! {
289-
/// The `unsafe_code` lint catches usage of `unsafe` code.
289+
/// The `unsafe_code` lint catches usage of `unsafe` code and other
290+
/// potentially unsound constructs like `no_mangle`, `export_name`,
291+
/// and `link_section`.
290292
///
291293
/// ### Example
292294
///
@@ -297,17 +299,29 @@ declare_lint! {
297299
///
298300
/// }
299301
/// }
302+
///
303+
/// #[no_mangle]
304+
/// fn func_0() { }
305+
///
306+
/// #[export_name = "exported_symbol_name"]
307+
/// pub fn name_in_rust() { }
308+
///
309+
/// #[no_mangle]
310+
/// #[link_section = ".example_section"]
311+
/// pub static VAR1: u32 = 1;
300312
/// ```
301313
///
302314
/// {{produces}}
303315
///
304316
/// ### Explanation
305317
///
306-
/// This lint is intended to restrict the usage of `unsafe`, which can be
307-
/// difficult to use correctly.
318+
/// This lint is intended to restrict the usage of `unsafe` blocks and other
319+
/// constructs (including, but not limited to `no_mangle`, `link_section`
320+
/// and `export_name` attributes) wrong usage of which causes undefined
321+
/// behavior.
308322
UNSAFE_CODE,
309323
Allow,
310-
"usage of `unsafe` code"
324+
"usage of `unsafe` code and other potentially unsound constructs"
311325
}
312326

313327
declare_lint_pass!(UnsafeCode => [UNSAFE_CODE]);

0 commit comments

Comments
 (0)