Skip to content

Commit

Permalink
Syntax: Some where improvements.
Browse files Browse the repository at this point in the history
- Fix "type-any-identifiers" misnamed in fn-where.
- Add `[foo]` slice type.
  • Loading branch information
ehuss committed Jun 16, 2018
1 parent 18edc8a commit 0a6b932
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 10 deletions.
24 changes: 14 additions & 10 deletions RustEnhanced.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ contexts:
- match: '<'
scope: punctuation.definition.generic.begin.rust
push: generic-angles-contents
# Alert the user of a broken generic construct
# Alert the use of a broken generic construct
- match: '.'
scope: invalid.illegal.rust
pop: true
Expand All @@ -435,13 +435,7 @@ contexts:
- include: strings
- match: '(?=\S)'
pop: true
- match: '\['
scope: punctuation.definition.group.begin.rust
push:
- match: '\]'
scope: punctuation.definition.group.end.rust
pop: true
- include: type-any-identifier
- include: type-slice
- match: '(?=>)'
pop: true
- match: '<'
Expand Down Expand Up @@ -502,9 +496,19 @@ contexts:
pop: true
- include: type-any-identifier
- include: type
- include: type-slice
- match: '\b_\b'
scope: keyword.operator.rust

type-slice:
- match: '\['
scope: punctuation.definition.group.begin.rust
push:
- match: '\]'
scope: punctuation.definition.group.end.rust
pop: true
- include: type-any-identifier

struct-identifier:
- match: '{{identifier}}(?=<)'
scope: entity.name.struct.rust
Expand Down Expand Up @@ -830,14 +834,14 @@ contexts:
push:
- match: '(?=<)'
push: generic-angles
- include: type-any-identifiers
- include: type-any-identifier
- match: '&'
scope: keyword.operator.rust
- match: '''{{identifier}}(?!\'')\b'
scope: storage.modifier.lifetime.rust
- match: '(?=\S)'
pop: true
- include: type-any-identifiers
- include: type-any-identifier
- match: ':'
scope: punctuation.separator.rust
- match: ';'
Expand Down
71 changes: 71 additions & 0 deletions syntax_test_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1203,3 +1203,74 @@ pub union Foo<'a, Y: Baz>
// that we don't accidentally interpret it as a keyword.
fn union() {}
// ^^^^^ meta.function entity.name.function

fn f<'b: 'a>(self) -> &'b mut [i32] where 'a: 'b { }
// ^^^^^^^^^^^^^^ meta.function meta.function.return-type
// ^ meta.function meta.function.return-type punctuation.definition.group.begin
// ^^^ meta.function meta.function.return-type storage.type
// ^ meta.function meta.function.return-type punctuation.definition.group.end
// ^^^^^ meta.function meta.where keyword.other
// ^^ meta.function meta.where storage.modifier.lifetime
// ^ meta.function meta.where punctuation.separator
// ^^ meta.function meta.where storage.modifier.lifetime
// ^ meta.function meta.block punctuation.definition.block.begin
// ^ meta.function meta.block punctuation.definition.block.end

fn f<F>(func: F) -> usize
// ^^ meta.function meta.function.return-type punctuation.separator
// ^^^^^ meta.function meta.function.return-type storage.type
where F: Fn(usize) -> usize {}
// ^^^^^ meta.function meta.where keyword.other
// ^^^^^^^^^^^^^^^^^^^^^ meta.function meta.where
// ^ punctuation.separator
// ^^ support.type
// ^ punctuation.definition.type.begin
// ^^^^^ storage.type
// ^ punctuation.definition.type.end
// ^^ meta.function.return-type punctuation.separator
// ^^^^^ meta.function.return-type storage.type
// ^ meta.function meta.block punctuation.definition.block.begin
// ^ meta.function meta.block punctuation.definition.block.end

fn f<L, R>(lhs: L, rhs: R)
where L: IntoIterator<Item=(&'a i32, &'a i32)>,
// ^^^^^ meta.function meta.where keyword.other
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function meta.where
// ^^^^^^^^^^^^ support.type
// ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.generic
// ^ punctuation.definition.generic.begin
// ^ punctuation.definition.type.begin
// ^ keyword.operator
// ^^ storage.modifier.lifetime
// ^^^ storage.type
// ^ keyword.operator
// ^^ storage.modifier.lifetime
// ^^^ storage.type
// ^ punctuation.definition.type.end
// ^ punctuation.definition.generic.end
R: IntoIterator<Item=(&'a i32, &'a i32)>, {}
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function meta.where
// ^ meta.function meta.block punctuation.definition.block.begin
// ^ meta.function meta.block punctuation.definition.block.end
fn f<F: Fn(usize) -> usize>(func: f) {}
// ^^^^^^^^^^^^^^^^^^^^^^^ meta.generic
// ^ meta.generic punctuation.definition.generic.begin
// ^ meta.generic punctuation.separator
// ^^ meta.generic support.type
// ^ meta.generic punctuation.definition.type.begin
// ^^^^^ meta.generic storage.type
// ^ meta.generic punctuation.definition.type.end
// ^^^^^ meta.generic meta.function.return-type storage.type
// ^ meta.generic punctuation.definition.generic.end
// ^ meta.function meta.function.parameters punctuation.definition.parameters.begin
// ^^^^ meta.function meta.function.parameters variable.parameter
fn f<L: IntoIterator<Item=(&'a i32, &'a i32)>>(lhs: L) {}
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.generic
// ^ punctuation.definition.generic.begin
// ^ punctuation.definition.generic.begin
// ^ punctuation.definition.type.begin
// ^^ storage.modifier.lifetime
// ^^^ storage.type
// ^ punctuation.definition.generic.begin
// ^ punctuation.definition.generic.end
// ^ meta.function meta.function.parameters punctuation.definition.parameters.begin

0 comments on commit 0a6b932

Please sign in to comment.