Browse Source

Better error messages when resources come at the end

Getty Ritter 4 years ago
parent
commit
3f023ea850
1 changed files with 24 additions and 29 deletions
  1. 24 29
      src/lib.rs

+ 24 - 29
src/lib.rs

@@ -1,21 +1,3 @@
-pub struct SpecsUnit;
-impl<'a> specs::SystemData<'a> for SpecsUnit {
-    fn setup(_world: &mut specs::World) {
-    }
-
-    fn fetch(_world: &'a specs::World) -> Self {
-        SpecsUnit
-    }
-
-    fn reads() -> Vec<specs::prelude::ResourceId> {
-        Vec::new()
-    }
-
-    fn writes() -> Vec<specs::prelude::ResourceId> {
-        Vec::new()
-    }
-}
-
 #[macro_export]
 macro_rules! system {
     ($name:ident ( $($pat:tt)* ) { $($rest:tt)* } ) => {
@@ -45,13 +27,18 @@ macro_rules! system {
 
 #[macro_export]
 macro_rules! args_to_systemdata {
-    ( ( ) ) => { crate::SpecsUnit };
     ( ( $name:ident : $ty:ty $(,)? ) ) => {
         ( specs::ReadStorage<'a, $ty> ,)
     };
     ( ( mut $name:ident : $ty:ty $(,)? ) ) => {
         ( specs::WriteStorage<'a, $ty> ,)
     };
+    ( ( resource $name:ident : $ty:ty $(,)? ) ) => {
+        compile_error!("Resources cannot come at the end of the argument block.")
+    };
+    ( ( resource mut $name:ident : $ty:ty $(,)? ) ) => {
+        compile_error!("Resources cannot come at the end of the argument block.")
+    };
     ( ( $name:ident : $ty:ty , $($tok:tt)* ) ) => {
         ( specs::ReadStorage<'a, $ty>, args_to_systemdata!( ( $( $tok )* ) ) )
     };
@@ -68,13 +55,18 @@ macro_rules! args_to_systemdata {
 
 #[macro_export]
 macro_rules! args_to_fn_pat {
-    ( ( ) ) => { _ };
     ( ( $name:ident : $ty:ty $(,)? ) ) => {
         ( $name ,)
     };
     ( ( mut $name:ident : $ty:ty $(,)? ) ) => {
         ( mut $name ,)
     };
+    ( ( resource $name:ident : $ty:ty $(,)? ) ) => {
+        compile_error!("Resources cannot come at the end of the argument block.")
+    };
+    ( ( resource mut $name:ident : $ty:ty $(,)? ) ) => {
+        compile_error!("Resources cannot come at the end of the argument block.")
+    };
     ( ( $name:ident : $ty:ty , $($tok:tt)* ) ) => {
         ( $name, args_to_fn_pat!( ( $($tok)* ) ) )
     };
@@ -91,13 +83,18 @@ macro_rules! args_to_fn_pat {
 
 #[macro_export]
 macro_rules! args_to_join_pat {
-    ( ( ) ) => { _ };
     ( ( $name:ident : $ty:ty $(,)? ) ) => {
         ( $name ,)
     };
     ( ( mut $name:ident : $ty:ty $(,)? ) ) => {
         ( mut $name ,)
     };
+    ( ( resource $name:ident : $ty:ty $(,)? ) ) => {
+        compile_error!("Resources cannot come at the end of the argument block.")
+    };
+    ( ( resource mut $name:ident : $ty:ty $(,)? ) ) => {
+        compile_error!("Resources cannot come at the end of the argument block.")
+    };
     ( ( $name:ident : $ty:ty , $($tok:tt)* ) ) => {
         ( $name, args_to_join_pat!( ( $($tok)* ) ) )
     };
@@ -114,13 +111,18 @@ macro_rules! args_to_join_pat {
 
 #[macro_export]
 macro_rules! args_to_join {
-    ( ( ) ) => { crate::SpecsUnit };
     ( ( $name:ident : $ty:ty $(,)? ) ) => {
         ( & $name ,)
     };
     ( ( mut $name:ident : $ty:ty $(,)? ) ) => {
         ( &mut $name ,)
     };
+    ( ( resource $name:ident : $ty:ty $(,)? ) ) => {
+        compile_error!("Resources cannot come at the end of the argument block.")
+    };
+    ( ( resource mut $name:ident : $ty:ty $(,)? ) ) => {
+        compile_error!("Resources cannot come at the end of the argument block.")
+    };
     ( ( $name:ident : $ty:ty , $($tok:tt)* ) ) => {
         ( & $name, args_to_join!( ( $($tok)* ) ) )
     };
@@ -172,11 +174,4 @@ mod tests {
         }
     }
 
-    system! {
-        Quux (resource mut n: usize, _x: Mov, mut y: Pos) {
-            y.x += *n;
-            *n += 1
-        }
-    }
-
 }