From 95c958d04d5b316dc08ce8775363fcc997bbefc4 Mon Sep 17 00:00:00 2001 From: Lily Lyons Date: Tue, 28 Nov 2023 22:06:40 -0800 Subject: [PATCH] chore: :rotating_light: fix wasily fixable warnings --- Cargo.toml | 2 ++ crates/components/src/command_view/mod.rs | 20 +++++++++----------- crates/components/src/map_view.rs | 3 ++- crates/components/src/tilepicker.rs | 9 +++++---- crates/core/src/data_cache.rs | 6 +++--- crates/core/src/tab.rs | 2 +- crates/data/src/helpers/id_vec.rs | 2 +- crates/data/src/helpers/optional_path.rs | 2 +- crates/data/src/option_vec.rs | 2 +- crates/filesystem/src/project.rs | 2 -- crates/graphics/src/event.rs | 6 +++++- crates/graphics/src/map.rs | 8 +++++++- crates/graphics/src/plane.rs | 3 ++- crates/modals/src/sound_picker.rs | 2 +- crates/ui/src/windows/event_edit.rs | 22 ++++++++++------------ crates/ui/src/windows/items.rs | 10 ++++------ src/app/mod.rs | 4 ++-- 17 files changed, 56 insertions(+), 49 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e30c16e4..44f7644c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,8 @@ rust_2018_idioms = "warn" unsafe_code = "warn" # clearly denote where you are using unsafe code in unsafe fns. in a future rust edition this will become a hard error. unsafe_op_in_unsafe_fn = "forbid" +# will become a hard error in a future rust edition +elided_lifetimes_in_paths = "forbid" [workspace.lints.clippy] all = "warn" diff --git a/crates/components/src/command_view/mod.rs b/crates/components/src/command_view/mod.rs index 26daea82..adfd4c01 100644 --- a/crates/components/src/command_view/mod.rs +++ b/crates/components/src/command_view/mod.rs @@ -31,25 +31,23 @@ mod ui; use std::collections::HashMap; pub struct CommandView { - selected_index: usize, - window_state: WindowState, - id: egui::Id, - modals: HashMap, // todo find a better way to handle modals + _selected_index: usize, + _window_state: WindowState, + _id: egui::Id, + _modals: HashMap, // todo find a better way to handle modals } enum WindowState { - Insert { index: usize, tab: usize }, - Edit { index: usize }, None, } impl Default for CommandView { fn default() -> Self { Self { - selected_index: 0, - window_state: WindowState::None, - id: egui::Id::new("command_view"), - modals: HashMap::new(), + _selected_index: 0, + _window_state: WindowState::None, + _id: egui::Id::new("command_view"), + _modals: HashMap::new(), } } } @@ -57,7 +55,7 @@ impl Default for CommandView { impl CommandView { pub fn new(id: impl std::hash::Hash) -> Self { Self { - id: egui::Id::new(id), + _id: egui::Id::new(id), ..Default::default() } } diff --git a/crates/components/src/map_view.rs b/crates/components/src/map_view.rs index d45a0870..86609a79 100644 --- a/crates/components/src/map_view.rs +++ b/crates/components/src/map_view.rs @@ -159,7 +159,8 @@ impl MapView { }) } - // FIXME + // FIXME lots of arguments + #[allow(clippy::too_many_arguments)] pub fn ui( &mut self, ui: &mut egui::Ui, diff --git a/crates/components/src/tilepicker.rs b/crates/components/src/tilepicker.rs index 2c86bb4b..68ff9b5c 100644 --- a/crates/components/src/tilepicker.rs +++ b/crates/components/src/tilepicker.rs @@ -16,7 +16,6 @@ // along with Luminol. If not, see . use itertools::Itertools; -use slab::Slab; use std::sync::Arc; use std::time::Duration; @@ -47,8 +46,12 @@ struct Callback { coll_enabled: bool, } -// FIXME +//? SAFETY: +//? wgpu resources are not Send + Sync on wasm, but egui_wgpu::CallbackTrait requires Send + Sync (because egui::Context is Send + Sync) +//? as long as this callback does not leave the thread it was created on on wasm (which it shouldn't be) these are ok. +#[allow(unsafe_code)] unsafe impl Send for Callback {} +#[allow(unsafe_code)] unsafe impl Sync for Callback {} impl egui_wgpu::CallbackTrait for Callback { @@ -107,8 +110,6 @@ impl Default for SelectedTile { } } -type ResourcesSlab = Slab>; - impl Tilepicker { pub fn new( update_state: &luminol_core::UpdateState<'_>, diff --git a/crates/core/src/data_cache.rs b/crates/core/src/data_cache.rs index 6caba68e..14e7fadf 100644 --- a/crates/core/src/data_cache.rs +++ b/crates/core/src/data_cache.rs @@ -353,7 +353,7 @@ macro_rules! nested_ref_getter { ($($typ:ty, $name:ident),* $(,)?) => { $( #[allow(unsafe_code, dead_code)] - pub fn $name(&self) -> RefMut<$typ> { + pub fn $name(&self) -> RefMut<'_, $typ> { match self { Self::Unloaded => panic!("data cache unloaded"), Self::Loaded { $name, ..} => $name.borrow_mut(), @@ -389,7 +389,7 @@ impl Data { &self, id: usize, filesystem: &impl luminol_filesystem::FileSystem, - ) -> RefMut { + ) -> RefMut<'_, rpg::Map> { let maps_ref = match self { Self::Loaded { maps, .. } => maps.borrow_mut(), Self::Unloaded => panic!("project not loaded"), @@ -402,7 +402,7 @@ impl Data { }) } - pub fn get_map(&self, id: usize) -> RefMut { + pub fn get_map(&self, id: usize) -> RefMut<'_, rpg::Map> { let maps_ref = match self { Self::Loaded { maps, .. } => maps.borrow_mut(), Self::Unloaded => panic!("project not loaded"), diff --git a/crates/core/src/tab.rs b/crates/core/src/tab.rs index eb80266a..5d99be96 100644 --- a/crates/core/src/tab.rs +++ b/crates/core/src/tab.rs @@ -112,7 +112,7 @@ impl Tabs { } /// Display all tabs. - pub fn ui(&mut self, ui: &mut egui::Ui, update_state: &mut crate::UpdateState) { + pub fn ui(&mut self, ui: &mut egui::Ui, update_state: &mut crate::UpdateState<'_>) { let mut edit_tabs = EditTabs::default(); let mut update_state = update_state.reborrow_with_edit_tabs(&mut edit_tabs); self.ui_without_edit(ui, &mut update_state); diff --git a/crates/data/src/helpers/id_vec.rs b/crates/data/src/helpers/id_vec.rs index 179c2f83..e36c854c 100644 --- a/crates/data/src/helpers/id_vec.rs +++ b/crates/data/src/helpers/id_vec.rs @@ -24,7 +24,7 @@ where impl<'de> serde::de::Visitor<'de> for Visitor { type Value = Vec; - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { formatter.write_str("a vec of nonzero usizes") } diff --git a/crates/data/src/helpers/optional_path.rs b/crates/data/src/helpers/optional_path.rs index da081415..1351d94e 100644 --- a/crates/data/src/helpers/optional_path.rs +++ b/crates/data/src/helpers/optional_path.rs @@ -35,7 +35,7 @@ where impl serde::de::Visitor<'_> for Visitor { type Value = Option; - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { formatter.write_str("a string") } diff --git a/crates/data/src/option_vec.rs b/crates/data/src/option_vec.rs index fb9d203f..a9ecc09c 100644 --- a/crates/data/src/option_vec.rs +++ b/crates/data/src/option_vec.rs @@ -207,7 +207,7 @@ where { type Value = OptionVec; - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { formatter.write_str("a key-value mapping") } diff --git a/crates/filesystem/src/project.rs b/crates/filesystem/src/project.rs index 35fb76b4..88b4acc6 100644 --- a/crates/filesystem/src/project.rs +++ b/crates/filesystem/src/project.rs @@ -19,8 +19,6 @@ use crate::FileSystem as _; use crate::{archiver, host, list, path_cache}; use crate::{DirEntry, Error, Metadata, OpenFlags, Result}; -use itertools::Itertools; - #[derive(Default)] pub enum FileSystem { #[default] diff --git a/crates/graphics/src/event.rs b/crates/graphics/src/event.rs index 21bf0454..464e438f 100644 --- a/crates/graphics/src/event.rs +++ b/crates/graphics/src/event.rs @@ -34,8 +34,12 @@ struct Callback { graphics_state: Arc, } -// FIXME +//? SAFETY: +//? wgpu resources are not Send + Sync on wasm, but egui_wgpu::CallbackTrait requires Send + Sync (because egui::Context is Send + Sync) +//? as long as this callback does not leave the thread it was created on on wasm (which it shouldn't be) these are ok. +#[allow(unsafe_code)] unsafe impl Send for Callback {} +#[allow(unsafe_code)] unsafe impl Sync for Callback {} impl egui_wgpu::CallbackTrait for Callback { diff --git a/crates/graphics/src/map.rs b/crates/graphics/src/map.rs index 15390308..12c64221 100644 --- a/crates/graphics/src/map.rs +++ b/crates/graphics/src/map.rs @@ -57,10 +57,16 @@ struct OverlayCallback { coll_enabled: bool, } -// FIXME +//? SAFETY: +//? wgpu resources are not Send + Sync on wasm, but egui_wgpu::CallbackTrait requires Send + Sync (because egui::Context is Send + Sync) +//? as long as this callback does not leave the thread it was created on on wasm (which it shouldn't be) these are ok. +#[allow(unsafe_code)] unsafe impl Send for Callback {} +#[allow(unsafe_code)] unsafe impl Sync for Callback {} +#[allow(unsafe_code)] unsafe impl Send for OverlayCallback {} +#[allow(unsafe_code)] unsafe impl Sync for OverlayCallback {} impl egui_wgpu::CallbackTrait for Callback { diff --git a/crates/graphics/src/plane.rs b/crates/graphics/src/plane.rs index 75514f9f..dccbee2b 100644 --- a/crates/graphics/src/plane.rs +++ b/crates/graphics/src/plane.rs @@ -21,7 +21,8 @@ pub struct Plane { } impl Plane { - // FIXME: holy SHIT + // FIXME lots of arguments + #[allow(clippy::too_many_arguments)] pub fn new( graphics_state: &crate::GraphicsState, texture: std::sync::Arc, diff --git a/crates/modals/src/sound_picker.rs b/crates/modals/src/sound_picker.rs index c679be84..e76a7c1d 100644 --- a/crates/modals/src/sound_picker.rs +++ b/crates/modals/src/sound_picker.rs @@ -23,7 +23,7 @@ // Program grant you additional permission to convey the resulting work. pub struct Modal { - tab: luminol_components::SoundTab, + _tab: luminol_components::SoundTab, } impl luminol_core::Modal for Modal { diff --git a/crates/ui/src/windows/event_edit.rs b/crates/ui/src/windows/event_edit.rs index 6e5373e4..b01a4f79 100644 --- a/crates/ui/src/windows/event_edit.rs +++ b/crates/ui/src/windows/event_edit.rs @@ -22,19 +22,17 @@ // terms of the Steamworks API by Valve Corporation, the licensors of this // Program grant you additional permission to convey the resulting work. - - /// The event editor window. pub struct Window { id: usize, map_id: usize, - selected_page: usize, + _selected_page: usize, name: String, - viewed_tab: u8, + _viewed_tab: u8, - switch_modal_1: Option, - switch_modal_2: Option, - variable_modal: Option, + _switch_modal_1: Option, + _switch_modal_2: Option, + _variable_modal: Option, } impl Window { @@ -43,13 +41,13 @@ impl Window { Self { id, map_id, - selected_page: 0, + _selected_page: 0, name: String::from("(unknown)"), - viewed_tab: 2, + _viewed_tab: 2, - switch_modal_1: None, - switch_modal_2: None, - variable_modal: None, + _switch_modal_1: None, + _switch_modal_2: None, + _variable_modal: None, } } } diff --git a/crates/ui/src/windows/items.rs b/crates/ui/src/windows/items.rs index c1301b82..f1f54122 100644 --- a/crates/ui/src/windows/items.rs +++ b/crates/ui/src/windows/items.rs @@ -22,8 +22,6 @@ // terms of the Steamworks API by Valve Corporation, the licensors of this // Program grant you additional permission to convey the resulting work. -use luminol_core::Modal; - /// Database - Items management window. pub struct Window { // ? Items ? @@ -31,10 +29,10 @@ pub struct Window { selected_item: usize, // ? Icon Graphic Picker ? - icon_picker: Option, + _icon_picker: Option, // ? Menu Sound Effect Picker ? - menu_se_picker: Option, + _menu_se_picker: Option, } impl Window { @@ -45,9 +43,9 @@ impl Window { items, selected_item: 0, - icon_picker: None, + _icon_picker: None, - menu_se_picker: None, + _menu_se_picker: None, } } } diff --git a/src/app/mod.rs b/src/app/mod.rs index 764d6a8d..8e9780b2 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -53,7 +53,7 @@ pub struct App { toolbar: luminol_core::ToolbarState, #[cfg(not(target_arch = "wasm32"))] - runtime: tokio::runtime::Runtime, + _runtime: tokio::runtime::Runtime, #[cfg(feature = "steamworks")] steamworks: Steamworks, @@ -181,7 +181,7 @@ impl App { toolbar: luminol_core::ToolbarState::default(), #[cfg(not(target_arch = "wasm32"))] - runtime, + _runtime: runtime, #[cfg(feature = "steamworks")] steamworks,