Skip to content

Commit 2c2772b

Browse files
keith-hallwbond
authored andcommitted
[Rust] scope support types in generics (#1820)
1 parent 4769288 commit 2c2772b

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Rust/Rust.sublime-syntax

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ variables:
1010
escaped_byte: '\\(x\h{2}|n|r|t|0|"|''|\\)'
1111
escaped_char: '\\(x\h{2}|n|r|t|0|"|''|\\|u\{\h{1,6}\})'
1212
int_suffixes: 'i8|i16|i32|i64|isize|u8|u16|u32|u64|usize'
13+
support_type: \b(Copy|Send|Sized|Sync|Drop|Fn|FnMut|FnOnce|Box|ToOwned|Clone|PartialEq|PartialOrd|Eq|Ord|AsRef|AsMut|Into|From|Default|Iterator|Extend|IntoIterator|DoubleEndedIterator|ExactSizeIterator|Option|Some|None|Result|Ok|Err|SliceConcatExt|String|ToString|Vec)\b
1314
contexts:
1415
main:
1516
- include: statements
@@ -188,7 +189,7 @@ contexts:
188189
- match: '\b[[:lower:]_][[:lower:][:digit:]_]*!(?=\s*(\(|\{|\[))'
189190
scope: support.macro.rust
190191

191-
- match: \b(Copy|Send|Sized|Sync|Drop|Fn|FnMut|FnOnce|Box|ToOwned|Clone|PartialEq|PartialOrd|Eq|Ord|AsRef|AsMut|Into|From|Default|Iterator|Extend|IntoIterator|DoubleEndedIterator|ExactSizeIterator|Option|Some|None|Result|Ok|Err|SliceConcatExt|String|ToString|Vec)\b
192+
- match: '{{support_type}}'
192193
scope: support.type.rust
193194

194195
- include: basic-identifiers
@@ -427,7 +428,9 @@ contexts:
427428
- include: block
428429

429430
type:
430-
- match: '{{identifier}}(?=<)'
431+
- match: (?:{{support_type}}|{{identifier}})(?=<)
432+
captures:
433+
1: support.type.rust
431434
push: generic-angles
432435
- match: \b(Self|i8|i16|i32|i64|isize|u8|u16|u32|u64|usize|f32|f64|bool|char|str)\b
433436
scope: storage.type.rust
@@ -484,6 +487,8 @@ contexts:
484487
pop: true
485488
- include: generic-angles-contents
486489
- include: type-any-identifier
490+
- match: '{{support_type}}'
491+
scope: support.type.rust
487492
- match: ':'
488493
scope: punctuation.separator.rust
489494
- match: '\+'

Rust/syntax_test_rust.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ struct PrintableStruct(Box<i32>);
214214
//^^^^ storage.type.struct
215215
// ^^^^^^^^^^^^^^^ entity.name.struct
216216
// ^ punctuation.section.group.begin
217+
// ^^^ support.type
217218
// ^^^^^^^^ meta.generic
218219
// ^ punctuation.definition.generic.begin
219220
// ^^^ storage.type
@@ -808,6 +809,7 @@ pub trait Animal {
808809

809810
fn collect_vec() {
810811
let _: Vec<(usize, usize)> = (0..10).enumerate().collect::<Vec<_>>();
812+
// ^^^ support.type
811813
// ^^^^^^^^^^^^^^^^^^^ meta.generic
812814
// ^ punctuation.section.group.begin
813815
// ^^^^^ storage.type
@@ -825,6 +827,7 @@ fn collect_vec() {
825827
// ^ punctuation.accessor.dot
826828
// ^^ punctuation.accessor
827829
// ^^^^^^^^ meta.generic
830+
// ^^^ support.type
828831
// ^^^^^^ meta.generic meta.generic
829832
// ^ keyword.operator
830833
let _: Vec<(usize, usize)> = vec!();
@@ -833,6 +836,8 @@ fn collect_vec() {
833836
// ^^^^ support.macro
834837
let _: Vec<(usize, usize)> = vec![];
835838
// ^^^^ support.macro
839+
let _: Vec<String> = vec![];
840+
// ^^^^^^ meta.generic support.type
836841
}
837842

838843
macro_rules! forward_ref_binop [

0 commit comments

Comments
 (0)