Skip to content

Commit eac441c

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

File tree

2 files changed

+85
-9
lines changed

2 files changed

+85
-9
lines changed

RustEnhanced.sublime-syntax

+13-9
Original file line numberDiff line numberDiff line change
@@ -461,13 +461,7 @@ contexts:
461461
- include: strings
462462
- match: '(?=\S)'
463463
pop: true
464-
- match: '\['
465-
scope: punctuation.definition.group.begin.rust
466-
push:
467-
- match: '\]'
468-
scope: punctuation.definition.group.end.rust
469-
pop: true
470-
- include: type-any-identifier
464+
- include: type-slice
471465
- match: '(?=>)'
472466
pop: true
473467
- match: '<'
@@ -528,9 +522,19 @@ contexts:
528522
pop: true
529523
- include: type-any-identifier
530524
- include: type
525+
- include: type-slice
531526
- match: '\b_\b'
532527
scope: keyword.operator.rust
533528

529+
type-slice:
530+
- match: '\['
531+
scope: punctuation.definition.group.begin.rust
532+
push:
533+
- match: '\]'
534+
scope: punctuation.definition.group.end.rust
535+
pop: true
536+
- include: type-any-identifier
537+
534538
struct-identifier:
535539
- meta_scope: meta.struct.rust
536540
- match: '{{identifier}}(?=<)'
@@ -859,14 +863,14 @@ contexts:
859863
push:
860864
- match: '(?=<)'
861865
push: generic-angles
862-
- include: type-any-identifiers
866+
- include: type-any-identifier
863867
- match: '&'
864868
scope: keyword.operator.rust
865869
- match: '''{{identifier}}(?!\'')\b'
866870
scope: storage.modifier.lifetime.rust
867871
- match: '(?=\S)'
868872
pop: true
869-
- include: type-any-identifiers
873+
- include: type-any-identifier
870874
- match: ':'
871875
scope: punctuation.separator.rust
872876
- match: ';'

syntax_test_rust.rs

+72
Original file line numberDiff line numberDiff line change
@@ -1442,3 +1442,75 @@ struct S (
14421442
// ^ meta.struct punctuation.definition.group.end
14431443
// ^^^ meta.struct storage.type
14441444
);
1445+
1446+
// Various tests on `where`.
1447+
fn f<'b: 'a>(self) -> &'b mut [i32] where 'a: 'b { }
1448+
// ^^^^^^^^^^^^^^ meta.function meta.function.return-type
1449+
// ^ meta.function meta.function.return-type punctuation.definition.group.begin
1450+
// ^^^ meta.function meta.function.return-type storage.type
1451+
// ^ meta.function meta.function.return-type punctuation.definition.group.end
1452+
// ^^^^^ meta.function meta.where keyword.other
1453+
// ^^ meta.function meta.where storage.modifier.lifetime
1454+
// ^ meta.function meta.where punctuation.separator
1455+
// ^^ meta.function meta.where storage.modifier.lifetime
1456+
// ^ meta.function meta.block punctuation.definition.block.begin
1457+
// ^ meta.function meta.block punctuation.definition.block.end
1458+
1459+
fn f<F>(func: F) -> usize
1460+
// ^^ meta.function meta.function.return-type punctuation.separator
1461+
// ^^^^^ meta.function meta.function.return-type storage.type
1462+
where F: Fn(usize) -> usize {}
1463+
// ^^^^^ meta.function meta.where keyword.other
1464+
// ^^^^^^^^^^^^^^^^^^^^^ meta.function meta.where
1465+
// ^ punctuation.separator
1466+
// ^^ support.type
1467+
// ^ punctuation.definition.type.begin
1468+
// ^^^^^ storage.type
1469+
// ^ punctuation.definition.type.end
1470+
// ^^ meta.function.return-type punctuation.separator
1471+
// ^^^^^ meta.function.return-type storage.type
1472+
// ^ meta.function meta.block punctuation.definition.block.begin
1473+
// ^ meta.function meta.block punctuation.definition.block.end
1474+
1475+
fn f<L, R>(lhs: L, rhs: R)
1476+
where L: IntoIterator<Item=(&'a i32, &'a i32)>,
1477+
// ^^^^^ meta.function meta.where keyword.other
1478+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function meta.where
1479+
// ^^^^^^^^^^^^ support.type
1480+
// ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.generic
1481+
// ^ punctuation.definition.generic.begin
1482+
// ^ punctuation.definition.type.begin
1483+
// ^ keyword.operator
1484+
// ^^ storage.modifier.lifetime
1485+
// ^^^ storage.type
1486+
// ^ keyword.operator
1487+
// ^^ storage.modifier.lifetime
1488+
// ^^^ storage.type
1489+
// ^ punctuation.definition.type.end
1490+
// ^ punctuation.definition.generic.end
1491+
R: IntoIterator<Item=(&'a i32, &'a i32)>, {}
1492+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function meta.where
1493+
// ^ meta.function meta.block punctuation.definition.block.begin
1494+
// ^ meta.function meta.block punctuation.definition.block.end
1495+
fn f<F: Fn(usize) -> usize>(func: f) {}
1496+
// ^^^^^^^^^^^^^^^^^^^^^^^ meta.generic
1497+
// ^ meta.generic punctuation.definition.generic.begin
1498+
// ^ meta.generic punctuation.separator
1499+
// ^^ meta.generic support.type
1500+
// ^ meta.generic punctuation.definition.type.begin
1501+
// ^^^^^ meta.generic storage.type
1502+
// ^ meta.generic punctuation.definition.type.end
1503+
// ^^^^^ meta.generic meta.function.return-type storage.type
1504+
// ^ meta.generic punctuation.definition.generic.end
1505+
// ^ meta.function meta.function.parameters punctuation.definition.parameters.begin
1506+
// ^^^^ meta.function meta.function.parameters variable.parameter
1507+
fn f<L: IntoIterator<Item=(&'a i32, &'a i32)>>(lhs: L) {}
1508+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.generic
1509+
// ^ punctuation.definition.generic.begin
1510+
// ^ punctuation.definition.generic.begin
1511+
// ^ punctuation.definition.type.begin
1512+
// ^^ storage.modifier.lifetime
1513+
// ^^^ storage.type
1514+
// ^ punctuation.definition.generic.begin
1515+
// ^ punctuation.definition.generic.end
1516+
// ^ meta.function meta.function.parameters punctuation.definition.parameters.begin

0 commit comments

Comments
 (0)