diff --git a/RustEnhanced.sublime-syntax b/RustEnhanced.sublime-syntax index 199e3af6..63f8ddad 100644 --- a/RustEnhanced.sublime-syntax +++ b/RustEnhanced.sublime-syntax @@ -534,7 +534,6 @@ contexts: generic-angles-contents: - include: comments - include: attribute - - include: type-slice-or-array - match: '(?=>)' pop: true - match: '<' @@ -544,7 +543,17 @@ contexts: scope: punctuation.definition.generic.end.rust pop: true - include: generic-angles-contents + - include: bool + # byte must be before type-any-identifier since it doesn't know about byte tokens + - include: byte - include: type-any-identifier + # char must be after type-any-identifier to deal with conflict with lifetimes + - include: char + # Handle negative integers (technically unary negative expression with a literal expression) + - match: '-' + scope: keyword.operator.arithmetic.rust + - include: integers + - include: block - match: '{{identifier}}' - match: ':|,' scope: punctuation.separator.rust @@ -1501,11 +1510,14 @@ contexts: - match: '[:;,]' scope: punctuation.separator.rust + bool: + - match: \b(true|false)\b + scope: constant.language.rust + keywords: # All keywords. Note in `statements` some of these are superseded by more # specific rules. - - match: \b(true|false)\b - scope: constant.language.rust + - include: bool - match: \b(let|const|static)\b scope: storage.type.rust diff --git a/tests/syntax-rust/syntax_test_generics.rs b/tests/syntax-rust/syntax_test_generics.rs index d9e07b9f..a46e8512 100644 --- a/tests/syntax-rust/syntax_test_generics.rs +++ b/tests/syntax-rust/syntax_test_generics.rs @@ -350,3 +350,97 @@ fn factory() -> Box i32> { // ^^^ storage.type Box::new(|x| x + 1) } + +// Const generics. +trait Foo { +// ^^^^^^^^^^^^^^^^ meta.trait meta.generic +// ^ punctuation.definition.generic.begin +// ^^^^^ storage.modifier +// ^ meta.trait meta.generic punctuation.separator +// ^^^^^ storage.type +// ^ punctuation.definition.generic.end + fn method(&mut self, arr: [[u8; M]; N]); +// ^^^^^^^^^^^^^^^^ meta.generic +// ^ punctuation.definition.generic.begin +// ^^^^^ storage.modifier +// ^ punctuation.separator +// ^^^^^ storage.type +// ^ punctuation.definition.generic.end +} + +struct Bar { +// ^^^^^^^^^^^^^^^^^^^ meta.struct meta.generic +// ^ punctuation.definition.generic.begin +// ^ punctuation.separator +// ^^^^^ storage.modifier +// ^ punctuation.separator +// ^^^^^ storage.type +// ^ punctuation.definition.generic.end + inner: [T; N], +} + +impl Foo for Bar { +// ^^^^^^^^^^^^^^^^ meta.impl meta.generic +// ^ punctuation.definition.generic.begin +// ^^^^^ storage.modifier +// ^ punctuation.separator +// ^^^^^ storage.type +// ^ punctuation.definition.generic.end + fn method(&mut self, arr: [[u8; M]; N]) {} +} + +struct Bool; +// ^^^^^^^^^^^^^^^ meta.struct meta.generic +// ^ punctuation.definition.generic.begin +// ^^^^^ storage.modifier +// ^ punctuation.separator +// ^^^^ storage.type +// ^ punctuation.definition.generic.end +struct Char; +struct Int; +struct Byte; + +fn function() { + const fn foo(x: bool) -> usize { 2 } + let x: Bar = Bar { inner: [1; 1] }; +// ^^^^^^^^ meta.function meta.block meta.generic +// ^ meta.function meta.block meta.generic punctuation.definition.generic.begin +// ^^^ meta.function meta.block meta.generic storage.type +// ^ meta.function meta.block meta.generic punctuation.separator +// ^ meta.function meta.block meta.generic constant.numeric.integer.decimal +// ^ meta.function meta.block meta.generic punctuation.definition.generic.end + let y: Bar 2) / 2 }> = Bar { inner: [1; 1] }; +// ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function meta.block meta.generic +// ^ punctuation.definition.generic.begin +// ^^^^^^^^^^^^^^^^^^ meta.block +// ^^^ support.function +// ^ meta.group punctuation.section.group.begin +// ^ keyword.operator.comparison +// ^ punctuation.section.group.end +// ^ keyword.operator.arithmetic +// ^ constant.numeric.integer.decimal +// ^ punctuation.section.block.end +// ^ punctuation.definition.generic.end + let b: Bool; +// ^^^^ meta.function meta.block meta.generic constant.language + let c: Char<'∂'>; +// ^^^ meta.function meta.block meta.generic string.quoted.single +// ^ punctuation.definition.string.begin +// ^ punctuation.definition.string.end + let i: Int<-1>; +// ^^^^ meta.function meta.block meta.generic +// ^ keyword.operator.arithmetic +// ^ constant.numeric.integer.decimal + let i: Int<0b1011>; +// ^^^^^^ meta.function meta.block meta.generic constant.numeric.integer.binary + let i: Int<4i32>; +// ^^^^^^ meta.function meta.block meta.generic +// ^ constant.numeric.integer.decimal +// ^^^ storage.type.numeric + let b: Byte; +// ^^^^^^ meta.function meta.block meta.generic +// ^^^^ string.quoted.single.rust +// ^ storage.type.string +// ^ punctuation.definition.string.begin +// ^ punctuation.definition.string.end +}