Skip to content

Commit 07e1e0a

Browse files
authored
Merge pull request #441 from Chris00/master
Highlight the (optional) type suffix of numbers with the type face
2 parents 41a543b + 32718d4 commit 07e1e0a

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

rust-mode-tests.el

+50
Original file line numberDiff line numberDiff line change
@@ -1304,6 +1304,56 @@ list of substrings of `STR' each followed by its face."
13041304
'("/* " font-lock-comment-delimiter-face
13051305
"#[foo] */" font-lock-comment-face)))
13061306

1307+
(ert-deftest font-lock-number-with-type ()
1308+
(rust-test-font-lock
1309+
"-123i32"
1310+
'("i32" font-lock-type-face))
1311+
(rust-test-font-lock
1312+
"123u32"
1313+
'("u32" font-lock-type-face))
1314+
(rust-test-font-lock
1315+
"123_123_u32"
1316+
'("u32" font-lock-type-face))
1317+
(rust-test-font-lock
1318+
"0xff_u8"
1319+
'("u8" font-lock-type-face))
1320+
(rust-test-font-lock
1321+
"0b1111_1111_1001_0000i64"
1322+
'("i64" font-lock-type-face))
1323+
(rust-test-font-lock
1324+
"0usize"
1325+
'("usize" font-lock-type-face))
1326+
(rust-test-font-lock
1327+
"123.0f64 + 1."
1328+
'("f64" font-lock-type-face))
1329+
(rust-test-font-lock
1330+
"0.1f32"
1331+
'("f32" font-lock-type-face))
1332+
(rust-test-font-lock
1333+
"12E+99_f64"
1334+
'("f64" font-lock-type-face))
1335+
(rust-test-font-lock
1336+
"5f32"
1337+
'("f32" font-lock-type-face))
1338+
(rust-test-font-lock
1339+
"0x5i32"
1340+
'("i32" font-lock-type-face))
1341+
(rust-test-font-lock
1342+
"1x5i32"
1343+
'())
1344+
(rust-test-font-lock
1345+
"0x5i321"
1346+
'())
1347+
(rust-test-font-lock
1348+
"fname5f32"
1349+
'())
1350+
(rust-test-font-lock
1351+
"0x5i32+1"
1352+
'("i32" font-lock-type-face))
1353+
(rust-test-font-lock
1354+
"f(0xFFi32)"
1355+
'("i32" font-lock-type-face)))
1356+
13071357
(ert-deftest font-lock-double-quote-character-literal ()
13081358
(rust-test-font-lock
13091359
"'\"'; let"

rust-mode.el

+12
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,16 @@ See `prettify-symbols-compose-predicate'."
361361
"bool"
362362
"str" "char"))
363363

364+
(defconst rust-number-with-type
365+
(eval-when-compile
366+
(concat
367+
"\\_<\\(?:0[box]?\\|[1-9]\\)[[:digit:]a-fA-F_.]*\\(?:[eE][+-]?[[:digit:]_]\\)?"
368+
(regexp-opt '("u8" "i8" "u16" "i16" "u32" "i32" "u64" "i64"
369+
"u128" "i128" "usize" "isize" "f32" "f64")
370+
t)
371+
"\\_>"))
372+
"Regular expression matching a number with a type suffix.")
373+
364374
(defvar rust-builtin-formatting-macros
365375
'("eprint"
366376
"eprintln"
@@ -470,6 +480,8 @@ Does not match type annotations of the form \"foo::<\"."
470480
("\\?" . 'rust-question-mark)
471481
("\\(&+\\)\\(?:'\\(?:\\<\\|_\\)\\|\\<\\|[[({:*_|]\\)"
472482
1 'rust-ampersand-face)
483+
;; Numbers with type suffix
484+
(,rust-number-with-type 1 font-lock-type-face)
473485
)
474486

475487
;; Ensure we highlight `Foo` in `struct Foo` as a type.

0 commit comments

Comments
 (0)