Skip to content

Commit 897af24

Browse files
Hi-Angelmookid
authored andcommitted
rust-mode.el: check for possible space between variable name and type (#325)
Fixes the following problem: consider code fn foo(a: u32, b : u32) {} Here, `b` was not highlighted as a variable, because the regex didn't take into account possible space before the colon. Signed-off-by: Konstantin Kharlamov <[email protected]>
1 parent 836a8a9 commit 897af24

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

rust-mode-tests.el

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3108,6 +3108,16 @@ impl Two<'a> {
31083108
'(("Impl" "One" "Two")
31093109
("Fn" "one" "two"))))
31103110

3111+
(ert-deftest font-lock-function-parameters ()
3112+
(rust-test-font-lock
3113+
"fn foo(a: u32, b : u32) {}"
3114+
'("fn" font-lock-keyword-face
3115+
"foo" font-lock-function-name-face
3116+
"a" font-lock-variable-name-face
3117+
"u32" font-lock-type-face
3118+
"b" font-lock-variable-name-face
3119+
"u32" font-lock-type-face)))
3120+
31113121
(when (executable-find rust-cargo-bin)
31123122
(ert-deftest rust-test-project-located ()
31133123
(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
@@ -694,7 +694,7 @@ Returns nil if the point is not within a Rust string."
694694
1 font-lock-preprocessor-face)
695695

696696
;; Field names like `foo:`, highlight excluding the :
697-
(,(concat (rust-re-grab rust-re-ident) ":[^:]") 1 font-lock-variable-name-face)
697+
(,(concat (rust-re-grab rust-re-ident) "[[:space:]]*:[^:]") 1 font-lock-variable-name-face)
698698

699699
;; CamelCase Means Type Or Constructor
700700
(,rust-re-type-or-constructor 1 font-lock-type-face)

0 commit comments

Comments
 (0)