Skip to content

fix(rust): recognize cooked and raw C string literals - #1525

Merged
github-actions[bot] merged 7 commits into
alecthomas:masterfrom
anishpentyala:fix/rust-c-string-literals
Nov 21, 2026
Merged

github-actions[bot] merged 7 commits into
alecthomas:masterfrom
anishpentyala:fix/rust-c-string-literals

Conversation

@anishpentyala

Copy link
Copy Markdown
Contributor

Problem

The Rust lexer currently separates the c prefix in cooked C strings and fails to recognize raw C strings such as cr"hello" and cr##"hello"##. This gives the prefix and contents the wrong token types and can lose the raw-string boundary.

Changes

  • Recognize c alongside b for cooked strings, using the existing byte-string escape state.
  • Recognize cr alongside r and br for raw strings, keeping the existing matching-hash backreference.
  • Add 13 token-level cases covering cooked/raw C strings, escapes, multiple hash counts, following-code recovery, and existing byte/raw/ordinary string controls, plus a Rust fixture.

This is highlighting support, not validation of Rust editions or invalid C-string contents.

Validation

  • Full ordinary suite passed: GOMEMLIMIT=512MiB GOGC=30 go test -p 1 ./....
  • Targeted literal tests and all Rust fixtures passed with the race detector, three runs.
  • Direct pinned ./bin/golangci-lint run ./... passed.
  • go vet -composites=false ./..., root/CLI builds, and lexer generation passed. Lexer generation left metadata unchanged.
  • The new C-string assertions fail on the unmodified base; existing byte/raw/ordinary-string controls pass there. Three assertion mutants were rejected.
  • Inspected actual CLI HTML output for raw-string termination and following-code recovery.

The full race run did not complete locally: the lexers process was killed in both the default and memory-bounded attempts. bit lint did not complete locally either: its top-level TinyGo/Binaryen bootstrap filled the local disk. The direct pinned lint run above is separate, not a claim that bit lint passed.

@github-actions

Copy link
Copy Markdown

Lexer and style changes should be tested with lexers/testdata files, not Go tests. Add a .actual input, generate its .expected output with RECORD=true go test ./lexers, and remove:

  • lexers/rust_c_string_test.go

@github-actions
github-actions Bot enabled auto-merge (squash) November 21, 2026 22:14
@github-actions
github-actions Bot merged commit 9afb109 into alecthomas:master Nov 21, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant