Skip to content

Commit

Permalink
Try #961:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Oct 12, 2022
2 parents 3731a64 + 2d5bf2e commit dde79a6
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 22 deletions.
2 changes: 1 addition & 1 deletion gdnative-core/src/core_types/float32_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ godot_test!(
}

for i in 0..8 {
assert_relative_eq!(i as f32 * 2., cow_arr.get(i as i32));
assert_relative_eq!(i as f32 * 2., cow_arr.get(i));
}

// the write shouldn't have affected the original array
Expand Down
2 changes: 1 addition & 1 deletion gdnative-core/src/core_types/int32_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ godot_test!(
}

for i in 0..8 {
assert_eq!(i * 2, cow_arr.get(i as i32));
assert_eq!(i * 2, cow_arr.get(i));
}

// the write shouldn't have affected the original array
Expand Down
2 changes: 1 addition & 1 deletion gdnative-core/src/core_types/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ impl TryFrom<GodotChar> for char {
1 => std::char::from_u32(c.0 as u32).ok_or(GodotCharError::IncompleteSequence),
4 => std::char::from_u32(c.0 as u32).ok_or(GodotCharError::InvalidCodePoint),
2 => {
let mut iter = std::char::decode_utf16(std::iter::once(c.0 as u16));
let mut iter = std::char::decode_utf16(std::iter::once(c.0));
let c = iter
.next()
.ok_or(GodotCharError::InvalidCodePoint)?
Expand Down
6 changes: 3 additions & 3 deletions gdnative-core/src/export/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,9 @@ bitflags::bitflags! {
const ANIMATE_AS_TRIGGER = sys::godot_property_usage_flags_GODOT_PROPERTY_USAGE_ANIMATE_AS_TRIGGER as u32;
const UPDATE_ALL_IF_MODIFIED = sys::godot_property_usage_flags_GODOT_PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED as u32;

const DEFAULT = Self::STORAGE.bits | Self::EDITOR.bits | Self::NETWORK.bits as u32;
const DEFAULT_INTL = Self::DEFAULT.bits | Self::INTERNATIONALIZED.bits as u32;
const NOEDITOR = Self::STORAGE.bits | Self::NETWORK.bits as u32;
const DEFAULT = Self::STORAGE.bits | Self::EDITOR.bits | Self::NETWORK.bits;
const DEFAULT_INTL = Self::DEFAULT.bits | Self::INTERNATIONALIZED.bits;
const NOEDITOR = Self::STORAGE.bits | Self::NETWORK.bits;
}
}

Expand Down
7 changes: 2 additions & 5 deletions gdnative-core/src/globalscope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,8 @@ pub fn move_toward(range: RangeInclusive<f32>, delta: f32) -> f32 {
/// ![Image](https://raw.githubusercontent.com/godotengine/godot-docs/3.4/img/ease_cheatsheet.png)
#[inline]
pub fn ease(mut s: f32, curve: f32) -> f32 {
if s < 0.0 {
s = 0.0;
} else if s > 1.0 {
s = 1.0;
}
s = s.clamp(0.0, 1.0);

if curve > 0.0 {
if curve < 1.0 {
1.0 - (1.0 - s).powf(1.0 / curve)
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 @@ -25,7 +25,7 @@
clippy::missing_safety_doc,
clippy::non_send_fields_in_send_ty
)]
#![cfg_attr(feature = "gd-test", allow(clippy::blacklisted_name))]
#![cfg_attr(feature = "gd-test", allow(clippy::disallowed_names))]

#[doc(hidden)]
pub extern crate gdnative_sys as sys;
Expand Down
20 changes: 19 additions & 1 deletion gdnative-derive/src/variant/bounds.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use syn::punctuated::Punctuated;
use syn::visit::Visit;
use syn::Generics;
use syn::{GenericParam, Generics};

use crate::extend_bounds::{with_visitor, BoundsVisitor};

Expand Down Expand Up @@ -50,3 +51,20 @@ pub(crate) fn extend_bounds(
}
})
}

