2
0
Fork 0
mirror of https://github.com/bevyengine/bevy synced 2024-12-30 15:03:23 +00:00
bevy/crates/bevy_ecs/compile_fail
Gino Valente 8039f34b0d
bevy_ecs: Replace panics in QueryData derive compile errors ()
# 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
..
src Move compile fail tests () 2024-05-03 13:35:21 +00:00
tests bevy_ecs: Replace panics in QueryData derive compile errors () 2024-10-07 16:30:34 +00:00
.gitignore Move compile fail tests () 2024-05-03 13:35:21 +00:00
Cargo.toml Update compile test to use ui_test 0.23 () 2024-05-05 22:17:56 +00:00
README.md Move compile fail tests () 2024-05-03 13:35:21 +00:00

Compile fail tests for bevy_ecs

This crate is separate from bevy_ecs and not part of the Bevy workspace in order to not fail crater tests for Bevy. The tests assert on the exact compiler errors and can easily fail for new Rust versions due to updated compiler errors (e.g. changes in spans).

The CI workflow executes these tests on the stable rust toolchain (see tools/ci).

For information on writing tests see compile_fail_utils/README.md.