]> git.lizzy.rs Git - rust.git/blob - src/docs/not_unsafe_ptr_arg_deref.txt
Auto merge of #9421 - xphoniex:fix-#9420, r=giraffate
[rust.git] / src / docs / not_unsafe_ptr_arg_deref.txt
1 ### What it does
2 Checks for public functions that dereference raw pointer
3 arguments but are not marked `unsafe`.
4
5 ### Why is this bad?
6 The function should probably be marked `unsafe`, since
7 for an arbitrary raw pointer, there is no way of telling for sure if it is
8 valid.
9
10 ### Known problems
11 * It does not check functions recursively so if the pointer is passed to a
12 private non-`unsafe` function which does the dereferencing, the lint won't
13 trigger.
14 * It only checks for arguments whose type are raw pointers, not raw pointers
15 got from an argument in some other way (`fn foo(bar: &[*const u8])` or
16 `some_argument.get_raw_ptr()`).
17
18 ### Example
19 ```
20 pub fn foo(x: *const u8) {
21     println!("{}", unsafe { *x });
22 }
23 ```
24
25 Use instead:
26 ```
27 pub unsafe fn foo(x: *const u8) {
28     println!("{}", unsafe { *x });
29 }
30 ```