bevy/crates
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
..
bevy_a11y Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
bevy_animation Fixes to animation graph evaluation (#15689) 2024-10-07 07:30:00 +00:00
bevy_app Documentation for variadics (#15387) 2024-10-02 12:48:36 +00:00
bevy_asset Fix doc comment (#15673) 2024-10-06 08:12:58 +00:00
bevy_audio Fix audio not playing (#15638) 2024-10-04 01:07:09 +00:00
bevy_color Eliminate redundant clamping from sample-interpolated curves (#15620) 2024-10-03 18:26:41 +00:00
bevy_core Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
bevy_core_pipeline Deprecate get_or_spawn (#15652) 2024-10-07 16:08:22 +00:00
bevy_derive move ANDROID_APP to bevy_window (#15585) 2024-10-02 03:01:06 +00:00
bevy_dev_tools Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
bevy_diagnostic Update sysinfo requirement from 0.31.0 to 0.32.0 (#15697) 2024-10-07 07:31:17 +00:00
bevy_dylib Generate links to definition in source code pages on docs.rs and dev-docs.bevyengine.org (#12965) 2024-07-29 23:10:16 +00:00
bevy_ecs bevy_ecs: Replace panics in QueryData derive compile errors (#15691) 2024-10-07 16:30:34 +00:00
bevy_encase_derive Update `glam to 0.29, encase` to 0.10. (#15249) 2024-09-23 19:44:02 +00:00
bevy_gilrs Implement gamepads as entities (#12770) 2024-09-27 20:07:20 +00:00
bevy_gizmos Use circle gizmos for capsule (#15602) 2024-10-02 19:47:56 +00:00
bevy_gltf Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
bevy_hierarchy Add more tools for traversing hierarchies (#15627) 2024-10-07 15:24:57 +00:00
bevy_image Add Image methods for easy access to a pixel's color (#10392) 2024-10-07 14:38:41 +00:00
bevy_input Revert "Have EntityCommands methods consume self for easier chaining" (#15523) 2024-10-02 12:47:26 +00:00
bevy_internal Inverse bevy_render bevy_winit dependency and move cursor to bevy_winit (#15649) 2024-10-06 18:25:50 +00:00
bevy_log Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
bevy_macro_utils Modify derive_label to support no_std environments (#15465) 2024-09-27 20:23:26 +00:00
bevy_math Add most common interpolations (#15675) 2024-10-07 15:56:06 +00:00
bevy_mesh Split out bevy_mesh from bevy_render (#15666) 2024-10-06 14:18:11 +00:00
bevy_mikktspace Add no_std support to bevy_mikktspace (#15528) 2024-09-30 18:17:03 +00:00
bevy_pbr Deprecate get_or_spawn (#15652) 2024-10-07 16:08:22 +00:00
bevy_picking Migrate bevy picking (#15690) 2024-10-07 16:26:37 +00:00
bevy_ptr Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
bevy_reflect Documentation for variadics (#15387) 2024-10-02 12:48:36 +00:00
bevy_remote Allow World::entity family of functions to take multiple entities and get multiple references back (#15614) 2024-10-07 15:21:40 +00:00
bevy_render Deprecate get_or_spawn (#15652) 2024-10-07 16:08:22 +00:00
bevy_scene Allow World::entity family of functions to take multiple entities and get multiple references back (#15614) 2024-10-07 15:21:40 +00:00
bevy_sprite Split out bevy_mesh from bevy_render (#15666) 2024-10-06 14:18:11 +00:00
bevy_state Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
bevy_tasks bump async-channel to 2.3.0 (#15497) 2024-09-28 19:21:59 +00:00
bevy_text Fix text measurement when multiple font sizes are present (#15669) 2024-10-05 22:46:37 +00:00
bevy_time Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
bevy_transform Allow World::entity family of functions to take multiple entities and get multiple references back (#15614) 2024-10-07 15:21:40 +00:00
bevy_ui Deprecate get_or_spawn (#15652) 2024-10-07 16:08:22 +00:00
bevy_utils Minor fixes for bevy_utils in no_std (#15463) 2024-10-04 19:25:49 +00:00
bevy_window Fix bevy_window and bevy_winit readme badges (#15637) 2024-10-04 00:38:49 +00:00
bevy_winit Inverse bevy_render bevy_winit dependency and move cursor to bevy_winit (#15649) 2024-10-06 18:25:50 +00:00