Skip to content

Commit b0dff7a

Browse files
chris-morganalexcrichton
authored andcommitted
Vim: highlight invalid characters in char literals.
1 parent 31dfcf9 commit b0dff7a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/etc/vim/syntax/rust.vim

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,11 @@ syn region rustGenericLifetimeCandidate display start=/\%(<\|,\s*\)\@<='/ end=/[
179179

180180
"rustLifetime must appear before rustCharacter, or chars will get the lifetime highlighting
181181
syn match rustLifetime display "\'\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*"
182-
syn match rustCharacter /b'\([^'\\]\|\\\(.\|x\x\{2}\)\)'/ contains=rustEscape,rustEscapeError
183-
syn match rustCharacter /'\([^'\\]\|\\\(.\|x\x\{2}\|u\x\{4}\|U\x\{8}\)\)'/ contains=rustEscape,rustEscapeUnicode,rustEscapeError
182+
syn match rustCharacterInvalid display contained /b\?'\zs[\n\r\t']\ze'/
183+
" The groups negated here add up to 0-255 but nothing else (they do not seem to go beyond ASCII).
184+
syn match rustCharacterInvalidUnicode display contained /b'\zs[^[:cntrl:][:graph:][:alnum:][:space:]]\ze'/
185+
syn match rustCharacter /b'\([^\\]\|\\\(.\|x\x\{2}\)\)'/ contains=rustEscape,rustEscapeError,rustCharacterInvalid,rustCharacterInvalidUnicode
186+
syn match rustCharacter /'\([^\\]\|\\\(.\|x\x\{2}\|u\x\{4}\|U\x\{8}\)\)'/ contains=rustEscape,rustEscapeUnicode,rustEscapeError,rustCharacterInvalid
184187

185188
syn region rustCommentLine start="//" end="$" contains=rustTodo,@Spell
186189
syn region rustCommentLineDoc start="//\%(//\@!\|!\)" end="$" contains=rustTodo,@Spell
@@ -223,6 +226,8 @@ hi def link rustEscapeUnicode rustEscape
223226
hi def link rustEscapeError Error
224227
hi def link rustStringContinuation Special
225228
hi def link rustString String
229+
hi def link rustCharacterInvalid Error
230+
hi def link rustCharacterInvalidUnicode rustCharacterInvalid
226231
hi def link rustCharacter Character
227232
hi def link rustNumber Number
228233
hi def link rustBoolean Boolean

0 commit comments

Comments
 (0)