Remove most compiler warnings

This commit is contained in:
SeanOMik 2024-01-06 15:52:12 -05:00
parent 9307265a5a
commit 4a42989098
Signed by: SeanOMik
GPG Key ID: FEC9E2FC15235964
15 changed files with 54 additions and 47 deletions

View File

@ -1,6 +1,6 @@
use proc_macro2::Ident;
use quote::quote;
use syn::{token::Enum, DataEnum, DeriveInput, Generics, GenericParam, parse_quote, Variant};
use syn::{DataEnum, DeriveInput, parse_quote, Variant};
use crate::add_trait_bounds;
@ -267,7 +267,7 @@ fn gen_if_field_indices_names(variant: &Variant) -> proc_macro2::TokenStream {
/// * `by_index`: Should the if statements be generated to check indices.
fn gen_enum_if_stmts(enum_id: &proc_macro2::Ident, data: &DataEnum, by_index: bool) -> proc_macro2::TokenStream {
let mut if_statement_count = 0;
let struct_vars = data.variants.iter().enumerate().map(|(idx, var)| {
let struct_vars = data.variants.iter().map(|var| {
let vty = VariantType::from(var);
let prepend_else = if_statement_count > 0;

View File

@ -1,15 +1,16 @@
use std::slice::Split;
use proc_macro::TokenStream;
use quote::{quote, ToTokens};
use syn::{Generics, parse::ParseBuffer, Path, Attribute, GenericParam, parse_quote, parse_macro_input, DeriveInput, TypeParamBound};
use syn::{Generics, Path, Attribute, GenericParam, parse_macro_input, DeriveInput, TypeParamBound};
mod enum_derive;
#[allow(unused_imports)]
use enum_derive::*;
mod struct_derive;
#[allow(unused_imports)]
use struct_derive::*;
#[allow(dead_code)]
pub(crate) struct ReflectDef {
pub type_path: Path,
pub generics: Generics,

View File

@ -22,7 +22,7 @@ use crate::add_trait_bounds;
/// _ => None,
/// }
/// ```
fn gen_struct_field_match(struct_id: &proc_macro2::Ident, data: &DataStruct, is_mut: bool) -> proc_macro2::TokenStream {
fn gen_struct_field_match(data: &DataStruct, is_mut: bool) -> proc_macro2::TokenStream {
let mut_tkn = if is_mut {
quote! {
mut
@ -63,7 +63,7 @@ fn gen_struct_field_match(struct_id: &proc_macro2::Ident, data: &DataStruct, is_
/// },
/// }
/// ```
fn gen_struct_set_field_match(struct_id: &proc_macro2::Ident, data: &DataStruct) -> proc_macro2::TokenStream {
fn gen_struct_set_field_match(data: &DataStruct) -> proc_macro2::TokenStream {
let field_arms = data.fields.iter().map(|field| {
let field_ident = field.ident.as_ref().expect("Struct is missing field ident!");
let field_name_str = field_ident.to_string();
@ -98,7 +98,7 @@ fn gen_struct_set_field_match(struct_id: &proc_macro2::Ident, data: &DataStruct)
/// _ => None,
/// }
/// ```
fn gen_struct_field_name_match(struct_id: &proc_macro2::Ident, data: &DataStruct) -> proc_macro2::TokenStream {
fn gen_struct_field_name_match(data: &DataStruct) -> proc_macro2::TokenStream {
let field_arms = data.fields.iter().map(|field| {
let field_ident = field.ident.as_ref().expect("Struct is missing field ident!");
let field_name_str = field_ident.to_string();
@ -137,7 +137,7 @@ fn gen_struct_field_name_match(struct_id: &proc_macro2::Ident, data: &DataStruct
/// },
/// }
/// ```
fn gen_struct_set_field_match_idx(struct_id: &proc_macro2::Ident, data: &DataStruct) -> proc_macro2::TokenStream {
fn gen_struct_set_field_match_idx(data: &DataStruct) -> proc_macro2::TokenStream {
let field_arms = data.fields.iter().enumerate().map(|(idx, field)| {
let field_ident = field.ident.as_ref().expect("Struct is missing field ident!");
let field_name_str = field_ident.to_string();
@ -172,7 +172,7 @@ fn gen_struct_set_field_match_idx(struct_id: &proc_macro2::Ident, data: &DataStr
/// _ => None,
/// }
/// ```
fn gen_struct_field_name_match_idx(struct_id: &proc_macro2::Ident, data: &DataStruct) -> proc_macro2::TokenStream {
fn gen_struct_field_name_match_idx(data: &DataStruct) -> proc_macro2::TokenStream {
let field_arms = data.fields.iter().enumerate().map(|(idx, field)| {
let mut field_ty_stream = proc_macro2::TokenStream::new();
field.ty.to_tokens(&mut field_ty_stream);
@ -211,7 +211,7 @@ fn gen_struct_field_name_match_idx(struct_id: &proc_macro2::Ident, data: &DataSt
/// _ => None,
/// }
/// ```
fn gen_struct_field_match_idx(struct_id: &proc_macro2::Ident, data: &DataStruct, is_mut: bool) -> proc_macro2::TokenStream {
fn gen_struct_field_match_idx(data: &DataStruct, is_mut: bool) -> proc_macro2::TokenStream {
let mut_tkn = if is_mut {
quote! {
mut
@ -245,7 +245,7 @@ fn gen_struct_field_match_idx(struct_id: &proc_macro2::Ident, data: &DataStruct,
/// _ => None,
/// }
/// ```
fn gen_struct_field_name_idx(struct_id: &proc_macro2::Ident, data: &DataStruct) -> proc_macro2::TokenStream {
fn gen_struct_field_name_idx(data: &DataStruct) -> proc_macro2::TokenStream {
let field_arms = data.fields.iter().enumerate().map(|(idx, field)| {
let field_ident = field.ident.as_ref().expect("Struct is missing field ident!");
let field_name_str = field_ident.to_string();
@ -269,15 +269,15 @@ pub fn derive_reflect_struct(input: &DeriveInput, data_struct: &DataStruct) -> p
let name = type_path.span().source_text().unwrap();
let field_len = data_struct.fields.len();
let get_field_match = gen_struct_field_match(type_path, data_struct, false);
let get_field_mut_match = gen_struct_field_match(type_path, data_struct, true);
let get_field_match_idx = gen_struct_field_match_idx(type_path, data_struct, false);
let get_field_mut_match_idx = gen_struct_field_match_idx(type_path, data_struct, true);
let set_field_named = gen_struct_set_field_match(type_path, data_struct);
let set_field_idx = gen_struct_set_field_match_idx(type_path, data_struct);
let get_field_name_match = gen_struct_field_name_match(type_path, data_struct);
let get_field_name_match_idx = gen_struct_field_name_match_idx(type_path, data_struct);
let field_name_at = gen_struct_field_name_idx(type_path, data_struct);
let get_field_match = gen_struct_field_match(data_struct, false);
let get_field_mut_match = gen_struct_field_match(data_struct, true);
let get_field_match_idx = gen_struct_field_match_idx(data_struct, false);
let get_field_mut_match_idx = gen_struct_field_match_idx(data_struct, true);
let set_field_named = gen_struct_set_field_match(data_struct);
let set_field_idx = gen_struct_set_field_match_idx(data_struct);
let get_field_name_match = gen_struct_field_name_match(data_struct);
let get_field_name_match_idx = gen_struct_field_name_match_idx(data_struct);
let field_name_at = gen_struct_field_name_idx(data_struct);
let generics = add_trait_bounds(input.generics.clone(), vec![parse_quote!(Reflect), parse_quote!(Clone)]);
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();

View File

@ -1,4 +1,4 @@
use std::{any::TypeId, sync::Arc, ptr::NonNull};
use std::any::TypeId;
use super::{Reflect, Tuple, ReflectRef};

View File

@ -1,12 +1,10 @@
use std::any::TypeId;
use lyra_reflect_derive::impl_reflect_trait_value;
use crate::List;
use crate::lyra_engine;
use super::{Reflect, ReflectRef, ReflectMut, util, TypeData};
use super::{Reflect, ReflectRef, ReflectMut, util};
impl_reflect_trait_value!(bool);
impl_reflect_trait_value!(char);
@ -53,7 +51,11 @@ impl<T: Clone + Reflect, const N: usize> Reflect for [T; N] {
}
fn apply(&mut self, val: &dyn Reflect) {
todo!()
if let ReflectRef::Array(arr) = val.reflect_ref() {
util::apply_array(self, arr);
} else {
panic!("Provided value was not a List!");
}
}
fn clone_inner(&self) -> Box<dyn Reflect> {

View File

@ -2,7 +2,7 @@
use std::{any::TypeId, any::Any, cell::{Ref, RefMut}};
use lyra_ecs::{world::World, DynamicBundle, Component, Entity, ComponentInfo, query::dynamic::DynamicType};
use lyra_ecs::{world::World, DynamicBundle, Component, Entity, ComponentInfo};
extern crate self as lyra_reflect;
@ -186,6 +186,7 @@ impl<'a> ReflectEither<'a> {
}
}
#[allow(dead_code)]
pub struct Value {
inner: Box<dyn Reflect>,
type_id: TypeId,

View File

@ -1,7 +1,9 @@
use std::{any::TypeId, sync::Arc};
use super::{Value, IntoValue};
use super::Value;
/// Method will probably be completely removed soon
#[allow(dead_code)]
#[derive(Clone)]
pub struct Method {
pub name: Option<String>,

View File

@ -49,6 +49,7 @@ pub trait Enum: Reflect {
fn variant_type(&self) -> EnumType;
}
#[allow(unused_variables)]
#[cfg(test)]
mod tests {
use lyra_reflect_derive::Reflect;

View File

@ -1,5 +1,4 @@
use super::{ReflectEither, Reflect, Struct};
use super::Reflect;
/// A struct that can set fields on different types of reflected values.
pub struct ReflectField<'a> {

View File

@ -77,7 +77,7 @@ impl<T: Reflect + Clone> List for Vec<T> {
}
}
fn push_front(&mut self, item: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>> {
fn push_front(&mut self, _item: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>> {
unimplemented!("push_front for `List` trait implementation of a `Vec<T>`. Doing so is slow!")
}

View File

@ -1,6 +1,4 @@
use std::{any::{TypeId, type_name, Any}, collections::HashMap, marker::PhantomData, sync::Arc};
use super::{field::Field, method::Method, Reflect, Value};
use super::{method::Method, Reflect};
/// A trait that a struct would implement
pub trait Struct: Reflect {
@ -43,13 +41,8 @@ pub trait Struct: Reflect {
#[cfg(test)]
mod tests {
use std::any::TypeId;
use lyra_reflect_derive::Reflect;
use crate::{Reflect, ReflectRef, ReflectMut};
use super::Struct;
use crate::lyra_engine;
#[derive(Clone, Copy, Reflect)]

View File

@ -1,3 +1,5 @@
use crate::Array;
use super::List;
/// A helper method that implements apply_list for you
@ -12,6 +14,17 @@ pub fn apply_list(apply_to: &mut dyn List, other: &dyn List) {
}
}
pub fn apply_array(apply_to: &mut dyn Array, other: &dyn Array) {
assert_eq!(apply_to.len(), other.len(),
"Arrays must be the same length when applying one to the other!");
let len = apply_to.len();
for i in 0..len {
let el = apply_to.get_mut(i).unwrap();
el.apply(other.get(i).unwrap());
}
}
/// A helper method that implements [`Reflect::clone_inner`] for you.
pub fn clone_inner_list(clone: &dyn List) -> Box<dyn List> {
let mut empty = clone.create_empty();

View File

@ -1,7 +1,6 @@
use std::{sync::{Arc, RwLock}, error::Error, collections::HashMap};
use std::collections::HashMap;
use anyhow::anyhow;
use lyra_ecs::{query::Res, ResourceObject};
use lyra_ecs::ResourceObject;
use crate::ScriptWorldPtr;

View File

@ -35,7 +35,7 @@ impl ReflectBranch {
pub fn as_component_unchecked(&self) -> &ReflectedComponent {
match self {
ReflectBranch::Component(c) => c,
_ => panic!("`self` is not an instance of `ReflectBranch::Component`")
//_ => panic!("`self` is not an instance of `ReflectBranch::Component`")
}
}

View File

@ -2,10 +2,6 @@ use std::ptr::NonNull;
use lyra_ecs::{world::World, Entity};
use mlua::{prelude::{LuaUserData, LuaAnyUserData, LuaValue, LuaResult, Lua, LuaError}, Variadic, AnyUserDataExt, FromLua, IntoLua, MultiValue, IntoLuaMulti};
use crate::ScriptBorrow;
#[derive(Clone)]
pub struct ScriptEntity(pub Entity);