Skip to content

Commit 74c2647

Browse files
Hi-Angelmookid
authored andcommitted
Highlight variable name in a for-loop (#326)
Signed-off-by: Konstantin Kharlamov <[email protected]>
1 parent 897af24 commit 74c2647

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

rust-mode-tests.el

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3118,6 +3118,18 @@ impl Two<'a> {
31183118
"b" font-lock-variable-name-face
31193119
"u32" font-lock-type-face)))
31203120

3121+
(ert-deftest variable-in-for-loop ()
3122+
(rust-test-font-lock
3123+
"for var in iter"
3124+
'("for" font-lock-keyword-face
3125+
"var" font-lock-variable-name-face
3126+
"in" font-lock-keyword-face))
3127+
(rust-test-font-lock
3128+
"for Foo{var} in iter"
3129+
'("for" font-lock-keyword-face
3130+
"Foo" font-lock-type-face
3131+
"in" font-lock-keyword-face)))
3132+
31213133
(when (executable-find rust-cargo-bin)
31223134
(ert-deftest rust-test-project-located ()
31233135
(lexical-let* ((test-dir (expand-file-name "test-project" default-directory))

rust-mode.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ Returns nil if the point is not within a Rust string."
700700
(,rust-re-type-or-constructor 1 font-lock-type-face)
701701

702702
;; Type-inferred binding
703-
(,(concat "\\_<\\(?:let\\s-+ref\\|let\\|ref\\)\\s-+\\(?:mut\\s-+\\)?" (rust-re-grab rust-re-ident) "\\_>") 1 font-lock-variable-name-face)
703+
(,(concat "\\_<\\(?:let\\s-+ref\\|let\\|ref\\|for\\)\\s-+\\(?:mut\\s-+\\)?" (rust-re-grab rust-re-ident) "\\_>") 1 font-lock-variable-name-face)
704704

705705
;; Type names like `Foo::`, highlight excluding the ::
706706
(,(rust-path-font-lock-matcher rust-re-uc-ident) 1 font-lock-type-face)

0 commit comments

Comments
 (0)