[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode dd6d417 215/486: Fix type annotations incorrectl
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode dd6d417 215/486: Fix type annotations incorrectly highlighted as modules. |
Date: |
Sat, 7 Aug 2021 09:25:21 -0400 (EDT) |
branch: elpa/rust-mode
commit dd6d417c1404efcf2364a61fd7e855ec134a991f
Author: Wilfred Hughes <me@wilfred.me.uk>
Commit: Wilfred Hughes <me@wilfred.me.uk>
Fix type annotations incorrectly highlighted as modules.
Previously, we were always treating :: as a module, but Rust
allows type annotations using :: e.g.
parse::<i32>();
This also changes module highlighting so that only the module name is
highlighted, excluding the ::. This makes rust-mode consistent with
other Emacs modes, such as c++-mode and ruby-mode.
---
rust-mode-tests.el | 21 +++++++++++++++++++++
rust-mode.el | 20 ++++++++++++++++++--
2 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index e7a0429..e41245f 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -1403,6 +1403,27 @@ this_is_not_a_string();)"
"\"/*! doc */\""
'("\"/*! doc */\"" font-lock-string-face)))
+(ert-deftest font-lock-module ()
+ (rust-test-font-lock
+ "foo::bar"
+ '("foo" font-lock-type-face)))
+
+(ert-deftest font-lock-submodule ()
+ (rust-test-font-lock
+ "foo::bar::baz"
+ '("foo" font-lock-type-face
+ "bar" font-lock-type-face)))
+
+(ert-deftest font-lock-type-annotation ()
+ "Ensure type annotations are not confused with modules."
+ (rust-test-font-lock
+ "parse::<i32>();"
+ ;; Only the i32 should have been highlighted.
+ '("i32" font-lock-type-face))
+ (rust-test-font-lock
+ "foo:: <i32>"
+ ;; Only the i32 should have been highlighted.
+ '("i32" font-lock-type-face)))
(ert-deftest indent-method-chains-no-align ()
(let ((rust-indent-method-chain nil)) (test-indent
diff --git a/rust-mode.el b/rust-mode.el
index 8049273..4697c70 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -14,6 +14,7 @@
;;; Code:
(eval-when-compile (require 'rx)
+ (require 'cl)
(require 'compile)
(require 'url-vars))
@@ -525,6 +526,21 @@ function or trait. When nil, where will be aligned with
fn or trait."
(concat "\\_<" (regexp-opt words t) "\\_>"))
(defconst rust-re-special-types (regexp-opt-symbols rust-special-types))
+
+(defun rust-module-font-lock-matcher (limit)
+ "Matches module names \"foo::\" but does not match type annotations
\"foo::<\"."
+ (block nil
+ (while t
+ (let* ((symbol-then-colons (rx-to-string `(seq (group (regexp
,rust-re-ident)) "::")))
+ (match (re-search-forward symbol-then-colons limit t)))
+ (cond
+ ;; If we didn't find a match, there are no more occurrences
+ ;; of foo::, so return.
+ ((null match) (return nil))
+ ;; If this isn't a type annotation foo::<, we've found a
+ ;; match, so a return it!
+ ((not (looking-at (rx (0+ space) "<"))) (return match)))))))
+
(defvar rust-mode-font-lock-keywords
(append
`(
@@ -548,8 +564,8 @@ function or trait. When nil, where will be aligned with fn
or trait."
;; Field names like `foo:`, highlight excluding the :
(,(concat (rust-re-grab rust-re-ident) ":[^:]") 1
font-lock-variable-name-face)
- ;; Module names like `foo::`, highlight including the ::
- (,(rust-re-grab (concat rust-re-ident "::")) 1 font-lock-type-face)
+ ;; Module names like `foo::`, highlight excluding the ::
+ (rust-module-font-lock-matcher 1 font-lock-type-face)
;; Lifetimes like `'foo`
(,(concat "'" (rust-re-grab rust-re-ident) "[^']") 1
font-lock-variable-name-face)
- [nongnu] elpa/rust-mode ee171df 172/486: test $EMACS directly rather than using "which", (continued)
- [nongnu] elpa/rust-mode ee171df 172/486: test $EMACS directly rather than using "which", ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode d1ed015 173/486: Distinguish face for doc-comments, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode c9c7871 179/486: Merge pull request #79 from MicahChalmer/angle-bracket-madness, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ee564d5 185/486: Merge pull request #85 from talchas/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 99b128c 187/486: Fix slowness in angle bracket matching, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5e77aed 191/486: Correcting highlighting of capitals in function names., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5e51aaa 194/486: Merge pull request #69 from tromey/safe-local-variables, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 012537b 195/486: remove byte-compiler warnings and prevent future ones, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 866df37 196/486: make rust-mode use lexical binding, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6252cf1 217/486: Fix indentation of closing delimiters, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode dd6d417 215/486: Fix type annotations incorrectly highlighted as modules.,
ELPA Syncer <=
- [nongnu] elpa/rust-mode 86d636a 223/486: Remove duplicate keywords, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b1cca0f 222/486: Merge pull request #72 from birkenfeld/builtin-face, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 061e6d8 214/486: Merge pull request #109 from mrBliss/highlight-unsafe, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 86c55b1 220/486: Integrate rustfmt support, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode beec95a 231/486: Allow disabling rustfmt with a dir-local/file-local variable, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6739dd9 226/486: Merge pull request #123 from birkenfeld/fix-unicode-char-escapes, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode f408b06 227/486: Run the after-revert hook after rustfmt, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode bc0df03 235/486: Merge pull request #135 from Stebalien/file-local, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 9812232 236/486: Document how to install on Debian, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode bfe24d2 237/486: Merge pull request #132 from tomjakubowski/move-module, ELPA Syncer, 2021/08/07