Skip to content

Fix/suppress clippy lints on nightly #822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gdnative-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#![allow(unused_unsafe)]
// False positives on generated drops that enforce lifetime
#![allow(clippy::drop_copy)]
// False positives on thread-safe singletons
#![allow(clippy::non_send_fields_in_send_ty)]
// Disable non-critical lints for generated code
#![allow(clippy::style, clippy::complexity, clippy::perf)]

Expand Down
5 changes: 1 addition & 4 deletions gdnative-core/src/core_types/transform2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,7 @@ fn test_transform2d_behavior_impl() {
let rotation_rust = new_transform_rust.rotation();
let rotation_godot = unsafe { (api.godot_transform2d_get_rotation)(new_transform_rust.sys()) };

assert!(
(rotation_rust - rotation_godot) < f32::EPSILON,
"Rotation getters should return equal results"
);
approx::assert_relative_eq!(rotation_rust, rotation_godot);

let scale_rust = new_transform_rust.scale();
let scale_godot =
Expand Down
2 changes: 1 addition & 1 deletion gdnative-core/src/core_types/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ impl Default for Variant {
impl fmt::Debug for Variant {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(f, "{:?}({})", self.get_type(), self.to_string())
write!(f, "{:?}({})", self.get_type(), self)
}
}

Expand Down
29 changes: 23 additions & 6 deletions gdnative-core/src/export/user_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,16 @@ impl<T> Clone for ArcData<T> {
}

/// User-data wrapper analogous to a `Arc<RefCell<T>>`, that is restricted to the thread
/// where it was originally created.
/// where it was originally created. The destructor of `T` is not guaranteed to be run if
/// this is actually shared across multiple threads.
///
/// This works by checking `ThreadId` before touching the underlying reference. If the id
/// doesn't match the original thread, `map` and `map_mut` will return an error.
///
/// Since it isn't possible to control where the last reference is dropped, the destructor
/// isn't run if the last reference is dropped on a different thread than the one where the
/// wrapper was originally created. To ensure that values are cleaned up properly, keep the
/// game single-threaded, or use a real thread-safe wrapper such as [`MutexData`] instead.
#[derive(Debug)]
pub struct LocalCellData<T> {
inner: Arc<local_cell::LocalCell<T>>,
Expand All @@ -535,12 +541,23 @@ pub use self::local_cell::LocalCellError;

mod local_cell {
use std::cell::{Ref, RefCell, RefMut};
use std::mem::ManuallyDrop;
use std::thread::{self, ThreadId};

#[derive(Debug)]
pub struct LocalCell<T> {
thread_id: ThreadId,
cell: RefCell<T>,
cell: RefCell<ManuallyDrop<T>>,
}

impl<T> Drop for LocalCell<T> {
fn drop(&mut self) {
if self.thread_id == thread::current().id() {
unsafe {
ManuallyDrop::drop(self.cell.get_mut());
}
}
}
}

/// Error indicating that a borrow has failed.
Expand Down Expand Up @@ -578,12 +595,12 @@ mod local_cell {
pub fn new(val: T) -> Self {
LocalCell {
thread_id: thread::current().id(),
cell: RefCell::new(val),
cell: RefCell::new(ManuallyDrop::new(val)),
}
}

#[inline]
fn inner(&self) -> Result<&RefCell<T>, LocalCellError> {
fn inner(&self) -> Result<&RefCell<ManuallyDrop<T>>, LocalCellError> {
let current = thread::current().id();

if self.thread_id == current {
Expand All @@ -597,13 +614,13 @@ mod local_cell {
}

#[inline]
pub fn try_borrow(&self) -> Result<Ref<T>, LocalCellError> {
pub fn try_borrow(&self) -> Result<Ref<ManuallyDrop<T>>, LocalCellError> {
let inner = self.inner()?;
inner.try_borrow().map_err(|_| LocalCellError::BorrowFailed)
}

#[inline]
pub fn try_borrow_mut(&self) -> Result<RefMut<T>, LocalCellError> {
pub fn try_borrow_mut(&self) -> Result<RefMut<ManuallyDrop<T>>, LocalCellError> {
let inner = self.inner()?;
inner
.try_borrow_mut()
Expand Down
2 changes: 1 addition & 1 deletion gdnative-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#![allow(
clippy::transmute_ptr_to_ptr,
clippy::missing_safety_doc,
clippy::if_then_panic
clippy::non_send_fields_in_send_ty
)]
#![cfg_attr(feature = "gd_test", allow(clippy::blacklisted_name))]

Expand Down
2 changes: 1 addition & 1 deletion test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::blacklisted_name, clippy::if_then_panic)]
#![allow(clippy::blacklisted_name)]

use gdnative::prelude::*;

Expand Down