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
- Add a new BodyStyle variant (e.g., RustUnsafeBlock) and pattern for
unsafe\s*{ to track unsafe block boundaries
- Scan function/impl bodies for leading
unsafe { and create container-like records (class kind with "unsafe_block" annotation)
- Emit type_reference records for types inside
&mut T patterns, capturing both the reference type and the mutability context
- Test with:
fn demo() { unsafe { let p = Box::leak(Box::new(42)); } }
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 anunsafecontainer. Additionally, patterns like&mut Ttype 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 blockssrc/CodeIndex/Indexer/References/Languages/RustReferenceExtractor.cs:337-389— mutable reference type emission missingSuggested approach
unsafe\s*{to track unsafe block boundariesunsafe {and create container-like records (class kind with "unsafe_block" annotation)&mut Tpatterns, capturing both the reference type and the mutability contextfn demo() { unsafe { let p = Box::leak(Box::new(42)); } }