Rust: Improvements (#2464)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
diff --git a/components/prism-rust.js b/components/prism-rust.js
index cb42b75..8270791 100644
--- a/components/prism-rust.js
+++ b/components/prism-rust.js
@@ -31,7 +31,7 @@
alias: 'string'
},
'attribute': {
- pattern: /#!?\[[^[\]]*\]/,
+ pattern: /#!?\[(?:[^\[\]"]|"(?:\\[\s\S]|[^\\"])*")*\]/,
greedy: true,
alias: 'attr-name',
inside: {
@@ -66,26 +66,55 @@
'variable': /\$\w+/,
'function-definition': {
- pattern: /(\bfn\s*)\w+/,
+ pattern: /(\bfn\s+)\w+/,
lookbehind: true,
alias: 'function'
},
+ 'type-definition': {
+ pattern: /(\b(?:enum|struct|union)\s+)\w+/,
+ lookbehind: true,
+ alias: 'class-name'
+ },
+ 'module-declaration': [
+ {
+ pattern: /(\b(?:crate|mod)\s+)[a-z][a-z_\d]*/,
+ lookbehind: true,
+ alias: 'namespace'
+ },
+ {
+ pattern: /(\b(?:crate|self|super)\s*)::\s*[a-z][a-z_\d]*\b(?:\s*::(?:\s*[a-z][a-z_\d]*\s*::)*)?/,
+ lookbehind: true,
+ alias: 'namespace',
+ inside: {
+ 'punctuation': /::/
+ }
+ }
+ ],
'keyword': [
// https://github.com/rust-lang/reference/blob/master/src/keywords.md
/\b(?:abstract|as|async|await|become|box|break|const|continue|crate|do|dyn|else|enum|extern|final|fn|for|if|impl|in|let|loop|macro|match|mod|move|mut|override|priv|pub|ref|return|self|Self|static|struct|super|trait|try|type|typeof|union|unsafe|unsized|use|virtual|where|while|yield)\b/,
- // primitives
+ // primitives and str
// https://doc.rust-lang.org/stable/rust-by-example/primitives.html
- /\b(?:[ui](?:8|16|32|64|128|size)|f(?:32|64)|bool|char)\b/
+ /\b(?:[ui](?:8|16|32|64|128|size)|f(?:32|64)|bool|char|str)\b/
],
// functions can technically start with an upper-case letter, but this will introduce a lot of false positives
// and Rust's naming conventions recommend snake_case anyway.
// https://doc.rust-lang.org/1.0.0/style/style/naming/README.html
- 'function': /\b[a-z_]\w*(?=\s*(?:::\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*)?\()/,
+ 'function': /\b[a-z_]\w*(?=\s*(?:::\s*<|\())/,
'macro': {
pattern: /\w+!/,
alias: 'property'
},
+ 'constant': /\b[A-Z_][A-Z_\d]+\b/,
+ 'class-name': /\b[A-Z]\w*\b/,
+
+ 'namespace': {
+ pattern: /(?:\b[a-z][a-z_\d]*\s*::\s*)*\b[a-z][a-z_\d]*\s*::(?!\s*<)/,
+ inside: {
+ 'punctuation': /::/
+ }
+ },
// Hex, oct, bin, dec numbers with visual separators and type suffix
'number': /\b(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(?:\d(?:_?\d)*)?\.?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)(?:_?(?:[iu](?:8|16|32|64|size)?|f32|f64))?\b/,
diff --git a/components/prism-rust.min.js b/components/prism-rust.min.js
index aaad309..215b6e9 100644
--- a/components/prism-rust.min.js
+++ b/components/prism-rust.min.js
@@ -1 +1 @@
-!function(e){for(var t="/\\*(?:[^*/]|\\*(?!/)|/(?!\\*)|<self>)*\\*/",a=0;a<2;a++)t=t.replace(/<self>/g,function(){return t});t=t.replace(/<self>/g,function(){return"[^\\s\\S]"}),e.languages.rust={comment:[{pattern:RegExp("(^|[^\\\\])"+t),lookbehind:!0,greedy:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0,greedy:!0}],string:{pattern:/b?"(?:\\[\s\S]|[^\\"])*"|b?r(#*)"(?:[^"]|"(?!\1))*"\1/,greedy:!0},char:{pattern:/b?'(?:\\(?:x[0-7][\da-fA-F]|u{(?:[\da-fA-F]_*){1,6}|.)|[^\\\r\n\t'])'/,greedy:!0,alias:"string"},attribute:{pattern:/#!?\[[^[\]]*\]/,greedy:!0,alias:"attr-name",inside:{string:null}},"closure-params":{pattern:/([=(,:]\s*|\bmove\s*)\|[^|]*\||\|[^|]*\|(?=\s*(?:\{|->))/,lookbehind:!0,greedy:!0,inside:{"closure-punctuation":{pattern:/^\||\|$/,alias:"punctuation"},rest:null}},"lifetime-annotation":{pattern:/'\w+/,alias:"symbol"},"fragment-specifier":{pattern:/(\$\w+:)[a-z]+/,lookbehind:!0,alias:"punctuation"},variable:/\$\w+/,"function-definition":{pattern:/(\bfn\s*)\w+/,lookbehind:!0,alias:"function"},keyword:[/\b(?:abstract|as|async|await|become|box|break|const|continue|crate|do|dyn|else|enum|extern|final|fn|for|if|impl|in|let|loop|macro|match|mod|move|mut|override|priv|pub|ref|return|self|Self|static|struct|super|trait|try|type|typeof|union|unsafe|unsized|use|virtual|where|while|yield)\b/,/\b(?:[ui](?:8|16|32|64|128|size)|f(?:32|64)|bool|char)\b/],function:/\b[a-z_]\w*(?=\s*(?:::\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*)?\()/,macro:{pattern:/\w+!/,alias:"property"},number:/\b(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(?:\d(?:_?\d)*)?\.?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)(?:_?(?:[iu](?:8|16|32|64|size)?|f32|f64))?\b/,boolean:/\b(?:false|true)\b/,punctuation:/->|\.\.=|\.{1,3}|::|[{}[\];(),:]/,operator:/[-+*\/%!^]=?|=[=>]?|&[&=]?|\|[|=]?|<<?=?|>>?=?|[@?]/},e.languages.rust["closure-params"].inside.rest=e.languages.rust,e.languages.rust.attribute.inside.string=e.languages.rust.string}(Prism);
\ No newline at end of file
+!function(e){for(var a="/\\*(?:[^*/]|\\*(?!/)|/(?!\\*)|<self>)*\\*/",t=0;t<2;t++)a=a.replace(/<self>/g,function(){return a});a=a.replace(/<self>/g,function(){return"[^\\s\\S]"}),e.languages.rust={comment:[{pattern:RegExp("(^|[^\\\\])"+a),lookbehind:!0,greedy:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0,greedy:!0}],string:{pattern:/b?"(?:\\[\s\S]|[^\\"])*"|b?r(#*)"(?:[^"]|"(?!\1))*"\1/,greedy:!0},char:{pattern:/b?'(?:\\(?:x[0-7][\da-fA-F]|u{(?:[\da-fA-F]_*){1,6}|.)|[^\\\r\n\t'])'/,greedy:!0,alias:"string"},attribute:{pattern:/#!?\[(?:[^\[\]"]|"(?:\\[\s\S]|[^\\"])*")*\]/,greedy:!0,alias:"attr-name",inside:{string:null}},"closure-params":{pattern:/([=(,:]\s*|\bmove\s*)\|[^|]*\||\|[^|]*\|(?=\s*(?:\{|->))/,lookbehind:!0,greedy:!0,inside:{"closure-punctuation":{pattern:/^\||\|$/,alias:"punctuation"},rest:null}},"lifetime-annotation":{pattern:/'\w+/,alias:"symbol"},"fragment-specifier":{pattern:/(\$\w+:)[a-z]+/,lookbehind:!0,alias:"punctuation"},variable:/\$\w+/,"function-definition":{pattern:/(\bfn\s+)\w+/,lookbehind:!0,alias:"function"},"type-definition":{pattern:/(\b(?:enum|struct|union)\s+)\w+/,lookbehind:!0,alias:"class-name"},"module-declaration":[{pattern:/(\b(?:crate|mod)\s+)[a-z][a-z_\d]*/,lookbehind:!0,alias:"namespace"},{pattern:/(\b(?:crate|self|super)\s*)::\s*[a-z][a-z_\d]*\b(?:\s*::(?:\s*[a-z][a-z_\d]*\s*::)*)?/,lookbehind:!0,alias:"namespace",inside:{punctuation:/::/}}],keyword:[/\b(?:abstract|as|async|await|become|box|break|const|continue|crate|do|dyn|else|enum|extern|final|fn|for|if|impl|in|let|loop|macro|match|mod|move|mut|override|priv|pub|ref|return|self|Self|static|struct|super|trait|try|type|typeof|union|unsafe|unsized|use|virtual|where|while|yield)\b/,/\b(?:[ui](?:8|16|32|64|128|size)|f(?:32|64)|bool|char|str)\b/],function:/\b[a-z_]\w*(?=\s*(?:::\s*<|\())/,macro:{pattern:/\w+!/,alias:"property"},constant:/\b[A-Z_][A-Z_\d]+\b/,"class-name":/\b[A-Z]\w*\b/,namespace:{pattern:/(?:\b[a-z][a-z_\d]*\s*::\s*)*\b[a-z][a-z_\d]*\s*::(?!\s*<)/,inside:{punctuation:/::/}},number:/\b(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(?:\d(?:_?\d)*)?\.?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)(?:_?(?:[iu](?:8|16|32|64|size)?|f32|f64))?\b/,boolean:/\b(?:false|true)\b/,punctuation:/->|\.\.=|\.{1,3}|::|[{}[\];(),:]/,operator:/[-+*\/%!^]=?|=[=>]?|&[&=]?|\|[|=]?|<<?=?|>>?=?|[@?]/},e.languages.rust["closure-params"].inside.rest=e.languages.rust,e.languages.rust.attribute.inside.string=e.languages.rust.string}(Prism);
\ No newline at end of file
diff --git a/examples/prism-rust.html b/examples/prism-rust.html
index 3f56a91..e7b2d1a 100644
--- a/examples/prism-rust.html
+++ b/examples/prism-rust.html
@@ -5,7 +5,7 @@
comment */</code></pre>
<h2>Strings</h2>
-<pre><code>'C'; '\''; '\n'; '\u7FFF'; // Characters
+<pre><code>'C'; '\''; '\n'; '\u{7FFF}'; // Characters
"foo \"bar\" baz"; // String
r##"foo #"bar"# baz"##; // Raw string with # pairs
b'C'; b'\''; b'\n'; // Bytes
@@ -14,10 +14,7 @@ br##"foo #"bar"# baz"##; // Raw byte string with # pairs
</code></pre>
<h2>Numbers</h2>
-<pre><code>123i; // type int
-123u; // type uint
-123_u; // type uint
-0xff_u8; // type u8
+<pre><code>0xff_u8; // type u8
0o70_i16; // type i16
0b1111_1111_1001_0000_i32; // type i32
@@ -32,9 +29,9 @@ br##"foo #"bar"# baz"##; // Raw byte string with # pairs
<h2>Functions and macros</h2>
<pre><code>println!("x is {}", x);
-fn next_two(x: int) -> (int, int) { (x + 1i, x + 2i) }
-next_two(5i);
-vec![1i, 2, 3];
+fn next_two(x: i32) -> (i32, i32) { (x + 1, x + 2) }
+next_two(5);
+vec![1, 2, 3];
</code></pre>
<h2>Attributes</h2>
@@ -47,6 +44,6 @@ fn a_test() {
<h2>Closure parameters and bitwise OR</h2>
<pre><code>let x = a | b;
let y = c || d;
-let add_one = |x: int| -> int { 1i + x };
+let add_one = |x: i32| -> i32 { 1i + x };
let printer = || { println!("x is: {}", x); };
</code></pre>
diff --git a/tests/languages/rust/class-name_feature.test b/tests/languages/rust/class-name_feature.test
new file mode 100644
index 0000000..442a8a2
--- /dev/null
+++ b/tests/languages/rust/class-name_feature.test
@@ -0,0 +1,87 @@
+struct foo {}
+
+let foo: CStr;
+let foo: &'a CStr;
+let foo: &'a Foo<dyn Bar>;
+Option::Some(foo);
+Option::None;
+
+// we can differentiate between enum variants and class names
+// so let's make the bug a feature!
+enum Foo {
+ Const,
+ Tuple(i8,i8),
+ Struct {
+ foo: u8
+ }
+}
+
+----------------------------------------------------
+
+[
+ ["keyword", "struct"],
+ ["type-definition", "foo"],
+ ["punctuation", "{"],
+ ["punctuation", "}"],
+
+ ["keyword", "let"],
+ " foo",
+ ["punctuation", ":"],
+ ["class-name", "CStr"],
+ ["punctuation", ";"],
+ ["keyword", "let"],
+ " foo",
+ ["punctuation", ":"],
+ ["operator", "&"],
+ ["lifetime-annotation", "'a"],
+ ["class-name", "CStr"],
+ ["punctuation", ";"],
+ ["keyword", "let"],
+ " foo",
+ ["punctuation", ":"],
+ ["operator", "&"],
+ ["lifetime-annotation", "'a"],
+ ["class-name", "Foo"],
+ ["operator", "<"],
+ ["keyword", "dyn"],
+ ["class-name", "Bar"],
+ ["operator", ">"],
+ ["punctuation", ";"],
+ ["class-name", "Option"],
+ ["punctuation", "::"],
+ ["class-name", "Some"],
+ ["punctuation", "("],
+ "foo",
+ ["punctuation", ")"],
+ ["punctuation", ";"],
+ ["class-name", "Option"],
+ ["punctuation", "::"],
+ ["class-name", "None"],
+ ["punctuation", ";"],
+
+ ["comment", "// we can differentiate between enum variants and class names"],
+ ["comment", "// so let's make the bug a feature!"],
+ ["keyword", "enum"],
+ ["type-definition", "Foo"],
+ ["punctuation", "{"],
+ ["class-name", "Const"],
+ ["punctuation", ","],
+ ["class-name", "Tuple"],
+ ["punctuation", "("],
+ ["keyword", "i8"],
+ ["punctuation", ","],
+ ["keyword", "i8"],
+ ["punctuation", ")"],
+ ["punctuation", ","],
+ ["class-name", "Struct"],
+ ["punctuation", "{"],
+ "\n\t\tfoo",
+ ["punctuation", ":"],
+ ["keyword", "u8"],
+ ["punctuation", "}"],
+ ["punctuation", "}"]
+]
+
+----------------------------------------------------
+
+Checks for class names and enum variants.
diff --git a/tests/languages/rust/constant_feature.test b/tests/languages/rust/constant_feature.test
new file mode 100644
index 0000000..84cac8b
--- /dev/null
+++ b/tests/languages/rust/constant_feature.test
@@ -0,0 +1,19 @@
+MAX
+SOME_CONSTANT
+
+// not a constant
+T
+
+----------------------------------------------------
+
+[
+ ["constant", "MAX"],
+ ["constant", "SOME_CONSTANT"],
+
+ ["comment", "// not a constant"],
+ ["class-name", "T"]
+]
+
+----------------------------------------------------
+
+Checks for constants.
diff --git a/tests/languages/rust/function_feature.test b/tests/languages/rust/function_feature.test
index c4a51d4..e833342 100644
--- a/tests/languages/rust/function_feature.test
+++ b/tests/languages/rust/function_feature.test
@@ -4,6 +4,8 @@ foo_bar_42(
foo_generic::<T, Option<T>>()
+mem::transmute::<Box<dyn FnOnce() + 'a>, Box<dyn FnOnce() + 'static>>()
+
fn apply<F>(f: F) where F: FnOnce() {
f();
}
@@ -21,11 +23,40 @@ fn apply<F>(f: F) where F: FnOnce() {
["function", "foo_generic"],
["punctuation", "::"],
["operator", "<"],
- "T",
+ ["class-name", "T"],
["punctuation", ","],
- " Option",
+ ["class-name", "Option"],
+ ["operator", "<"],
+ ["class-name", "T"],
+ ["operator", ">>"],
+ ["punctuation", "("],
+ ["punctuation", ")"],
+
+ ["namespace", [
+ "mem",
+ ["punctuation", "::"]
+ ]],
+ ["function", "transmute"],
+ ["punctuation", "::"],
+ ["operator", "<"],
+ ["class-name", "Box"],
["operator", "<"],
- "T",
+ ["keyword", "dyn"],
+ ["class-name", "FnOnce"],
+ ["punctuation", "("],
+ ["punctuation", ")"],
+ ["operator", "+"],
+ ["lifetime-annotation", "'a"],
+ ["operator", ">"],
+ ["punctuation", ","],
+ ["class-name", "Box"],
+ ["operator", "<"],
+ ["keyword", "dyn"],
+ ["class-name", "FnOnce"],
+ ["punctuation", "("],
+ ["punctuation", ")"],
+ ["operator", "+"],
+ ["lifetime-annotation", "'static"],
["operator", ">>"],
["punctuation", "("],
["punctuation", ")"],
@@ -33,17 +64,17 @@ fn apply<F>(f: F) where F: FnOnce() {
["keyword", "fn"],
["function-definition", "apply"],
["operator", "<"],
- "F",
+ ["class-name", "F"],
["operator", ">"],
["punctuation", "("],
"f",
["punctuation", ":"],
- " F",
+ ["class-name", "F"],
["punctuation", ")"],
["keyword", "where"],
- " F",
+ ["class-name", "F"],
["punctuation", ":"],
- " FnOnce",
+ ["class-name", "FnOnce"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", "{"],
diff --git a/tests/languages/rust/issue1339.test b/tests/languages/rust/issue1339.test
index df5d7d8..7f7f9a6 100644
--- a/tests/languages/rust/issue1339.test
+++ b/tests/languages/rust/issue1339.test
@@ -1,11 +1,12 @@
const ALL_CARDS: &'static [&'static char] = &["2"]
+
fn foo<'a> (first: &'a str, second: &'a str) => () { }
----------------------------------------------------
[
["keyword", "const"],
- " ALL_CARDS",
+ ["constant", "ALL_CARDS"],
["punctuation", ":"],
["operator", "&"],
["lifetime-annotation", "'static"],
@@ -19,6 +20,7 @@ fn foo<'a> (first: &'a str, second: &'a str) => () { }
["punctuation", "["],
["string", "\"2\""],
["punctuation", "]"],
+
["keyword", "fn"],
["function-definition", "foo"],
["operator", "<"],
@@ -29,13 +31,13 @@ fn foo<'a> (first: &'a str, second: &'a str) => () { }
["punctuation", ":"],
["operator", "&"],
["lifetime-annotation", "'a"],
- " str",
+ ["keyword", "str"],
["punctuation", ","],
" second",
["punctuation", ":"],
["operator", "&"],
["lifetime-annotation", "'a"],
- " str",
+ ["keyword", "str"],
["punctuation", ")"],
["operator", "=>"],
["punctuation", "("],
diff --git a/tests/languages/rust/keyword_feature.test b/tests/languages/rust/keyword_feature.test
index 5ec2bb7..a55ca38 100644
--- a/tests/languages/rust/keyword_feature.test
+++ b/tests/languages/rust/keyword_feature.test
@@ -7,11 +7,11 @@ box
break
const
continue
-crate
+crate;
do
dyn
else
-enum
+enum;
extern
final
fn;
@@ -23,7 +23,7 @@ let
loop
macro
match
-mod
+mod;
move
mut
override
@@ -34,13 +34,13 @@ return
self
Self
static
-struct
+struct;
super
trait
try
type
typeof
-union
+union;
unsafe
unsized
use
@@ -61,11 +61,11 @@ yield
["keyword", "break"],
["keyword", "const"],
["keyword", "continue"],
- ["keyword", "crate"],
+ ["keyword", "crate"], ["punctuation", ";"],
["keyword", "do"],
["keyword", "dyn"],
["keyword", "else"],
- ["keyword", "enum"],
+ ["keyword", "enum"], ["punctuation", ";"],
["keyword", "extern"],
["keyword", "final"],
["keyword", "fn"], ["punctuation", ";"],
@@ -77,7 +77,7 @@ yield
["keyword", "loop"],
["keyword", "macro"],
["keyword", "match"],
- ["keyword", "mod"],
+ ["keyword", "mod"], ["punctuation", ";"],
["keyword", "move"],
["keyword", "mut"],
["keyword", "override"],
@@ -88,13 +88,13 @@ yield
["keyword", "self"],
["keyword", "Self"],
["keyword", "static"],
- ["keyword", "struct"],
+ ["keyword", "struct"], ["punctuation", ";"],
["keyword", "super"],
["keyword", "trait"],
["keyword", "try"],
["keyword", "type"],
["keyword", "typeof"],
- ["keyword", "union"],
+ ["keyword", "union"], ["punctuation", ";"],
["keyword", "unsafe"],
["keyword", "unsized"],
["keyword", "use"],
diff --git a/tests/languages/rust/namespace_feature.test b/tests/languages/rust/namespace_feature.test
new file mode 100644
index 0000000..f858e07
--- /dev/null
+++ b/tests/languages/rust/namespace_feature.test
@@ -0,0 +1,186 @@
+use std::{
+ fs::File,
+ io::{BufRead, BufReader},
+ path::PathBuf,
+};
+use ::serde::de::{Error, Visitor};
+use std::sync::atomic::{AtomicBool, Ordering};
+pub mod sample;
+extern crate test;
+
+Result<Self, D::Error>
+
+where D: serde::Deserializer<'de>,
+
+serde_json::from_str(&line)
+self.read_records::<smol_str::SmolStr>()
+
+pub static ALLOCATOR: alloc::Tracing = alloc::Tracing::new();
+
+unsafe fn alloc(&self, layout: std::alloc::Layout) -> *mut u8 {}
+
+----------------------------------------------------
+
+[
+ ["keyword", "use"],
+ ["namespace", [
+ "std",
+ ["punctuation", "::"]
+ ]],
+ ["punctuation", "{"],
+ ["namespace", [
+ "fs",
+ ["punctuation", "::"]
+ ]],
+ ["class-name", "File"],
+ ["punctuation", ","],
+ ["namespace", [
+ "io",
+ ["punctuation", "::"]
+ ]],
+ ["punctuation", "{"],
+ ["class-name", "BufRead"],
+ ["punctuation", ","],
+ ["class-name", "BufReader"],
+ ["punctuation", "}"],
+ ["punctuation", ","],
+ ["namespace", [
+ "path",
+ ["punctuation", "::"]
+ ]],
+ ["class-name", "PathBuf"],
+ ["punctuation", ","],
+ ["punctuation", "}"],
+ ["punctuation", ";"],
+ ["keyword", "use"],
+ ["punctuation", "::"],
+ ["namespace", [
+ "serde",
+ ["punctuation", "::"],
+ "de",
+ ["punctuation", "::"]
+ ]],
+ ["punctuation", "{"],
+ ["class-name", "Error"],
+ ["punctuation", ","],
+ ["class-name", "Visitor"],
+ ["punctuation", "}"],
+ ["punctuation", ";"],
+ ["keyword", "use"],
+ ["namespace", [
+ "std",
+ ["punctuation", "::"],
+ "sync",
+ ["punctuation", "::"],
+ "atomic",
+ ["punctuation", "::"]
+ ]],
+ ["punctuation", "{"],
+ ["class-name", "AtomicBool"],
+ ["punctuation", ","],
+ ["class-name", "Ordering"],
+ ["punctuation", "}"],
+ ["punctuation", ";"],
+ ["keyword", "pub"],
+ ["keyword", "mod"],
+ ["module-declaration", "sample"],
+ ["punctuation", ";"],
+ ["keyword", "extern"],
+ ["keyword", "crate"],
+ ["module-declaration", "test"],
+ ["punctuation", ";"],
+
+ ["class-name", "Result"],
+ ["operator", "<"],
+ ["keyword", "Self"],
+ ["punctuation", ","],
+ ["class-name", "D"],
+ ["punctuation", "::"],
+ ["class-name", "Error"],
+ ["operator", ">"],
+
+ ["keyword", "where"],
+ ["class-name", "D"],
+ ["punctuation", ":"],
+ ["namespace", [
+ "serde",
+ ["punctuation", "::"]
+ ]],
+ ["class-name", "Deserializer"],
+ ["operator", "<"],
+ ["lifetime-annotation", "'de"],
+ ["operator", ">"],
+ ["punctuation", ","],
+
+ ["namespace", [
+ "serde_json",
+ ["punctuation", "::"]
+ ]],
+ ["function", "from_str"],
+ ["punctuation", "("],
+ ["operator", "&"],
+ "line",
+ ["punctuation", ")"],
+ ["keyword", "self"],
+ ["punctuation", "."],
+ ["function", "read_records"],
+ ["punctuation", "::"],
+ ["operator", "<"],
+ ["namespace", [
+ "smol_str",
+ ["punctuation", "::"]
+ ]],
+ ["class-name", "SmolStr"],
+ ["operator", ">"],
+ ["punctuation", "("],
+ ["punctuation", ")"],
+
+ ["keyword", "pub"],
+ ["keyword", "static"],
+ ["constant", "ALLOCATOR"],
+ ["punctuation", ":"],
+ ["namespace", [
+ "alloc",
+ ["punctuation", "::"]
+ ]],
+ ["class-name", "Tracing"],
+ ["operator", "="],
+ ["namespace", [
+ "alloc",
+ ["punctuation", "::"]
+ ]],
+ ["class-name", "Tracing"],
+ ["punctuation", "::"],
+ ["function", "new"],
+ ["punctuation", "("],
+ ["punctuation", ")"],
+ ["punctuation", ";"],
+
+ ["keyword", "unsafe"],
+ ["keyword", "fn"],
+ ["function-definition", "alloc"],
+ ["punctuation", "("],
+ ["operator", "&"],
+ ["keyword", "self"],
+ ["punctuation", ","],
+ " layout",
+ ["punctuation", ":"],
+ ["namespace", [
+ "std",
+ ["punctuation", "::"],
+ "alloc",
+ ["punctuation", "::"]
+ ]],
+ ["class-name", "Layout"],
+ ["punctuation", ")"],
+ ["punctuation", "->"],
+ ["operator", "*"],
+ ["keyword", "mut"],
+ ["keyword", "u8"],
+ ["punctuation", "{"],
+ ["punctuation", "}"]
+]
+
+----------------------------------------------------
+
+Checks for namespaces.