Tidy up lifetimes and warnings

This commit is contained in:
Tobias Berger 2022-11-15 12:52:34 +01:00
parent 938eed66eb
commit 05ceedad82
Signed by: toby
GPG key ID: 2D05EFAB764D6A88
10 changed files with 23 additions and 57 deletions

View file

@ -1,37 +1,3 @@
#![warn(absolute_paths_not_starting_with_crate)]
#![warn(box_pointers)]
#![warn(elided_lifetimes_in_paths)]
#![warn(explicit_outlives_requirements)]
#![warn(keyword_idents)]
#![warn(macro_use_extern_crate)]
#![warn(meta_variable_misuse)]
#![warn(missing_abi)]
// #![warn(missing_copy_implementations)]
#![warn(missing_debug_implementations)]
// #![warn(missing_docs)]
#![warn(non_ascii_idents)]
#![warn(noop_method_call)]
#![warn(pointer_structural_match)]
#![warn(rust_2021_incompatible_closure_captures)]
#![warn(rust_2021_incompatible_or_patterns)]
#![warn(rust_2021_prefixes_incompatible_syntax)]
#![warn(rust_2021_prelude_collisions)]
#![warn(single_use_lifetimes)]
#![warn(trivial_casts)]
#![warn(trivial_numeric_casts)]
#![warn(unreachable_pub)]
#![warn(unsafe_code)]
#![warn(unsafe_op_in_unsafe_fn)]
#![warn(unstable_features)]
#![warn(unused_crate_dependencies)]
#![warn(unused_extern_crates)]
#![warn(unused_import_braces)]
#![warn(unused_lifetimes)]
#![warn(unused_macro_rules)]
#![warn(unused_qualifications)]
#![warn(unused_results)]
#![warn(variant_size_differences)]
pub mod world; pub mod world;
pub use world::{TerrainCell, World, WorldGenError}; pub use world::{TerrainCell, World, WorldGenError};
pub mod biome; pub mod biome;

View file

