You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
983: Handle generics in NativeScript derive and `#[methods]` r=chitoyuu a=chitoyuu
The derive macros are now aware of both lifetime and type parameters. `'static` bounds are added to both kinds, which improves the error message shown when a user tries to put a lifetime into a NativeClass.
This behavior is chosen because unlike type parameters, lifetime parameters aren't very useful in this context: only `'static` would be supported anyway, and any attempted usage is hightly likely to have originated from user error.
Also added the `#[skip]` attribute for skipping fields in `FromVarargs`. This is useful mainly for skipping marker fields in generic code.
Close#601
## Error message
The error message that appears when lifetime parameters are declared for `NativeClass` types now clearly indicate where the problem lies and what the expectations are:
```
error[E0478]: lifetime bound not satisfied
--> tests/ui/derive_fail_lifetime.rs:3:10
|
3 | #[derive(NativeClass)]
| ^^^^^^^^^^^
|
note: lifetime parameter instantiated with the lifetime `'a` as defined here
--> tests/ui/derive_fail_lifetime.rs:4:12
|
4 | struct Foo<'a> {
| ^^
= note: but lifetime parameter must outlive the static lifetime
= note: this error originates in the derive macro `NativeClass` (in Nightly builds, run with -Z macro-backtrace for more info)
```
Compares this with the old error message:
```
error[E0726]: implicit elided lifetime not allowed here
--> tests/ui/derive_fail_lifetime.rs:4:8
|
4 | struct Foo<'a> {
| ^^^ expected lifetime parameter
|
= note: assuming a `'static` lifetime...
help: indicate the anonymous lifetime
|
4 | struct Foo<'_><'a> {
| ++++
error[E0106]: missing lifetime specifier
--> tests/ui/derive_fail_lifetime.rs:4:8
|
4 | struct Foo<'a> {
| ^^^ expected named lifetime parameter
|
help: consider introducing a named lifetime parameter
|
3 ~ #[derive(NativeClass<'a>)]
4 ~ struct Foo<'a><'a> {
|
error[E0277]: the trait bound `&gdnative::prelude::Node: OwnerArg<'_, Reference, Shared
>` is not satisfied
--> tests/ui/derive_fail_lifetime.rs:3:10
|
3 | #[derive(NativeClass)]
| ^^^^^^^^^^^ the trait `OwnerArg<'_, Reference, Shared>` is not implemented
for `&gdnative::prelude::Node`
|
= help: the following other types implement trait `OwnerArg<'a, T, Own>`:
&'a T
TRef<'a, T, Own>
= note: this error originates in the derive macro `NativeClass` (in Nightly builds, r
un with -Z macro-backtrace for more info)
```
Close#174
Co-authored-by: Chitose Yuuzaki <chitoyuu@potatoes.gay>
0 commit comments