-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added bevy_macros_compile_fail_tests crate
Created with compile tests for the Deref/DerefMut derives
- Loading branch information
Showing
25 changed files
with
396 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "bevy_macros_compile_fail_tests" | ||
version = "0.1.0" | ||
edition = "2021" | ||
description = "Compile fail tests for Bevy Engine's various macros" | ||
homepage = "https://bevyengine.org" | ||
repository = "/~https://github.com/bevyengine/bevy" | ||
license = "MIT OR Apache-2.0" | ||
publish = false | ||
|
||
[dependencies] | ||
bevy_derive = { path = "../bevy_derive" } | ||
trybuild = "1.0.71" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Compile fail tests for Bevy macros | ||
|
||
This crate is 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](../../tools/ci/src/main.rs)). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// Nothing here, check out the integration tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#[test] | ||
fn test() { | ||
let t = trybuild::TestCases::new(); | ||
t.compile_fail("tests/deref_derive/*.fail.rs"); | ||
t.pass("tests/deref_derive/*.pass.rs"); | ||
} |
9 changes: 9 additions & 0 deletions
9
crates/bevy_macros_compile_fail_tests/tests/deref_derive/invalid_item.fail.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use bevy_derive::Deref; | ||
|
||
#[derive(Deref)] | ||
struct UnitStruct; | ||
|
||
#[derive(Deref)] | ||
enum Enum {} | ||
|
||
fn main() {} |
15 changes: 15 additions & 0 deletions
15
crates/bevy_macros_compile_fail_tests/tests/deref_derive/invalid_item.fail.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error: Deref cannot be derived on field-less structs | ||
--> tests/deref_derive/invalid_item.fail.rs:3:10 | ||
| | ||
3 | #[derive(Deref)] | ||
| ^^^^^ | ||
| | ||
= note: this error originates in the derive macro `Deref` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: Deref can only be derived on structs | ||
--> tests/deref_derive/invalid_item.fail.rs:6:10 | ||
| | ||
6 | #[derive(Deref)] | ||
| ^^^^^ | ||
| | ||
= note: this error originates in the derive macro `Deref` (in Nightly builds, run with -Z macro-backtrace for more info) |
12 changes: 12 additions & 0 deletions
12
crates/bevy_macros_compile_fail_tests/tests/deref_derive/missing_attribute.fail.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use bevy_derive::Deref; | ||
|
||
#[derive(Deref)] | ||
struct TupleStruct(usize, String); | ||
|
||
#[derive(Deref)] | ||
struct Struct { | ||
foo: usize, | ||
bar: String, | ||
} | ||
|
||
fn main() {} |
15 changes: 15 additions & 0 deletions
15
crates/bevy_macros_compile_fail_tests/tests/deref_derive/missing_attribute.fail.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error: deriving Deref on multi-field structs requires one field to have the `#[deref]` attribute | ||
--> tests/deref_derive/missing_attribute.fail.rs:3:10 | ||
| | ||
3 | #[derive(Deref)] | ||
| ^^^^^ | ||
| | ||
= note: this error originates in the derive macro `Deref` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: deriving Deref on multi-field structs requires one field to have the `#[deref]` attribute | ||
--> tests/deref_derive/missing_attribute.fail.rs:6:10 | ||
| | ||
6 | #[derive(Deref)] | ||
| ^^^^^ | ||
| | ||
= note: this error originates in the derive macro `Deref` (in Nightly builds, run with -Z macro-backtrace for more info) |
14 changes: 14 additions & 0 deletions
14
crates/bevy_macros_compile_fail_tests/tests/deref_derive/multiple_attributes.fail.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use bevy_derive::Deref; | ||
|
||
#[derive(Deref)] | ||
struct TupleStruct(#[deref] usize, #[deref] String); | ||
|
||
#[derive(Deref)] | ||
struct Struct { | ||
#[deref] | ||
foo: usize, | ||
#[deref] | ||
bar: String, | ||
} | ||
|
||
fn main() {} |
11 changes: 11 additions & 0 deletions
11
crates/bevy_macros_compile_fail_tests/tests/deref_derive/multiple_attributes.fail.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error: `#[deref]` attribute can only be used on a single field | ||
--> tests/deref_derive/multiple_attributes.fail.rs:4:36 | ||
| | ||
4 | struct TupleStruct(#[deref] usize, #[deref] String); | ||
| ^^^^^^^^ | ||
|
||
error: `#[deref]` attribute can only be used on a single field | ||
--> tests/deref_derive/multiple_attributes.fail.rs:10:5 | ||
| | ||
10 | #[deref] | ||
| ^^^^^^^^ |
22 changes: 22 additions & 0 deletions
22
crates/bevy_macros_compile_fail_tests/tests/deref_derive/multiple_fields.pass.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use bevy_derive::Deref; | ||
|
||
#[derive(Deref)] | ||
struct TupleStruct(usize, #[deref] String); | ||
|
||
#[derive(Deref)] | ||
struct Struct { | ||
foo: usize, | ||
#[deref] | ||
bar: String, | ||
} | ||
|
||
fn main() { | ||
let value = TupleStruct(123, "Hello world!".to_string()); | ||
let _: &String = &*value; | ||
|
||
let value = Struct { | ||
foo: 123, | ||
bar: "Hello world!".to_string(), | ||
}; | ||
let _: &String = &*value; | ||
} |
6 changes: 6 additions & 0 deletions
6
crates/bevy_macros_compile_fail_tests/tests/deref_mut_derive.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#[test] | ||
fn test() { | ||
let t = trybuild::TestCases::new(); | ||
t.compile_fail("tests/deref_mut_derive/*.fail.rs"); | ||
t.pass("tests/deref_mut_derive/*.pass.rs"); | ||
} |
9 changes: 9 additions & 0 deletions
9
crates/bevy_macros_compile_fail_tests/tests/deref_mut_derive/invalid_item.fail.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use bevy_derive::DerefMut; | ||
|
||
#[derive(DerefMut)] | ||
struct UnitStruct; | ||
|
||
#[derive(DerefMut)] | ||
enum Enum {} | ||
|
||
fn main() {} |
15 changes: 15 additions & 0 deletions
15
crates/bevy_macros_compile_fail_tests/tests/deref_mut_derive/invalid_item.fail.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error: DerefMut cannot be derived on field-less structs | ||
--> tests/deref_mut_derive/invalid_item.fail.rs:3:10 | ||
| | ||
3 | #[derive(DerefMut)] | ||
| ^^^^^^^^ | ||
| | ||
= note: this error originates in the derive macro `DerefMut` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: DerefMut can only be derived on structs | ||
--> tests/deref_mut_derive/invalid_item.fail.rs:6:10 | ||
| | ||
6 | #[derive(DerefMut)] | ||
| ^^^^^^^^ | ||
| | ||
= note: this error originates in the derive macro `DerefMut` (in Nightly builds, run with -Z macro-backtrace for more info) |
30 changes: 30 additions & 0 deletions
30
crates/bevy_macros_compile_fail_tests/tests/deref_mut_derive/mismatched_target_type.fail.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use bevy_derive::DerefMut; | ||
use std::ops::Deref; | ||
|
||
#[derive(DerefMut)] | ||
struct TupleStruct(#[deref] usize, String); | ||
|
||
impl Deref for TupleStruct { | ||
type Target = String; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.1 | ||
} | ||
} | ||
|
||
#[derive(DerefMut)] | ||
struct Struct { | ||
#[deref] | ||
foo: usize, | ||
bar: String, | ||
} | ||
|
||
impl Deref for Struct { | ||
type Target = String; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.bar | ||
} | ||
} | ||
|
||
fn main() {} |
25 changes: 25 additions & 0 deletions
25
.../bevy_macros_compile_fail_tests/tests/deref_mut_derive/mismatched_target_type.fail.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
error[E0308]: mismatched types | ||
--> tests/deref_mut_derive/mismatched_target_type.fail.rs:4:10 | ||
| | ||
4 | #[derive(DerefMut)] | ||
| ^^^^^^^^ | ||
| | | ||
| expected `&mut String`, found `&mut usize` | ||
| expected `&mut String` because of return type | ||
| | ||
= note: expected mutable reference `&mut String` | ||
found mutable reference `&mut usize` | ||
= note: this error originates in the derive macro `DerefMut` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0308]: mismatched types | ||
--> tests/deref_mut_derive/mismatched_target_type.fail.rs:15:10 | ||
| | ||
15 | #[derive(DerefMut)] | ||
| ^^^^^^^^ | ||
| | | ||
| expected `&mut String`, found `&mut usize` | ||
| expected `&mut String` because of return type | ||
| | ||
= note: expected mutable reference `&mut String` | ||
found mutable reference `&mut usize` | ||
= note: this error originates in the derive macro `DerefMut` (in Nightly builds, run with -Z macro-backtrace for more info) |
29 changes: 29 additions & 0 deletions
29
crates/bevy_macros_compile_fail_tests/tests/deref_mut_derive/missing_attribute.fail.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use bevy_derive::DerefMut; | ||
use std::ops::Deref; | ||
|
||
#[derive(DerefMut)] | ||
struct TupleStruct(usize, String); | ||
|
||
impl Deref for TupleStruct { | ||
type Target = String; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.1 | ||
} | ||
} | ||
|
||
#[derive(DerefMut)] | ||
struct Struct { | ||
foo: usize, | ||
bar: String, | ||
} | ||
|
||
impl Deref for Struct { | ||
type Target = String; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.bar | ||
} | ||
} | ||
|
||
fn main() {} |
15 changes: 15 additions & 0 deletions
15
crates/bevy_macros_compile_fail_tests/tests/deref_mut_derive/missing_attribute.fail.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error: deriving DerefMut on multi-field structs requires one field to have the `#[deref]` attribute | ||
--> tests/deref_mut_derive/missing_attribute.fail.rs:4:10 | ||
| | ||
4 | #[derive(DerefMut)] | ||
| ^^^^^^^^ | ||
| | ||
= note: this error originates in the derive macro `DerefMut` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: deriving DerefMut on multi-field structs requires one field to have the `#[deref]` attribute | ||
--> tests/deref_mut_derive/missing_attribute.fail.rs:15:10 | ||
| | ||
15 | #[derive(DerefMut)] | ||
| ^^^^^^^^ | ||
| | ||
= note: this error originates in the derive macro `DerefMut` (in Nightly builds, run with -Z macro-backtrace for more info) |
13 changes: 13 additions & 0 deletions
13
crates/bevy_macros_compile_fail_tests/tests/deref_mut_derive/missing_deref.fail.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use bevy_derive::DerefMut; | ||
|
||
#[derive(DerefMut)] | ||
struct TupleStruct(usize, #[deref] String); | ||
|
||
#[derive(DerefMut)] | ||
struct Struct { | ||
foo: usize, | ||
#[deref] | ||
bar: String, | ||
} | ||
|
||
fn main() {} |
39 changes: 39 additions & 0 deletions
39
crates/bevy_macros_compile_fail_tests/tests/deref_mut_derive/missing_deref.fail.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
error[E0277]: the trait bound `TupleStruct: Deref` is not satisfied | ||
--> tests/deref_mut_derive/missing_deref.fail.rs:4:8 | ||
| | ||
4 | struct TupleStruct(usize, #[deref] String); | ||
| ^^^^^^^^^^^ the trait `Deref` is not implemented for `TupleStruct` | ||
| | ||
note: required by a bound in `DerefMut` | ||
--> $RUST/core/src/ops/deref.rs | ||
| | ||
| pub trait DerefMut: Deref { | ||
| ^^^^^ required by this bound in `DerefMut` | ||
|
||
error[E0277]: the trait bound `Struct: Deref` is not satisfied | ||
--> tests/deref_mut_derive/missing_deref.fail.rs:7:8 | ||
| | ||
7 | struct Struct { | ||
| ^^^^^^ the trait `Deref` is not implemented for `Struct` | ||
| | ||
note: required by a bound in `DerefMut` | ||
--> $RUST/core/src/ops/deref.rs | ||
| | ||
| pub trait DerefMut: Deref { | ||
| ^^^^^ required by this bound in `DerefMut` | ||
|
||
error[E0277]: the trait bound `TupleStruct: Deref` is not satisfied | ||
--> tests/deref_mut_derive/missing_deref.fail.rs:3:10 | ||
| | ||
3 | #[derive(DerefMut)] | ||
| ^^^^^^^^ the trait `Deref` is not implemented for `TupleStruct` | ||
| | ||
= note: this error originates in the derive macro `DerefMut` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0277]: the trait bound `Struct: Deref` is not satisfied | ||
--> tests/deref_mut_derive/missing_deref.fail.rs:6:10 | ||
| | ||
6 | #[derive(DerefMut)] | ||
| ^^^^^^^^ the trait `Deref` is not implemented for `Struct` | ||
| | ||
= note: this error originates in the derive macro `DerefMut` (in Nightly builds, run with -Z macro-backtrace for more info) |
31 changes: 31 additions & 0 deletions
31
crates/bevy_macros_compile_fail_tests/tests/deref_mut_derive/multiple_attributes.fail.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use bevy_derive::DerefMut; | ||
use std::ops::Deref; | ||
|
||
#[derive(DerefMut)] | ||
struct TupleStruct(#[deref] usize, #[deref] String); | ||
|
||
impl Deref for TupleStruct { | ||
type Target = String; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.1 | ||
} | ||
} | ||
|
||
#[derive(DerefMut)] | ||
struct Struct { | ||
#[deref] | ||
foo: usize, | ||
#[deref] | ||
bar: String, | ||
} | ||
|
||
impl Deref for Struct { | ||
type Target = String; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.bar | ||
} | ||
} | ||
|
||
fn main() {} |
11 changes: 11 additions & 0 deletions
11
crates/bevy_macros_compile_fail_tests/tests/deref_mut_derive/multiple_attributes.fail.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error: `#[deref]` attribute can only be used on a single field | ||
--> tests/deref_mut_derive/multiple_attributes.fail.rs:5:36 | ||
| | ||
5 | struct TupleStruct(#[deref] usize, #[deref] String); | ||
| ^^^^^^^^ | ||
|
||
error: `#[deref]` attribute can only be used on a single field | ||
--> tests/deref_mut_derive/multiple_attributes.fail.rs:19:5 | ||
| | ||
19 | #[deref] | ||
| ^^^^^^^^ |
Oops, something went wrong.