Skip to content

Commit

Permalink
Merge #776
Browse files Browse the repository at this point in the history
776: Silence UB warnings caused by bindgen r=Bromeon a=Bromeon

Since the update to rustc 1.53, bindgen using UB causes warnings.
See rust-lang/rust-bindgen#1651 for detail.

Warnings all in the style of:
```
warning: dereferencing a null pointer
  --> ../godot-rust/target/<toolchain>/debug/build/gdnative-sys-7023d0a45a684438/out/bindings.rs:98:19
   |
98 |         unsafe { &(*(::std::ptr::null::<godot_string>()))._dont_touch_that as *const _ as usize },
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed
   |
   = note: `#[warn(deref_nullptr)]` on by default
```

Co-authored-by: Jan Haller <[email protected]>
  • Loading branch information
KarimHamidou and Bromeon authored Oct 4, 2023
2 parents 00bdb09 + 0e03734 commit 257a84b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions gdnative-bindings/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#![allow(non_snake_case)] // because of the generated bindings.
// For silenced lints/warnings, see also gdnative-sys/src/lib.rs

// Generated bindings don't follow some conventions
#![allow(non_snake_case)]
#![allow(unused_unsafe)]
// False positives on generated drops that enforce lifetime
#![allow(clippy::drop_copy)]
// Disable non-critical lints for generated code.
// Disable non-critical lints for generated code
#![allow(clippy::style, clippy::complexity, clippy::perf)]

mod generated;
Expand Down
6 changes: 6 additions & 0 deletions gdnative-sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
// For silenced lints/warnings, see also gdnative-bindings/src/lib.rs

// Notes:
// * deref_nullptr: since rustc 1.53, bindgen causes UB warnings -- see https://github.com/rust-lang/rust-bindgen/issues/1651
// remove this once bindgen has fixed the issue (currently at version 1.59.1)
#![allow(
non_upper_case_globals,
non_camel_case_types,
non_snake_case,
improper_ctypes,
deref_nullptr,
clippy::style
)]
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
Expand Down

0 comments on commit 257a84b

Please sign in to comment.