summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/not_unsafe_ptr_arg_deref.txt
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:03:36 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:03:36 +0000
commit17d40c6057c88f4c432b0d7bac88e1b84cb7e67f (patch)
tree3f66c4a5918660bb8a758ab6cda5ff8ee4f6cdcd /src/tools/clippy/src/docs/not_unsafe_ptr_arg_deref.txt
parentAdding upstream version 1.64.0+dfsg1. (diff)
downloadrustc-17d40c6057c88f4c432b0d7bac88e1b84cb7e67f.tar.xz
rustc-17d40c6057c88f4c432b0d7bac88e1b84cb7e67f.zip
Adding upstream version 1.65.0+dfsg1.upstream/1.65.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/src/docs/not_unsafe_ptr_arg_deref.txt')
-rw-r--r--src/tools/clippy/src/docs/not_unsafe_ptr_arg_deref.txt30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/tools/clippy/src/docs/not_unsafe_ptr_arg_deref.txt b/src/tools/clippy/src/docs/not_unsafe_ptr_arg_deref.txt
new file mode 100644
index 000000000..31355fbb7
--- /dev/null
+++ b/src/tools/clippy/src/docs/not_unsafe_ptr_arg_deref.txt
@@ -0,0 +1,30 @@
+### What it does
+Checks for public functions that dereference raw pointer
+arguments but are not marked `unsafe`.
+
+### Why is this bad?
+The function should probably be marked `unsafe`, since
+for an arbitrary raw pointer, there is no way of telling for sure if it is
+valid.
+
+### Known problems
+* It does not check functions recursively so if the pointer is passed to a
+private non-`unsafe` function which does the dereferencing, the lint won't
+trigger.
+* It only checks for arguments whose type are raw pointers, not raw pointers
+got from an argument in some other way (`fn foo(bar: &[*const u8])` or
+`some_argument.get_raw_ptr()`).
+
+### Example
+```
+pub fn foo(x: *const u8) {
+ println!("{}", unsafe { *x });
+}
+```
+
+Use instead:
+```
+pub unsafe fn foo(x: *const u8) {
+ println!("{}", unsafe { *x });
+}
+``` \ No newline at end of file