From 32963140482d40517d38904791bd253dd50f192c Mon Sep 17 00:00:00 2001 From: Shiva Kiran Koninty Date: Tue, 14 Apr 2026 11:10:11 +0530 Subject: [PATCH 1/2] Revert "Add keyword `raw` (#585)" This reverts commit 6482f5601e807fa61cee6a09a18a7e9152c394f3. The raw borrow operator is a weak keyword, as such, it must only be highlighted in the right context. Weak keywords: https://doc.rust-lang.org/reference/keywords.html#weak-keywords --- rust-prog-mode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-prog-mode.el b/rust-prog-mode.el index f2538ab..f2f3f0b 100644 --- a/rust-prog-mode.el +++ b/rust-prog-mode.el @@ -188,7 +188,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" From 447985e8a8ad81d8589d0e62b1c5cae83a4da067 Mon Sep 17 00:00:00 2001 From: Shiva Kiran Koninty Date: Tue, 14 Apr 2026 11:10:34 +0530 Subject: [PATCH 2/2] Add `raw` borrow operator as a contextual keyword The `raw` borrow operator is a contextual keyword. Highlight it only in the context of borrows. ```rust let mut x = 5; // highlight "raw" here let a = &raw const x; let b = &raw mut x; // do not highlight "raw" here let raw = &x as *const _; let raw_mut = &x as *mut _; ``` Raw borrow operator: https://doc.rust-lang.org/reference/expressions/operator-expr.html#raw-borrow-operators Rust weak keywords: https://doc.rust-lang.org/reference/keywords.html#weak-keywords --- rust-mode-tests.el | 22 ++++++++++++++++++++++ rust-prog-mode.el | 9 +++++++++ 2 files changed, 31 insertions(+) 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 f2f3f0b..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) @@ -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)