@ -26,7 +26,7 @@ impl Error for CartesianError {
} }
} }
impl Display for CartesianError { impl Display for CartesianError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self { match self {
CartesianError::InvalidAlpha(alpha) => { CartesianError::InvalidAlpha(alpha) => {
f.write_fmt(format_args!("Alpha value must be [0..PI], was {}", alpha)) f.write_fmt(format_args!("Alpha value must be [0..PI], was {}", alpha))

View file

@ -50,7 +50,7 @@ impl<'de> Deserialize<'de> for World {
impl<'de> Visitor<'de> for WorldVisitor { impl<'de> Visitor<'de> for WorldVisitor {
type Value = World; type Value = World;
fn expecting(&self, formatter: &mut Formatter<'_>) -> fmt::Result { fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
formatter.write_str("struct World") formatter.write_str("struct World")
} }

View file

@ -46,7 +46,7 @@ impl Error for WorldGenError {
} }
} }
impl Display for WorldGenError { impl Display for WorldGenError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self { match self {
WorldGenError::CartesianError(err) => Display::fmt(err, f), WorldGenError::CartesianError(err) => Display::fmt(err, f),
} }

View file

@ -38,7 +38,7 @@ impl Error for LoadError {
} }
} }
impl Display for LoadError { impl Display for LoadError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self { match self {
LoadError::MissingSave(_) => f.write_str("No save found at given path"), LoadError::MissingSave(_) => f.write_str("No save found at given path"),
LoadError::InvalidSave(_) => f.write_str("Loaded file is not a valid save"), LoadError::InvalidSave(_) => f.write_str("Loaded file is not a valid save"),
@ -70,7 +70,7 @@ impl Error for SaveError {
} }
} }
impl Display for SaveError { impl Display for SaveError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self { match self {
SaveError::MissingWorld => f.write_str("No world to save found."), SaveError::MissingWorld => f.write_str("No world to save found."),
SaveError::SerializationError(_) => f.write_str("Failed to serialize world."), SaveError::SerializationError(_) => f.write_str("Failed to serialize world."),

View file

@ -28,7 +28,7 @@ pub(crate) fn widget<S: 'static + WidgetSystem>(world: &mut World, ui: &mut Ui,
instances: HashMap::new(), instances: HashMap::new(),
}); });
} }
world.resource_scope(|world, mut states: Mut<'_, StateInstances<S>>| { world.resource_scope(|world, mut states: Mut<StateInstances<S>>| {
if !states.instances.contains_key(&id) { if !states.instances.contains_key(&id) {
debug!( debug!(
"Registering system state for widget {id:?} of type {}", "Registering system state for widget {id:?} of type {}",

View file

@ -31,7 +31,7 @@ iterable_enum!(ToolbarButton {
impl ToolbarButton { impl ToolbarButton {
fn clicked(self, world: &mut World) { fn clicked(self, world: &mut World) {
world.resource_scope(|world, mut world_manager: Mut<'_, WorldManager>| { world.resource_scope(|world, mut world_manager: Mut<WorldManager>| {
match self { match self {
ToolbarButton::GenerateWorld => { ToolbarButton::GenerateWorld => {
let generate_world_task = &mut world.resource_mut::<GenerateWorldTask>(); let generate_world_task = &mut world.resource_mut::<GenerateWorldTask>();

View file

@ -49,7 +49,7 @@ fn window<S: 'static + WindowSystem>(world: &mut World, ctx: &Context) {
instances: HashMap::new(), instances: HashMap::new(),
}); });
} }
world.resource_scope(|world, mut states: Mut<'_, StateInstances<S>>| { world.resource_scope(|world, mut states: Mut<StateInstances<S>>| {
let id: WindowId = S::name().into(); let id: WindowId = S::name().into();
if !states.instances.contains_key(&id) { if !states.instances.contains_key(&id) {
debug!( debug!(

View file

@ -37,10 +37,10 @@ use {
#[cfg(feature = "render")] #[cfg(feature = "render")]
fn update_cursor_map_position( fn update_cursor_map_position(
mut cursor_map_position: ResMut<'_, CursorMapPosition>, mut cursor_map_position: ResMut<CursorMapPosition>,
transform: Query<'_, '_, (&Camera, &GlobalTransform), With<Camera2d>>, transform: Query<(&Camera, &GlobalTransform), With<Camera2d>>,
windows: Res<'_, Windows>, windows: Res<Windows>,
world_manager: Res<'_, WorldManager>, world_manager: Res<WorldManager>,
) { ) {
let Some(world) = world_manager.get_world() else { let Some(world) = world_manager.get_world() else {
return return
@ -70,9 +70,9 @@ fn update_cursor_map_position(
} }
fn handle_generate_world_task( fn handle_generate_world_task(
mut generate_world_task: ResMut<'_, GenerateWorldTask>, mut generate_world_task: ResMut<GenerateWorldTask>,
mut world_manager: ResMut<'_, WorldManager>, mut world_manager: ResMut<WorldManager>,
#[cfg(feature = "render")] mut should_redraw: ResMut<'_, ShouldRedraw>, #[cfg(feature = "render")] mut should_redraw: ResMut<ShouldRedraw>,
) { ) {
if let Some(task) = &mut generate_world_task.0 { if let Some(task) = &mut generate_world_task.0 {
if task.is_finished() { if task.is_finished() {
@ -100,10 +100,10 @@ fn handle_generate_world_task(
#[cfg(feature = "render")] #[cfg(feature = "render")]
fn generate_graphics( fn generate_graphics(
mut commands: Commands<'_, '_>, mut commands: Commands,
images: ResMut<'_, Assets<Image>>, images: ResMut<Assets<Image>>,
egui_context: ResMut<'_, EguiContext>, egui_context: ResMut<EguiContext>,
render_settings: ResMut<'_, WorldRenderSettings>, render_settings: ResMut<WorldRenderSettings>,
) { ) {
// Add Julia-Mono font to egui // Add Julia-Mono font to egui
{ {
@ -180,7 +180,7 @@ fn open_tile_info(mut windows: ResMut<OpenedWindows>, keys: Res<Input<KeyCode>>)
#[cfg(feature = "render")] #[cfg(feature = "render")]
fn update_gui(world: &mut World) { fn update_gui(world: &mut World) {
world.resource_scope(|world, mut ctx: Mut<'_, EguiContext>| { world.resource_scope(|world, mut ctx: Mut<EguiContext>| {
let ctx = ctx.ctx_mut(); let ctx = ctx.ctx_mut();
#[cfg(feature = "logging")] #[cfg(feature = "logging")]
{ {
@ -215,9 +215,9 @@ fn update_gui(world: &mut World) {
fn redraw_map( fn redraw_map(
mut should_redraw: ResMut<ShouldRedraw>, mut should_redraw: ResMut<ShouldRedraw>,
world_manager: Res<WorldManager>, world_manager: Res<WorldManager>,
render_settings: Res<'_, WorldRenderSettings>, render_settings: Res<WorldRenderSettings>,
mut images: ResMut<Assets<Image>>, mut images: ResMut<Assets<Image>>,
mut map_sprite: Query<'_, '_, &mut Sprite>, mut map_sprite: Query<&mut Sprite>,
) { ) {
let Some(world) = world_manager.get_world() else { let Some(world) = world_manager.get_world() else {
#[cfg(feature = "logging")] #[cfg(feature = "logging")]

View file

@ -13,7 +13,7 @@ pub(crate) struct CursorMapPosition {
} }
#[cfg(feature = "render")] #[cfg(feature = "render")]
impl Display for CursorMapPosition { impl Display for CursorMapPosition {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_fmt(format_args!("x: {}, y: {}", self.x, self.y)) f.write_fmt(format_args!("x: {}, y: {}", self.x, self.y))
} }
} }