Skip to content

Commit

Permalink
Merge #703
Browse files Browse the repository at this point in the history
703: Fix current and future clippy lints r=toasteater a=toasteater

This fixes new clippy lints in current stable and nightly.

bors r+

Co-authored-by: toasteater <48371905+toasteater@users.noreply.github.com>
  • Loading branch information
bors[bot] and toasteater committed Feb 23, 2021
2 parents 4bc7681 + 6e41d9c commit 46514c7
Show file tree
Hide file tree
Showing 19 changed files with 49 additions and 44 deletions.
6 changes: 3 additions & 3 deletions bindings_generator/src/class_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ use std::{collections::HashMap, fs};
use roxmltree::Node;

#[derive(Debug)]
pub struct GodotXMLDocs {
pub struct GodotXmlDocs {
class_fn_desc: HashMap<(String, String), String>,
}

impl GodotXMLDocs {
impl GodotXmlDocs {
pub fn new(folder: &str) -> Self {
let entries = fs::read_dir(folder)
.unwrap()
.map(|e| e.unwrap().path())
.collect::<Vec<_>>();

let mut docs = GodotXMLDocs {
let mut docs = GodotXmlDocs {
class_fn_desc: HashMap::default(),
};

Expand Down
4 changes: 2 additions & 2 deletions bindings_generator/src/classes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::api::*;
use crate::class_docs::GodotXMLDocs;
use crate::class_docs::GodotXmlDocs;
use crate::methods;
use crate::special_methods;

Expand All @@ -24,7 +24,7 @@ pub(crate) fn generate_class_struct(class: &GodotClass) -> TokenStream {
pub(crate) fn generate_class_impl(
class: &GodotClass,
icalls: &mut HashMap<String, methods::MethodSig>,
docs: Option<&GodotXMLDocs>,
docs: Option<&GodotXmlDocs>,
) -> TokenStream {
let class_singleton = if class.singleton {
special_methods::generate_singleton_getter(class)
Expand Down
4 changes: 2 additions & 2 deletions bindings_generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct BindingResult {
pub icalls: TokenStream,
}

pub fn generate_bindings(api: &Api, docs: Option<&GodotXMLDocs>) -> BindingResult {
pub fn generate_bindings(api: &Api, docs: Option<&GodotXmlDocs>) -> BindingResult {
let mut icalls = HashMap::new();

let class_bindings = api
Expand Down Expand Up @@ -80,7 +80,7 @@ fn generate_class_bindings(
api: &Api,
class: &GodotClass,
icalls: &mut HashMap<String, MethodSig>,
docs: Option<&GodotXMLDocs>,
docs: Option<&GodotXmlDocs>,
) -> TokenStream {
// types and methods
let types_and_methods = {
Expand Down
6 changes: 3 additions & 3 deletions bindings_generator/src/methods.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::api::*;
use crate::class_docs::GodotXMLDocs;
use crate::class_docs::GodotXmlDocs;
use crate::rust_safe_name;

use proc_macro2::TokenStream;
Expand Down Expand Up @@ -250,7 +250,7 @@ fn rename_property_getter<'a>(name: &'a str, class: &GodotClass) -> &'a str {
if name.starts_with("get_") && class.is_getter(name) {
&name[4..]
} else {
&name[..]
&name
}
}

Expand All @@ -263,7 +263,7 @@ const UNSAFE_OBJECT_METHODS: &[(&str, &str)] = &[
pub(crate) fn generate_methods(
class: &GodotClass,
icalls: &mut HashMap<String, MethodSig>,
docs: Option<&GodotXMLDocs>,
docs: Option<&GodotXmlDocs>,
) -> TokenStream {
// Brings values of some types to a type with less information.
fn arg_erase(ty: &Ty, name: &proc_macro2::Ident) -> TokenStream {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
[ext_resource path="res://dodge_the_creeps_library.gdnlib" type="GDNativeLibrary" id=1]

[resource]
resource_name = "HUD"
class_name = "HUD"
resource_name = "Hud"
class_name = "Hud"
library = ExtResource( 1 )
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[gd_scene load_steps=6 format=2]

[ext_resource path="res://HUD.gdns" type="Script" id=1]
[ext_resource path="res://Hud.gdns" type="Script" id=1]
[ext_resource path="res://fonts/Xolonium-Regular.ttf" type="DynamicFontData" id=2]

[sub_resource type="DynamicFont" id=1]
Expand Down
2 changes: 1 addition & 1 deletion examples/dodge_the_creeps/Main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[ext_resource path="res://Main.gdns" type="Script" id=1]
[ext_resource path="res://Mob.tscn" type="PackedScene" id=2]
[ext_resource path="res://Player.tscn" type="PackedScene" id=3]
[ext_resource path="res://HUD.tscn" type="PackedScene" id=4]
[ext_resource path="res://Hud.tscn" type="PackedScene" id=4]

[sub_resource type="Curve2D" id=1]
_data = {
Expand Down
8 changes: 4 additions & 4 deletions examples/dodge_the_creeps/src/hud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use gdnative::prelude::*;

#[derive(NativeClass)]
#[inherit(CanvasLayer)]
#[user_data(user_data::ArcData<HUD>)]
#[user_data(user_data::ArcData<Hud>)]
#[register_with(Self::register_hud)]
pub struct HUD;
pub struct Hud;

#[methods]
impl HUD {
impl Hud {
fn register_hud(builder: &ClassBuilder<Self>) {
builder.add_signal(Signal {
name: "start_game",
Expand All @@ -16,7 +16,7 @@ impl HUD {
}

fn new(_owner: &CanvasLayer) -> Self {
HUD
Hud
}

#[export]
Expand Down
2 changes: 1 addition & 1 deletion examples/dodge_the_creeps/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn init(handle: InitHandle) {
handle.add_class::<player::Player>();
handle.add_class::<mob::Mob>();
handle.add_class::<main_scene::Main>();
handle.add_class::<hud::HUD>();
handle.add_class::<hud::Hud>();
}

godot_init!(init);
8 changes: 4 additions & 4 deletions examples/dodge_the_creeps/src/main_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Main {
score_timer.stop();
mob_timer.stop();

let hud = unsafe { owner.get_node_as_instance::<hud::HUD>("hud").unwrap() };
let hud = unsafe { owner.get_node_as_instance::<hud::Hud>("hud").unwrap() };
hud.map(|x, o| x.show_game_over(&*o))
.ok()
.unwrap_or_else(|| godot_print!("Unable to get hud"));
Expand All @@ -57,7 +57,7 @@ impl Main {

start_timer.start(0.0);

let hud = unsafe { owner.get_node_as_instance::<hud::HUD>("hud").unwrap() };
let hud = unsafe { owner.get_node_as_instance::<hud::Hud>("hud").unwrap() };
hud.map(|x, o| {
x.update_score(&*o, self.score);
x.show_message(&*o, "Get Ready".into());
Expand All @@ -78,7 +78,7 @@ impl Main {
fn on_score_timer_timeout(&mut self, owner: &Node) {
self.score += 1;

let hud = unsafe { owner.get_node_as_instance::<hud::HUD>("hud").unwrap() };
let hud = unsafe { owner.get_node_as_instance::<hud::Hud>("hud").unwrap() };
hud.map(|x, o| x.update_score(&*o, self.score))
.ok()
.unwrap_or_else(|| godot_print!("Unable to get hud"));
Expand Down Expand Up @@ -119,7 +119,7 @@ impl Main {
mob_owner
.set_linear_velocity(mob_owner.linear_velocity().rotated(Angle { radians: d }));

let hud = unsafe { owner.get_node_as_instance::<hud::HUD>("hud").unwrap() };
let hud = unsafe { owner.get_node_as_instance::<hud::Hud>("hud").unwrap() };

hud.map(|_, o| {
o.connect(
Expand Down
6 changes: 3 additions & 3 deletions gdnative-bindings/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use gdnative_bindings_generator::*;
use std::env;
use std::fs::File;
use std::io::{BufWriter, Write as _};
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::process::Command;

fn main() {
Expand All @@ -15,7 +15,7 @@ fn main() {
let icalls_rs = out_path.join("icalls.rs");

let api = Api::new(&api_data);
let docs = GodotXMLDocs::new("docs");
let docs = GodotXmlDocs::new("docs");
let binding_res = generate_bindings(&api, Some(&docs));

{
Expand Down Expand Up @@ -111,7 +111,7 @@ fn generate(
}
}

fn format_file(output_rs: &PathBuf) {
fn format_file(output_rs: &Path) {
print!(
"Formatting generated file: {}... ",
output_rs.file_name().and_then(|s| s.to_str()).unwrap()
Expand Down
12 changes: 6 additions & 6 deletions gdnative-core/src/core_types/node_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ where
}
}

impl Into<String> for NodePath {
impl From<NodePath> for String {
#[inline]
fn into(self) -> String {
self.to_string()
fn from(p: NodePath) -> String {
p.to_string()
}
}

Expand All @@ -155,10 +155,10 @@ impl From<GodotString> for NodePath {
}
}

impl Into<GodotString> for NodePath {
impl From<NodePath> for GodotString {
#[inline]
fn into(self) -> GodotString {
self.to_godot_string()
fn from(p: NodePath) -> GodotString {
p.to_godot_string()
}
}

Expand Down
1 change: 1 addition & 0 deletions gdnative-core/src/core_types/vector2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub trait Vector2Godot {
/// Internal API for converting to `sys` representation. Makes it possible to remove
/// `transmute`s elsewhere.
#[doc(hidden)]
#[allow(clippy::wrong_self_convention)]
fn to_sys(self) -> sys::godot_vector2;
/// Internal API for converting to `sys` representation. Makes it possible to remove
/// `transmute`s elsewhere.
Expand Down
1 change: 1 addition & 0 deletions gdnative-core/src/core_types/vector3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub trait Vector3Godot {
fn distance_squared_to(self, other: Vector3) -> f32;

#[doc(hidden)]
#[allow(clippy::wrong_self_convention)]
fn to_sys(self) -> sys::godot_vector3;
/// Internal API for converting to `sys` representation. Makes it possible to remove
/// `transmute`s elsewhere.
Expand Down
4 changes: 2 additions & 2 deletions gdnative-core/src/nativescript/init/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ where

let path = ::std::ffi::CString::new(self.name).unwrap();

let set = unsafe { self.setter.as_godot_function() };
let get = unsafe { self.getter.as_godot_function() };
let set = unsafe { self.setter.into_godot_function() };
let get = unsafe { self.getter.into_godot_function() };

unsafe {
(get_api().godot_nativescript_register_property)(
Expand Down
14 changes: 8 additions & 6 deletions gdnative-core/src/nativescript/init/property/accessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ pub use self::invalid::{InvalidGetter, InvalidSetter};

/// Trait for raw property setters.
///
/// It's usually unnecessary to use this directly.
/// This is an internal interface. User code should not use this directly.
pub unsafe trait RawSetter<C, T> {
unsafe fn as_godot_function(self) -> sys::godot_property_set_func;
#[doc(hidden)]
unsafe fn into_godot_function(self) -> sys::godot_property_set_func;
}

/// Trait for raw property getters.
///
/// It's usually unnecessary to use this directly.
/// This is an internal interface. User code should not use this directly.
pub unsafe trait RawGetter<C, T> {
unsafe fn as_godot_function(self) -> sys::godot_property_get_func;
#[doc(hidden)]
unsafe fn into_godot_function(self) -> sys::godot_property_get_func;
}

#[derive(Debug)]
Expand Down Expand Up @@ -206,7 +208,7 @@ where
SelfArg: MapSet<C, F, T>,
{
#[inline]
unsafe fn as_godot_function(self) -> sys::godot_property_set_func {
unsafe fn into_godot_function(self) -> sys::godot_property_set_func {
let mut set = sys::godot_property_set_func::default();
let data = Box::new(self.func);
set.method_data = Box::into_raw(data) as *mut _;
Expand Down Expand Up @@ -281,7 +283,7 @@ where
(SelfArg, RetKind): MapGet<C, F, T>,
{
#[inline]
unsafe fn as_godot_function(self) -> sys::godot_property_get_func {
unsafe fn into_godot_function(self) -> sys::godot_property_get_func {
let mut get = sys::godot_property_get_func::default();
let data = Box::new(self.func);
get.method_data = Box::into_raw(data) as *mut _;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ extern "C" fn invalid_free_func(data: *mut libc::c_void) {

unsafe impl<'l, C: NativeClass, T: FromVariant> RawSetter<C, T> for InvalidSetter<'l> {
#[inline]
unsafe fn as_godot_function(self) -> sys::godot_property_set_func {
unsafe fn into_godot_function(self) -> sys::godot_property_set_func {
let mut set = sys::godot_property_set_func::default();

let data = Box::new(InvalidAccessorData {
Expand All @@ -98,7 +98,7 @@ unsafe impl<'l, C: NativeClass, T: FromVariant> RawSetter<C, T> for InvalidSette

unsafe impl<'l, C: NativeClass, T: ToVariant> RawGetter<C, T> for InvalidGetter<'l> {
#[inline]
unsafe fn as_godot_function(self) -> sys::godot_property_get_func {
unsafe fn into_godot_function(self) -> sys::godot_property_get_func {
let mut get = sys::godot_property_get_func::default();

let data = Box::new(InvalidAccessorData {
Expand Down
4 changes: 2 additions & 2 deletions gdnative-core/src/nativescript/profiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ impl Signature<'static> {
/// If `file` or `tag` contain `::` or NUL-bytes.
#[inline]
pub fn new(file: &str, line: u32, tag: &str) -> Self {
if file.find("::").is_some() {
if file.contains("::") {
panic!("file name should not contain `::`");
}

if tag.find("::").is_some() {
if tag.contains("::") {
panic!("tag should not contain `::`");
}

Expand Down
1 change: 1 addition & 0 deletions impl/proc_macros/src/typed_array_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ fn fn_ty(method: &str) -> Type {
}
}

#[allow(clippy::unnecessary_wraps)]
fn expand(input: Args) -> Result<TokenStream, syn::Error> {
let Args {
trait_name,
Expand Down

0 comments on commit 46514c7

Please sign in to comment.