Skip to content

Commit 0e03734

Browse files
KarimHamidouBromeon
authored andcommitted
Silence UB warnings caused by bindgen
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 ---------------------------------------------------------------------
1 parent 00bdb09 commit 0e03734

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

gdnative-bindings/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
#![allow(non_snake_case)] // because of the generated bindings.
1+
// For silenced lints/warnings, see also gdnative-sys/src/lib.rs
2+
3+
// Generated bindings don't follow some conventions
4+
#![allow(non_snake_case)]
25
#![allow(unused_unsafe)]
36
// False positives on generated drops that enforce lifetime
47
#![allow(clippy::drop_copy)]
5-
// Disable non-critical lints for generated code.
8+
// Disable non-critical lints for generated code
69
#![allow(clippy::style, clippy::complexity, clippy::perf)]
710

811
mod generated;

gdnative-sys/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
// For silenced lints/warnings, see also gdnative-bindings/src/lib.rs
2+
3+
// Notes:
4+
// * deref_nullptr: since rustc 1.53, bindgen causes UB warnings -- see https://github.com/rust-lang/rust-bindgen/issues/1651
5+
// remove this once bindgen has fixed the issue (currently at version 1.59.1)
16
#![allow(
27
non_upper_case_globals,
38
non_camel_case_types,
49
non_snake_case,
510
improper_ctypes,
11+
deref_nullptr,
612
clippy::style
713
)]
814
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

0 commit comments

Comments
 (0)