bevy/crates/bevy_ecs/compile_fail/tests/ui
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
..
entity_ref_mut_lifetime_safety.rs Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
entity_ref_mut_lifetime_safety.stderr Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
query_exact_sized_iterator_safety.rs Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
query_exact_sized_iterator_safety.stderr Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
query_iter_combinations_mut_iterator_safety.rs Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
query_iter_combinations_mut_iterator_safety.stderr Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
query_iter_many_mut_iterator_safety.rs Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
query_iter_many_mut_iterator_safety.stderr Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
query_lifetime_safety.rs Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
query_lifetime_safety.stderr Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
query_to_readonly.rs Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
query_to_readonly.stderr Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
query_transmute_safety.rs Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
query_transmute_safety.stderr Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
system_param_derive_readonly.rs Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
system_param_derive_readonly.stderr Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
system_query_get_lifetime_safety.rs Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
system_query_get_lifetime_safety.stderr Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
system_query_get_many_lifetime_safety.rs Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
system_query_get_many_lifetime_safety.stderr Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
system_query_get_many_mut_lifetime_safety.rs Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
system_query_get_many_mut_lifetime_safety.stderr Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
system_query_iter_lifetime_safety.rs Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
system_query_iter_lifetime_safety.stderr Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
system_query_iter_many_mut_lifetime_safety.rs Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
system_query_iter_many_mut_lifetime_safety.stderr Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
system_query_set_get_lifetime_safety.rs Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
system_query_set_get_lifetime_safety.stderr Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
system_query_set_iter_lifetime_safety.rs Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
system_query_set_iter_lifetime_safety.stderr Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
system_state_get_lifetime_safety.rs Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
system_state_get_lifetime_safety.stderr Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
system_state_iter_lifetime_safety.rs Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
system_state_iter_lifetime_safety.stderr Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
system_state_iter_mut_overlap_safety.rs Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
system_state_iter_mut_overlap_safety.stderr Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
world_query_derive.rs bevy_ecs: Replace panics in QueryData derive compile errors (#15691) 2024-10-07 16:30:34 +00:00
world_query_derive.stderr Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00