diff --git a/.config/ast-grep/rule-tests/__snapshots__/resolved-vc-in-return-type-snapshot.yml b/.config/ast-grep/rule-tests/__snapshots__/resolved-vc-in-return-type-snapshot.yml new file mode 100644 index 0000000000000..61e11ed047484 --- /dev/null +++ b/.config/ast-grep/rule-tests/__snapshots__/resolved-vc-in-return-type-snapshot.yml @@ -0,0 +1,89 @@ +id: resolved-vc-in-return-type +snapshots: + ? | + #[turbo_tasks::function] + pub async fn flag_this(x: ResolvedVc) -> ResolvedVc {} + : fixed: | + #[turbo_tasks::function] + pub async fn flag_this(x: ResolvedVc) -> Vc {} + labels: + - source: ResolvedVc + style: primary + start: 74 + end: 92 + - source: flag_this + style: secondary + start: 38 + end: 47 + - source: '#[turbo_tasks::function]' + style: secondary + start: 0 + end: 24 + - source: 'pub async fn flag_this(x: ResolvedVc) -> ResolvedVc {}' + style: secondary + start: 25 + end: 95 + ? | + #[turbo_tasks::function] + pub async fn flag_this_too(x: ResolvedVc) -> Result> {} + : fixed: | + #[turbo_tasks::function] + pub async fn flag_this_too(x: ResolvedVc) -> Result> {} + labels: + - source: ResolvedVc + style: primary + start: 85 + end: 103 + - source: flag_this_too + style: secondary + start: 38 + end: 51 + - source: '#[turbo_tasks::function]' + style: secondary + start: 0 + end: 24 + - source: 'pub async fn flag_this_too(x: ResolvedVc) -> Result> {}' + style: secondary + start: 25 + end: 107 + ? | + #[turbo_tasks::value_trait] + pub trait ValueTrait() { + fn flag_this() -> ResolvedVc; + } + : fixed: | + #[turbo_tasks::value_trait] + pub trait ValueTrait() { + fn flag_this() -> Vc; + } + labels: + - source: ResolvedVc + style: primary + start: 75 + end: 93 + - source: '#[turbo_tasks::value_trait]' + style: secondary + start: 0 + end: 27 + - source: |- + pub trait ValueTrait() { + fn flag_this() -> ResolvedVc; + } + style: secondary + start: 28 + end: 96 + - source: |- + pub trait ValueTrait() { + fn flag_this() -> ResolvedVc; + } + style: secondary + start: 28 + end: 96 + - source: flag_this + style: secondary + start: 60 + end: 69 + - source: fn flag_this() -> ResolvedVc; + style: secondary + start: 57 + end: 94 diff --git a/.config/ast-grep/rule-tests/__snapshots__/resolved-vc-in-trait-arguments-snapshot.yml b/.config/ast-grep/rule-tests/__snapshots__/resolved-vc-in-trait-arguments-snapshot.yml new file mode 100644 index 0000000000000..33d59d73d375d --- /dev/null +++ b/.config/ast-grep/rule-tests/__snapshots__/resolved-vc-in-trait-arguments-snapshot.yml @@ -0,0 +1,39 @@ +id: resolved-vc-in-trait-arguments +snapshots: + ? | + #[turbo_tasks::value_trait] + pub trait Example { + fn write_to_disk(self: ResolvedVc); + } + : fixed: | + #[turbo_tasks::value_trait] + pub trait Example { + fn write_to_disk(self: Vc); + } + labels: + - source: ResolvedVc + style: primary + start: 75 + end: 91 + - source: '#[turbo_tasks::value_trait]' + style: secondary + start: 0 + end: 27 + - source: |- + pub trait Example { + fn write_to_disk(self: ResolvedVc); + } + style: secondary + start: 28 + end: 95 + - source: |- + pub trait Example { + fn write_to_disk(self: ResolvedVc); + } + style: secondary + start: 28 + end: 95 + - source: 'fn write_to_disk(self: ResolvedVc);' + style: secondary + start: 52 + end: 93 diff --git a/.config/ast-grep/rule-tests/resolved-vc-in-return-type-test.yml b/.config/ast-grep/rule-tests/resolved-vc-in-return-type-test.yml new file mode 100644 index 0000000000000..6dc6f99195cb6 --- /dev/null +++ b/.config/ast-grep/rule-tests/resolved-vc-in-return-type-test.yml @@ -0,0 +1,20 @@ +id: resolved-vc-in-return-type +valid: + - | + pub async fn ignore_this(x: ResolvedVc) -> Result> {} + - | + pub trait OtherTrait() { + fn ignore_this() -> ResolvedVc; + } +invalid: + - | + #[turbo_tasks::function] + pub async fn flag_this(x: ResolvedVc) -> ResolvedVc {} + - | + #[turbo_tasks::function] + pub async fn flag_this_too(x: ResolvedVc) -> Result> {} + - | + #[turbo_tasks::value_trait] + pub trait ValueTrait() { + fn flag_this() -> ResolvedVc; + } diff --git a/.config/ast-grep/rule-tests/resolved-vc-in-trait-arguments-test.yml b/.config/ast-grep/rule-tests/resolved-vc-in-trait-arguments-test.yml new file mode 100644 index 0000000000000..c16a9cf9958fd --- /dev/null +++ b/.config/ast-grep/rule-tests/resolved-vc-in-trait-arguments-test.yml @@ -0,0 +1,14 @@ +id: resolved-vc-in-trait-arguments +valid: + - | + #[turbo_tasks::value_trait] + pub trait Example { + fn write_to_disk(self: Vc); + fn write_to_disk(self: ResolvedVc) {} + } +invalid: + - | + #[turbo_tasks::value_trait] + pub trait Example { + fn write_to_disk(self: ResolvedVc); + } diff --git a/.config/ast-grep/rules/resolved-vc-in-return-type.yml b/.config/ast-grep/rules/resolved-vc-in-return-type.yml new file mode 100644 index 0000000000000..cf63e3a225474 --- /dev/null +++ b/.config/ast-grep/rules/resolved-vc-in-return-type.yml @@ -0,0 +1,52 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/main/schemas/rule.json + +id: resolved-vc-in-return-type +message: Returning a `ResolvedVc` in a turbo task is not recommended. Consider replacing `$TYPE` in `$FN_NAME` with `$RESOLVED_VC` instead. +severity: warning # error, warning, info, hint +language: Rust +rule: + any: + # turbo tasks function + - all: + - pattern: + context: 'let x: ResolvedVc<$A> = 1;' + selector: generic_type + - pattern: $TYPE + inside: + kind: function_item + field: return_type + stopBy: end + follows: + pattern: '#[turbo_tasks::function]' + has: + kind: identifier + pattern: $FN_NAME + # turbo tasks value trait + - all: + - pattern: + context: 'let x: ResolvedVc<$A> = 1;' + selector: generic_type + - pattern: $TYPE + inside: + kind: function_signature_item + field: return_type + stopBy: end + inside: + inside: + kind: trait_item + follows: + pattern: '#[turbo_tasks::value_trait]' + has: + kind: identifier + pattern: $FN_NAME +rewriters: + - id: rewrite-vc + rule: + pattern: $TYPE + fix: Vc<$A> +transform: + RESOLVED_VC: + rewrite: + rewriters: [rewrite-vc] + source: $TYPE +fix: $RESOLVED_VC diff --git a/.config/ast-grep/rules/resolved-vc-in-trait.yml b/.config/ast-grep/rules/resolved-vc-in-trait.yml new file mode 100644 index 0000000000000..4a910516c28cd --- /dev/null +++ b/.config/ast-grep/rules/resolved-vc-in-trait.yml @@ -0,0 +1,20 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/main/schemas/rule.json + +id: resolved-vc-in-trait-arguments +message: Using `ResolvedVc` in a turbo tasks trait is unsound. Consider making `$FN_NAME` take `Vc` instead. +severity: warning # error, warning, info, hint +language: Rust +rule: + pattern: + context: 'let x: ResolvedVc<$A> = 1;' + selector: generic_type + inside: + kind: function_signature_item + stopBy: end + pattern: fn $FN_NAME($_ARGS) + inside: + inside: + kind: trait_item + follows: + pattern: '#[turbo_tasks::value_trait]' +fix: Vc<$A> diff --git a/.config/ast-grep/rules/to-resolved-in-loop.yml b/.config/ast-grep/rules/to-resolved-in-loop.yml new file mode 100644 index 0000000000000..7099720fb78b7 --- /dev/null +++ b/.config/ast-grep/rules/to-resolved-in-loop.yml @@ -0,0 +1,30 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/main/schemas/rule.json + +id: to-resolved-in-loop +message: 'Calling `$EXPR` in a loop could be a doing a lot of work sequentially. Consider producing an iterator of futures and using `try_join`.' +severity: info # error, warning, info, hint +language: Rust +rule: + kind: for_expression + pattern: for $VAR in $ITER {$$$_ARGS} + has: + kind: try_expression + stopBy: end + all: + - pattern: $ARG.to_resolved().await? + - pattern: $EXPR + # ignore sequential application + - not: + inside: + kind: assignment_expression + pattern: '*$VAR = $_EXPR' + # ignore conditionals via match + - not: + inside: + kind: match_arm + stopBy: end + # ignore conditionals via if + - not: + inside: + kind: if_expression + stopBy: end