Skip to content

Rust attribute-based derive macro traits not emitted as references in conditional compilation #2052

Description

@Widthdom

Summary

Rust attributes inside #[cfg_attr(...)] and similar conditional directives that specify derive traits (e.g., #[cfg_attr(test, derive(Debug))]) are not consistently emitted as type references. The current DeriveAttributeRegex and CfgAttrDeriveAttributeRegex extract some cases but fail when the trait list spans multiple lines or when cfg conditions contain complex boolean logic with nested parentheses. This creates gaps in trait reference tracking for test-gated derives.

Where

  • src/CodeIndex/Indexer/References/Languages/RustReferenceExtractor.cs:10-15 (DeriveAttributeRegex, CfgAttrDeriveAttributeRegex) — single-line only
  • src/CodeIndex/Indexer/References/Languages/RustReferenceExtractor.cs:79-87 (EmitDeriveTypeList) — no multiline handling

Suggested approach

  1. Enhance CfgAttrDeriveAttributeRegex to handle nested parens in cfg conditions using balancing groups like C# patterns
  2. Build a multiline attribute scanner for derive lists spanning multiple physical lines
  3. Ensure #[cfg_attr(all(test, feature = "serde"), derive(Debug, Serialize))] and similar nested patterns emit all trait references
  4. Test with: #[cfg_attr(\n all(test, not(miri)),\n derive(\n Debug,\n Clone\n )\n)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions