diff --git a/.config/ast-grep/rules/resolved-vc.yml b/.config/ast-grep/rules/resolved-vc.yml new file mode 100644 index 0000000000000..5dacc94ad70bf --- /dev/null +++ b/.config/ast-grep/rules/resolved-vc.yml @@ -0,0 +1,42 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/main/schemas/rule.json + +id: no-vc-struct +message: Don't use a Vc directly in a struct +note: 'Prefer using ResolvedVc, or add a `// no-resolved-vc(): ` comment' +severity: warning +language: rust + +rule: + pattern: + context: 'let x: Vc<$A> = 1;' + selector: generic_type + inside: + stopBy: end + not: + follows: + kind: line_comment + regex: \s*//\s*no-resolved-vc\((.+)\):.+ + inside: + inside: + any: + - kind: struct_item + follows: + stopBy: + not: + kind: attribute_item + kind: attribute_item + has: + kind: attribute + regex: '^turbo_tasks::value(\(.*\))?$' + - inside: + kind: enum_variant_list + inside: + follows: + stopBy: + not: + kind: attribute_item + kind: attribute_item + has: + kind: attribute + regex: '^turbo_tasks::value(\(.*\))?$' +fix: ResolvedVc<$A> diff --git a/turbopack/crates/turbo-tasks/src/vc/resolved.rs b/turbopack/crates/turbo-tasks/src/vc/resolved.rs index 77bca100563cf..3bfb2bd2e8e32 100644 --- a/turbopack/crates/turbo-tasks/src/vc/resolved.rs +++ b/turbopack/crates/turbo-tasks/src/vc/resolved.rs @@ -36,6 +36,7 @@ pub struct ResolvedVc where T: ?Sized, { + // no-resolved-vc(kdy1): This is a resolved Vc, so we don't need to resolve it again pub(crate) node: Vc, }