Skip to content

Rust unsafe block boundaries and mutable reference scopes not indexed as symbol containers #2053

Description

@Widthdom

Summary

Rust unsafe { ... } blocks are treated as opaque code regions; symbols and type references inside them are attributed to the parent scope, not tracked as part of an unsafe container. Additionally, patterns like &mut T type annotations produce no reference record for the mutability context. This prevents accurate semantic analysis of memory-unsafe code sections and makes unsafe auditing harder. The unsafe modifier in impl blocks (line 171 of SymbolExtractor.Rust.cs) is recognized but block-level unsafe is not.

Where

  • src/CodeIndex/Indexer/Symbols/SymbolExtractor.cs:1294-1317 — no BodyStyle.Brace for unsafe blocks
  • src/CodeIndex/Indexer/References/Languages/RustReferenceExtractor.cs:337-389 — mutable reference type emission missing

Suggested approach

  1. Add a new BodyStyle variant (e.g., RustUnsafeBlock) and pattern for unsafe\s*{ to track unsafe block boundaries
  2. Scan function/impl bodies for leading unsafe { and create container-like records (class kind with "unsafe_block" annotation)
  3. Emit type_reference records for types inside &mut T patterns, capturing both the reference type and the mutability context
  4. Test with: fn demo() { unsafe { let p = Box::leak(Box::new(42)); } }

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