branch: elpa/rust-mode
commit 74c264783e25166055a7871a00e4f68fe0495a0d
Author: Konstantin Kharlamov <[email protected]>
Commit: Nathan Moreau <[email protected]>

    Highlight variable name in a for-loop (#326)
    
    Signed-off-by: Konstantin Kharlamov <[email protected]>
---
 rust-mode-tests.el | 12 ++++++++++++
 rust-mode.el       |  2 +-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index 0c1ad1d..a22e43a 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -3118,6 +3118,18 @@ impl Two<'a> {
      "b" font-lock-variable-name-face
      "u32" font-lock-type-face)))
 
+(ert-deftest variable-in-for-loop ()
+  (rust-test-font-lock
+   "for var in iter"
+   '("for" font-lock-keyword-face
+     "var" font-lock-variable-name-face
+     "in" font-lock-keyword-face))
+  (rust-test-font-lock
+   "for Foo{var} in iter"
+   '("for" font-lock-keyword-face
+     "Foo" font-lock-type-face
+     "in" font-lock-keyword-face)))
+
 (when (executable-find rust-cargo-bin)
   (ert-deftest rust-test-project-located ()
     (lexical-let* ((test-dir (expand-file-name "test-project" 
default-directory))
diff --git a/rust-mode.el b/rust-mode.el
index cdc44e5..ec4f1c9 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -700,7 +700,7 @@ Returns nil if the point is not within a Rust string."
      (,rust-re-type-or-constructor 1 font-lock-type-face)
 
      ;; Type-inferred binding
-     (,(concat "\\_<\\(?:let\\s-+ref\\|let\\|ref\\)\\s-+\\(?:mut\\s-+\\)?" 
(rust-re-grab rust-re-ident) "\\_>") 1 font-lock-variable-name-face)
+     (,(concat 
"\\_<\\(?:let\\s-+ref\\|let\\|ref\\|for\\)\\s-+\\(?:mut\\s-+\\)?" (rust-re-grab 
rust-re-ident) "\\_>") 1 font-lock-variable-name-face)
 
      ;; Type names like `Foo::`, highlight excluding the ::
      (,(rust-path-font-lock-matcher rust-re-uc-ident) 1 font-lock-type-face)

Reply via email to