diff --git a/rust-mode-tests.el b/rust-mode-tests.el index 4c970c4..9074190 100644 --- a/rust-mode-tests.el +++ b/rust-mode-tests.el @@ -1979,6 +1979,28 @@ this_is_not_a_string();)" "union" font-lock-variable-name-face "bar" font-lock-type-face))) +(ert-deftest rust-test-raw-context-sensitive () + (rust-test-font-lock + "let raw = 7; let foo = &raw const raw; let bar = &raw mut raw;" + '("let" font-lock-keyword-face + ;; The first raw is a variable name. + "raw" font-lock-variable-name-face + "let" font-lock-keyword-face + "foo" font-lock-variable-name-face + "&" rust-ampersand-face + ;; The second raw is a contextual keyword. + "raw" font-lock-keyword-face + "const" font-lock-keyword-face + ;; The third raw is a value. + "let" font-lock-keyword-face + "bar" font-lock-variable-name-face + "&" rust-ampersand-face + ;; The fourth raw is a contextual keyword. + "raw" font-lock-keyword-face + "mut" font-lock-keyword-face + ;; The fifth raw is a value. + ))) + (ert-deftest indent-method-chains-no-align () (let ((rust-indent-method-chain nil)) (test-indent " diff --git a/rust-prog-mode.el b/rust-prog-mode.el index f2538ab..ea6ef82 100644 --- a/rust-prog-mode.el +++ b/rust-prog-mode.el @@ -112,6 +112,14 @@ to the function arguments. When nil, `->' will be indented one level." (or space line-start) (group symbol-start "union" symbol-end) (+ space) (regexp ,rust-re-ident)))) +(defconst rust-re-raw + (rx-to-string + `(seq + "&" + (zero-or-more space) + (group "raw") + (one-or-more space) + (or "const" "mut")))) (defun rust-re-item-def (itype) (concat (rust-re-word itype) @@ -188,7 +196,7 @@ See `prettify-symbols-compose-predicate'." "let" "loop" "match" "mod" "move" "mut" "priv" "pub" - "raw" "ref" "return" + "ref" "return" "self" "static" "struct" "super" "true" "trait" "type" "try" "use" @@ -269,6 +277,7 @@ Does not match type annotations of the form \"foo::<\"." ;; Contextual keywords ("\\_<\\(default\\)[[:space:]]+fn\\_>" 1 font-lock-keyword-face) (,rust-re-union 1 font-lock-keyword-face) + (,rust-re-raw 1 font-lock-keyword-face) ;; Special types (,(regexp-opt rust-special-types 'symbols) . font-lock-type-face)