pub(crate) fn remove_bounds(mut generics: Generics) -> Generics {
for param in generics.params.iter_mut() {
match param {
GenericParam::Type(ty) => {
ty.colon_token = None;
ty.bounds = Punctuated::new();
}
GenericParam::Lifetime(lt) => {
lt.colon_token = None;
lt.bounds = Punctuated::new();
}
GenericParam::Const(_) => {}
}
}
generics
}
4 changes: 3 additions & 1 deletion gdnative-derive/src/variant/from.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use proc_macro2::{Literal, Span, TokenStream as TokenStream2};

use crate::variant::bounds;
use syn::Ident;

use super::repr::Repr;
Expand Down Expand Up @@ -106,11 +107,12 @@ pub(crate) fn expand_from_variant(derive_data: DeriveData) -> Result<TokenStream
}
};

let generics_no_bounds = bounds::remove_bounds(generics.clone());
let where_clause = &generics.where_clause;

let result = quote! {
#derived
impl #generics ::gdnative::core_types::FromVariant for #ident #generics #where_clause {
impl #generics ::gdnative::core_types::FromVariant for #ident #generics_no_bounds #where_clause {
fn from_variant(
#input_ident: &::gdnative::core_types::Variant
) -> ::std::result::Result<Self, ::gdnative::core_types::FromVariantError> {
Expand Down
4 changes: 3 additions & 1 deletion gdnative-derive/src/variant/to.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::variant::bounds;
use proc_macro2::{Literal, TokenStream as TokenStream2};

use super::repr::Repr;
Expand Down Expand Up @@ -69,11 +70,12 @@ pub(crate) fn expand_to_variant(
}
};

let generics_no_bounds = bounds::remove_bounds(generics.clone());
let where_clause = &generics.where_clause;

let result = quote! {
#derived
impl #generics #trait_path for #ident #generics #where_clause {
impl #generics #trait_path for #ident #generics_no_bounds #where_clause {
fn #to_variant_fn(#to_variant_receiver) -> ::gdnative::core_types::Variant {
use #trait_path;
use ::gdnative::core_types::FromVariant;
Expand Down
4 changes: 2 additions & 2 deletions gdnative-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ unsafe fn find_version(
version_minor: u32,
) -> Option<Result<*const godot_gdnative_api_struct, InitError>> {
let mut got = None;
if (*api).type_ as u32 == api_type as u32 {
if (*api).type_ == api_type as u32 {
while !api.is_null() {
// The boolean expression below SHOULD always be true;
// we will double check to be safe.
if (*api).type_ as u32 == api_type as u32 {
if (*api).type_ == api_type as u32 {
let (major, minor) = ((*api).version.major, (*api).version.minor);
if major == version_major && minor == version_minor {
return Some(Ok(api));
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)]
#![allow(clippy::disallowed_names)]
#![allow(deprecated)]

use gdnative::prelude::*;
Expand Down
10 changes: 6 additions & 4 deletions test/src/test_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ pub(crate) fn register(handle: InitHandle) {

crate::godot_itest! { test_derive_to_variant {
#[derive(Clone, Eq, PartialEq, Debug, ToVariant, FromVariant)]
struct ToVar<T, R>
struct ToVar<T: Associated, R>
where
T: Associated,
R: Default,
{
foo: T::A,
Expand All @@ -55,7 +54,7 @@ crate::godot_itest! { test_derive_to_variant {
}

#[derive(Clone, Eq, PartialEq, Debug, ToVariant, FromVariant)]
enum ToVarEnum<T> {
enum ToVarEnum<T: Bound> {
Foo(T),
Bar,
Baz { baz: u8 },
Expand All @@ -67,9 +66,12 @@ crate::godot_itest! { test_derive_to_variant {
T: Associated,
R: Default;

trait Bound {}
impl Bound for bool {}

trait Associated {
type A;
type B;
type B : Bound;
}

impl Associated for f64 {
Expand Down

0 comments on commit dde79a6

Please sign in to comment.