rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.04k stars 12.54k forks source link

libc::posix_memalign, libc::pwrite and pread are not considered unsafe operation during library build #128582

Open biabbas opened 1 month ago

biabbas commented 1 month ago

To resolve build errors, ununused_unsafe is allowed for target VxWorks. We use libc::pread as pread64 which is declared as unsafe in libc for VxWorks https://github.com/rust-lang/rust/blob/master/library/std/src/sys/pal/unix/fd.rs#L129 We use libc::pwrite as pwrite64 which is also an unsafe fn https://github.com/rust-lang/rust/blob/master/library/std/src/sys/pal/unix/fd.rs#L323

Error

error: unnecessary `unsafe` block
  --> std/src/sys/alloc/unix.rs:84:23
   |
84 |             let ret = unsafe { libc::posix_memalign(&mut out, align, layout.size()) };
   |                       ^^^^^^ unnecessary `unsafe` block

error: unnecessary `unsafe` block
   --> library/std/src/sys/pal/unix/fd.rs:137:9
    |
137 |         unsafe {
    |         ^^^^^^ unnecessary `unsafe` block
    |
    = note: `-D unused-unsafe` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(unused_unsafe)]`

error: unnecessary `unsafe` block
   --> library/std/src/sys/pal/unix/fd.rs:330:9
    |
330 |         unsafe {
    |         ^^^^^^ unnecessary `unsafe` block
biabbas commented 3 days ago

https://github.com/rust-lang/libc/pull/3727 Getting this into a libc release would probably solve this.