14
14
; ;; Code:
15
15
16
16
(eval-when-compile (require 'rx )
17
+ (require 'cl )
17
18
(require 'compile )
18
19
(require 'url-vars ))
19
20
@@ -525,6 +526,21 @@ function or trait. When nil, where will be aligned with fn or trait."
525
526
(concat " \\ _<" (regexp-opt words t ) " \\ _>" ))
526
527
(defconst rust-re-special-types (regexp-opt-symbols rust-special-types))
527
528
529
+
530
+ (defun rust-module-font-lock-matcher (limit )
531
+ " Matches module names \" foo::\" but does not match type annotations \" foo::<\" ."
532
+ (block nil
533
+ (while t
534
+ (let* ((symbol-then-colons (rx-to-string `(seq (group (regexp , rust-re-ident )) " ::" )))
535
+ (match (re-search-forward symbol-then-colons limit t )))
536
+ (cond
537
+ ; ; If we didn't find a match, there are no more occurrences
538
+ ; ; of foo::, so return.
539
+ ((null match ) (return nil ))
540
+ ; ; If this isn't a type annotation foo::<, we've found a
541
+ ; ; match, so a return it!
542
+ ((not (looking-at (rx (0+ space) " <" ))) (return match )))))))
543
+
528
544
(defvar rust-mode-font-lock-keywords
529
545
(append
530
546
`(
@@ -548,8 +564,8 @@ function or trait. When nil, where will be aligned with fn or trait."
548
564
; ; Field names like `foo:`, highlight excluding the :
549
565
(,(concat (rust-re-grab rust-re-ident) " :[^:]" ) 1 font-lock-variable-name-face )
550
566
551
- ; ; Module names like `foo::`, highlight including the ::
552
- (,( rust-re-grab ( concat rust-re-ident " :: " )) 1 font-lock-type-face )
567
+ ; ; Module names like `foo::`, highlight excluding the ::
568
+ (rust-module-font-lock-matcher 1 font-lock-type-face )
553
569
554
570
; ; Lifetimes like `'foo`
555
571
(,(concat " '" (rust-re-grab rust-re-ident) " [^']" ) 1 font-lock-variable-name-face )
0 commit comments