Skip to content

Commit 950cfad

Browse files
committed
Syntax: Some where improvements.
- Fix "type-any-identifiers" misnamed in fn-where. - Add `[foo]` slice type.
1 parent 18edc8a commit 950cfad

File tree

2 files changed

+84
-9
lines changed

2 files changed

+84
-9
lines changed

RustEnhanced.sublime-syntax

+13-9
Original file line numberDiff line numberDiff line change
@@ -435,13 +435,7 @@ contexts:
435435
- include: strings
436436
- match: '(?=\S)'
437437
pop: true
438-
- match: '\['
439-
scope: punctuation.definition.group.begin.rust
440-
push:
441-
- match: '\]'
442-
scope: punctuation.definition.group.end.rust
443-
pop: true
444-
- include: type-any-identifier
438+
- include: type-slice
445439
- match: '(?=>)'
446440
pop: true
447441
- match: '<'
@@ -502,9 +496,19 @@ contexts:
502496
pop: true
503497
- include: type-any-identifier
504498
- include: type
499+
- include: type-slice
505500
- match: '\b_\b'
506501
scope: keyword.operator.rust
507502

503+
type-slice:
504+
- match: '\['
505+
scope: punctuation.definition.group.begin.rust
506+
push:
507+
- match: '\]'
508+
scope: punctuation.definition.group.end.rust
509+
pop: true
510+
- include: type-any-identifier
511+
508512
struct-identifier:
509513
- match: '{{identifier}}(?=<)'
510514
scope: entity.name.struct.rust
@@ -830,14 +834,14 @@ contexts:
830834
push:
831835
- match: '(?=<)'
832836
push: generic-angles
833-
- include: type-any-identifiers
837+
- include: type-any-identifier
834838
- match: '&'
835839
scope: keyword.operator.rust
836840
- match: '''{{identifier}}(?!\'')\b'
837841
scope: storage.modifier.lifetime.rust
838842
- match: '(?=\S)'
839843
pop: true
840-
- include: type-any-identifiers
844+
- include: type-any-identifier
841845
- match: ':'
842846
scope: punctuation.separator.rust
843847
- match: ';'

syntax_test_rust.rs

+71
Original file line numberDiff line numberDiff line change
@@ -1203,3 +1203,74 @@ pub union Foo<'a, Y: Baz>
12031203
// that we don't accidentally interpret it as a keyword.
12041204
fn union() {}
12051205
// ^^^^^ meta.function entity.name.function
1206+
1207+
fn f<'b: 'a>(self) -> &'b mut [i32] where 'a: 'b { }
1208+
// ^^^^^^^^^^^^^^ meta.function meta.function.return-type
1209+
// ^ meta.function meta.function.return-type punctuation.definition.group.begin
1210+
// ^^^ meta.function meta.function.return-type storage.type
1211+
// ^ meta.function meta.function.return-type punctuation.definition.group.end
1212+
// ^^^^^ meta.function meta.where keyword.other
1213+
// ^^ meta.function meta.where storage.modifier.lifetime
1214+
// ^ meta.function meta.where punctuation.separator
1215+
// ^^ meta.function meta.where storage.modifier.lifetime
1216+
// ^ meta.function meta.block punctuation.definition.block.begin
1217+
// ^ meta.function meta.block punctuation.definition.block.end
1218+
1219+
fn f<F>(func: F) -> usize
1220+
// ^^ meta.function meta.function.return-type punctuation.separator
1221+
// ^^^^^ meta.function meta.function.return-type storage.type
1222+
where F: Fn(usize) -> usize {}
1223+
// ^^^^^ meta.function meta.where keyword.other
1224+
// ^^^^^^^^^^^^^^^^^^^^^ meta.function meta.where
1225+
// ^ punctuation.separator
1226+
// ^^ support.type
1227+
// ^ punctuation.definition.type.begin
1228+
// ^^^^^ storage.type
1229+
// ^ punctuation.definition.type.end
1230+
// ^^ meta.function.return-type punctuation.separator
1231+
// ^^^^^ meta.function.return-type storage.type
1232+
// ^ meta.function meta.block punctuation.definition.block.begin
1233+
// ^ meta.function meta.block punctuation.definition.block.end
1234+
1235+
fn f<L, R>(lhs: L, rhs: R)
1236+
where L: IntoIterator<Item=(&'a i32, &'a i32)>,
1237+
// ^^^^^ meta.function meta.where keyword.other
1238+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function meta.where
1239+
// ^^^^^^^^^^^^ support.type
1240+
// ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.generic
1241+
// ^ punctuation.definition.generic.begin
1242+
// ^ punctuation.definition.type.begin
1243+
// ^ keyword.operator
1244+
// ^^ storage.modifier.lifetime
1245+
// ^^^ storage.type
1246+
// ^ keyword.operator
1247+
// ^^ storage.modifier.lifetime
1248+
// ^^^ storage.type
1249+
// ^ punctuation.definition.type.end
1250+
// ^ punctuation.definition.generic.end
1251+
R: IntoIterator<Item=(&'a i32, &'a i32)>, {}
1252+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function meta.where
1253+
// ^ meta.function meta.block punctuation.definition.block.begin
1254+
// ^ meta.function meta.block punctuation.definition.block.end
1255+
fn f<F: Fn(usize) -> usize>(func: f) {}
1256+
// ^^^^^^^^^^^^^^^^^^^^^^^ meta.generic
1257+
// ^ meta.generic punctuation.definition.generic.begin
1258+
// ^ meta.generic punctuation.separator
1259+
// ^^ meta.generic support.type
1260+
// ^ meta.generic punctuation.definition.type.begin
1261+
// ^^^^^ meta.generic storage.type
1262+
// ^ meta.generic punctuation.definition.type.end
1263+
// ^^^^^ meta.generic meta.function.return-type storage.type
1264+
// ^ meta.generic punctuation.definition.generic.end
1265+
// ^ meta.function meta.function.parameters punctuation.definition.parameters.begin
1266+
// ^^^^ meta.function meta.function.parameters variable.parameter
1267+
fn f<L: IntoIterator<Item=(&'a i32, &'a i32)>>(lhs: L) {}
1268+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.generic
1269+
// ^ punctuation.definition.generic.begin
1270+
// ^ punctuation.definition.generic.begin
1271+
// ^ punctuation.definition.type.begin
1272+
// ^^ storage.modifier.lifetime
1273+
// ^^^ storage.type
1274+
// ^ punctuation.definition.generic.begin
1275+
// ^ punctuation.definition.generic.end
1276+
// ^ meta.function meta.function.parameters punctuation.definition.parameters.begin

0 commit comments

Comments
 (0)