bevy/crates/bevy_ecs/macros/src
Gino Valente 8039f34b0d
bevy_ecs: Replace panics in QueryData derive compile errors (#15691)
# Objective

The current `QueryData` derive panics when it encounters an error.
Additionally, it doesn't provide the clearest error message:

```rust
#[derive(QueryData)]
#[query_data(mut)]
struct Foo {
    // ...
}
```

```
error: proc-macro derive panicked
  --> src/foo.rs:16:10
   |
16 | #[derive(QueryData)]
   |          ^^^^^^^^^
   |
   = help: message: Invalid `query_data` attribute format
```

## Solution

Updated the derive logic to not panic and gave a bit more detail in the
error message.

This is makes the error message just a bit clearer and maintains the
correct span:

```
error: invalid attribute, expected `mutable` or `derive`
  --> src/foo.rs:17:14
   |
17 | #[query_data(mut)]
   |              ^^^
```

## Testing

You can test locally by running the following in
`crates/bevy_ecs/compile_fail`:

```
cargo test --target-dir ../../../target
```
2024-10-07 16:30:34 +00:00
..
component.rs Allow a closure to be used as a required component default (#15269) 2024-10-04 00:34:39 +00:00
lib.rs Implement SystemParam::queue() method for blanket implementation of ParamSet (#15599) 2024-10-02 19:46:50 +00:00
query_data.rs bevy_ecs: Replace panics in QueryData derive compile errors (#15691) 2024-10-07 16:30:34 +00:00
query_filter.rs Make QueryFilter an unsafe trait (#14790) 2024-09-09 15:23:12 +00:00
states.rs Computed State & Sub States (#11426) 2024-05-02 19:36:23 +00:00
world_query.rs Allow to expect (adopted) (#15301) 2024-09-20 19:16:42 +00:00