-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for
#[turbo_tasks::value(resolved)]
and `#[turbo_tasks:…
…:value_trait(resolved)]` (vercel/turborepo#8720) ### Description - `#[turbo_tasks::value(resolved)]`: This is essentially just shorthand for also doing `#[derive(ResolvedValue)]`. We'll want this on-by-default eventually, but it's strictly opt-in for now. - `#[turbo_tasks::value_trait(resolved)]`: This adds an additional supertrait for `ResolvedValue`. This wasn't quite possible to do without this flag as most supertraits are required to implement `VcValueTrait` because they're used with the `Upcast`/`Downcast` traits. ### Testing Instructions ``` TRYBUILD=overwrite cargo nextest r -p turbo-tasks-macros-tests ```
- Loading branch information
Showing
13 changed files
with
162 additions
and
16 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
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
13 changes: 13 additions & 0 deletions
13
crates/turbo-tasks-macros-tests/tests/value/fail_resolved.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 @@ | ||
#![feature(arbitrary_self_types)] | ||
|
||
use turbo_tasks::Vc; | ||
|
||
#[turbo_tasks::value(resolved)] | ||
struct MyValue { | ||
value: Vc<i32>, | ||
} | ||
|
||
fn main() { | ||
let v = MyValue { value: Vc::cell(0) }; | ||
let _ = v.value; | ||
} |
22 changes: 22 additions & 0 deletions
22
crates/turbo-tasks-macros-tests/tests/value/fail_resolved.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,22 @@ | ||
error[E0277]: the trait bound `Vc<i32>: ResolvedValue` is not satisfied | ||
--> tests/value/fail_resolved.rs:7:12 | ||
| | ||
7 | value: Vc<i32>, | ||
| ^^^^^^^ the trait `ResolvedValue` is not implemented for `Vc<i32>` | ||
| | ||
= help: the following other types implement trait `ResolvedValue`: | ||
&T | ||
&mut T | ||
() | ||
(A, Z, Y, X, W, V, U, T) | ||
(B, A, Z, Y, X, W, V, U, T) | ||
(C, B, A, Z, Y, X, W, V, U, T) | ||
(D, C, B, A, Z, Y, X, W, V, U, T) | ||
(E, D, C, B, A, Z, Y, X, W, V, U, T) | ||
and $N others | ||
note: required by a bound in `DeriveResolvedValueAssertion::assert_impl_resolved_value` | ||
--> tests/value/fail_resolved.rs:5:22 | ||
| | ||
5 | #[turbo_tasks::value(resolved)] | ||
| ^^^^^^^^ required by this bound in `DeriveResolvedValueAssertion::assert_impl_resolved_value` | ||
= note: this error originates in the derive macro `turbo_tasks::ResolvedValue` (in Nightly builds, run with -Z macro-backtrace for more info) |
14 changes: 14 additions & 0 deletions
14
crates/turbo-tasks-macros-tests/tests/value/pass_resolved.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 @@ | ||
#![feature(arbitrary_self_types)] | ||
|
||
#[turbo_tasks::value(resolved)] | ||
struct MyValue { | ||
value: i32, | ||
} | ||
|
||
fn expects_resolved<T: turbo_tasks::ResolvedValue>(value: T) {} | ||
|
||
fn main() { | ||
let v = MyValue { value: 0 }; | ||
expects_resolved(v); | ||
let _ = v.value; | ||
} |
10 changes: 10 additions & 0 deletions
10
crates/turbo-tasks-macros-tests/tests/value_trait/pass_resolved.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,10 @@ | ||
#![feature(arbitrary_self_types)] | ||
|
||
#[turbo_tasks::value_trait(resolved)] | ||
trait MyTrait {} | ||
|
||
fn expects_resolved<T: turbo_tasks::ResolvedValue + ?Sized>() {} | ||
|
||
fn main() { | ||
expects_resolved::<&dyn MyTrait>(); | ||
} |
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 was deleted.
Oops, something went wrong.
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
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