Skip to content

Commit eda330a

Browse files
committed
fix(syntax): storages not highlighted
Sometimes, when a storage followed itself: ```rust &ref mut … ``` The second `rustStorage` would not be highlighted. Additionally, the special `'static` lifetime was not detected. This commit fixes those issues.
1 parent 117e1e6 commit eda330a

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

syntax/rust.vim

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ syn keyword rustUnsafeKeyword unsafe
5454
syn keyword rustKeyword use nextgroup=rustModPath skipempty skipwhite
5555
" FIXME: Scoped impl's name is also fallen in this category
5656
syn keyword rustKeyword mod trait nextgroup=rustType skipempty skipwhite
57-
syn keyword rustStorage move mut ref static const nextgroup=@rustIdentifiers skipempty skipwhite
57+
syn keyword rustStorage move mut ref static const nextgroup=rustStorage,@rustIdentifiers skipempty skipwhite
5858
syn match rustDefault /\<default\ze\_s\+\(impl\|fn\|type\|const\)\>/ display
5959
syn keyword rustAwait await nextgroup=@rustIdentifiers skipempty skipwhite
6060
syn match rustKeyword /\<try\>!\@!/ display
@@ -71,7 +71,7 @@ syn match rustIdentifier "\<\l\+\(_\l\+\)*\((\)\@!\>" contained contains=rustBo
7171
syn match rustType "\<\(\u\l*\)\+\((\)\@!\>" contains=rustTypePrime contained display
7272
syn match rustConstant "\<\u\+\(_\u\+\)*\((\)\@!\>" contained display
7373
syn match rustFuncName "\<\w\+\(::\)\?\(<.*>\)\?\s*\((\)\@=\>" contains=rustEnumVariant,rustModPathSep,rustGenericRegion display
74-
syn cluster rustIdentifiers contains=rustLifetime,rustModPath,rustBuiltinType,rustEnum,rustTrait,rustEnumVariant,rustMacro,rustFuncName,rustConstant,rustIdentifier,rustType
74+
syn cluster rustIdentifiers contains=@rustLifetimes,rustModPath,rustBuiltinType,rustEnum,rustTrait,rustEnumVariant,rustMacro,rustFuncName,rustConstant,rustIdentifier,rustType
7575

7676
syn region rustMacroRepeat matchgroup=rustMacroRepeatDelimiters start="$(" end="),\=[*+]" contains=TOP
7777
syn match rustMacroVariable "\$\w\+" display
@@ -201,8 +201,10 @@ syn match rustFloat "\<[0-9][0-9_]*\%(\.[0-9][0-9_]*\)\=\%([eE][+-]\=[0-9_]\
201201

202202
"rustLifetime must appear before rustCharacter, or chars will get the lifetime highlighting
203203
syn match rustLifetime "\'\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display nextgroup=rustNoise,@rustIdentifiers skipempty skipwhite
204-
syn match rustLabel "\'\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*:" display
205-
syn match rustLabel "\%(\<\%(break\|continue\)\s*\)\@<=\'\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display
204+
syn match rustStaticLifetime "'static" display contains=rustStorage nextgroup=rustNoise,@rustIdentifiers skipempty skipwhite
205+
syn cluster rustLifetimes contains=rustStaticLifetime,rustLifetime
206+
syn match rustLabel "\'\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*:" contains=rustBounds display
207+
syn match rustLabel "\%(\<\%(break\|continue\)\s*\)\@<=\'\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display
206208
syn match rustCharacterInvalid /b\?'\zs[\n\r\t']\ze'/ contained
207209
" The groups negated here add up to 0-255 but nothing else (they do not seem to go beyond ASCII).
208210
syn match rustCharacterInvalidUnicode /b'\zs[^[:cntrl:][:graph:][:alnum:][:space:]]\ze'/ contained display
@@ -364,7 +366,8 @@ hi def link rustDerive PreProc
364366
hi def link rustDefault StorageClass
365367
hi def link rustStorage StorageClass
366368
hi def link rustObsoleteStorage Error
367-
hi def link rustLifetime Special
369+
hi def link rustLifetime Special
370+
hi def link rustStaticLifetime rustStorage
368371
hi def link rustLabel Label
369372
hi def link rustExternCrate rustKeyword
370373
hi def link rustObsoleteExternMod Error

0 commit comments

Comments
 (0)