rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

Edition2024: __IncompleteArrayField fn as_slice(), fn as_mut_slice() WARNINGS

Open cameronelliott opened this issue 1 year ago • 0 comments

Sorry, I don't have reproduction steps, but I will point out the issue as precisely as I can.

This issue does NOT happen with package.edition=2021 This issue does happen with package.edition=2024 (nightly as of Feb 8, 2024)

Here is my rust compiler output, also below, I will provide permalinks to where the fixes are needed.

warning: call to unsafe function `std::slice::from_raw_parts` is unsafe and requires unsafe block (error E0133)
   --> /home/c/foofy/foofy-as-a-library/target/debug/build/foofy2-6ba5d4f1a518e0c9/out/bindings.rs:101:9
    |
101 |         ::std::slice::from_raw_parts(self.as_ptr(), len)
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
    |
    = note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
    = note: consult the function's documentation for information on how to avoid undefined behavior
note: an unsafe function restricts its caller, but its body is safe by default
   --> /home/c/foofy/foofy-as-a-library/target/debug/build/foofy2-6ba5d4f1a518e0c9/out/bindings.rs:100:5
    |
100 |     pub unsafe fn as_slice(&self, len: usize) -> &[T] {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: `#[warn(unsafe_op_in_unsafe_fn)]` on by default

warning: call to unsafe function `std::slice::from_raw_parts_mut` is unsafe and requires unsafe block (error E0133)
   --> /home/c/foofy/foofy-as-a-library/target/debug/build/foofy2-6ba5d4f1a518e0c9/out/bindings.rs:105:9
    |
105 |         ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len)
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
    |
    = note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
    = note: consult the function's documentation for information on how to avoid undefined behavior
note: an unsafe function restricts its caller, but its body is safe by default
   --> /home/c/foofy/foofy-as-a-library/target/debug/build/foofy2-6ba5d4f1a518e0c9/out/bindings.rs:104:5
    |
104 |     pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: `foofy2` (lib) generated 2 warnings (run `cargo fix --lib -p foofy2` to apply 2 suggestions)
    Finished dev [unoptimized + debuginfo] target(s) in 6.72s

HERE is the first place where the offending code is output: https://github.com/rust-lang/rust-bindgen/blob/8b1f971b2e1ccf09eee0bd8cc9bf8a37c15a4825/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs#L20

HERE is the second place where the offending code is output: https://github.com/rust-lang/rust-bindgen/blob/8b1f971b2e1ccf09eee0bd8cc9bf8a37c15a4825/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs#L24

cameronelliott avatar Feb 09 '24 01:02 cameronelliott