summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.rs')
-rw-r--r--src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.rs b/src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.rs
new file mode 100644
index 000000000..c1b316765
--- /dev/null
+++ b/src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.rs
@@ -0,0 +1,24 @@
+// run-rustfix
+#![warn(clippy::cast_slice_from_raw_parts)]
+
+#[allow(unused_imports, unused_unsafe)]
+fn main() {
+ let mut vec = vec![0u8; 1];
+ let ptr: *const u8 = vec.as_ptr();
+ let mptr = vec.as_mut_ptr();
+ let _: *const [u8] = unsafe { std::slice::from_raw_parts(ptr, 1) as *const [u8] };
+ let _: *const [u8] = unsafe { std::slice::from_raw_parts_mut(mptr, 1) as *mut [u8] };
+ let _: *const [u8] = unsafe { std::slice::from_raw_parts(ptr, 1) } as *const [u8];
+ {
+ use core::slice;
+ let _: *const [u8] = unsafe { slice::from_raw_parts(ptr, 1) } as *const [u8];
+ use slice as one;
+ let _: *const [u8] = unsafe { one::from_raw_parts(ptr, 1) } as *const [u8];
+ }
+ {
+ use std::slice;
+ let _: *const [u8] = unsafe { slice::from_raw_parts(ptr, 1) } as *const [u8];
+ use slice as one;
+ let _: *const [u8] = unsafe { one::from_raw_parts(ptr, 1) } as *const [u8];
+ }
+}