Skip to content

Commit aa59aa9

Browse files
committed
highlight where in struct defn properly
1 parent 247ffbe commit aa59aa9

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

RustEnhanced.sublime-syntax

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,10 @@ contexts:
489489
struct-body:
490490
- meta_scope: meta.struct.rust
491491
- include: comments
492+
- match: '(?=\bwhere\b)'
493+
push: impl-where
492494
- match: '(?=\()'
493-
set: struct-tuple
495+
push: struct-tuple
494496
- match: '(?=\{)'
495497
set: struct-classic
496498
- match: '(?=;)'
@@ -663,7 +665,7 @@ contexts:
663665
- match: '(?=\{)'
664666
set: impl-body
665667
- match: '(?=\bwhere\b)'
666-
set: impl-where
668+
push: impl-where
667669
- match: '{{identifier}}(?=<)'
668670
scope: entity.name.impl.rust
669671
push: generic-angles
@@ -677,10 +679,10 @@ contexts:
677679
scope: storage.modifier.lifetime.rust
678680

679681
impl-where:
680-
- meta_scope: meta.impl.rust
682+
- meta_scope: meta.where.rust
681683
- include: comments
682-
- match: '(?=\{)'
683-
set: impl-body
684+
- match: '(?=(\{|;))'
685+
pop: true
684686
- match: \bwhere\b
685687
scope: keyword.other.rust
686688
- match: \bfor\b
@@ -755,7 +757,7 @@ contexts:
755757
pop: true
756758

757759
fn-where:
758-
- meta_scope: meta.function.rust
760+
- meta_scope: meta.function.rust meta.where.rust
759761
- include: comments
760762
- match: '(?=\{)'
761763
set: fn-body

syntax_test_rust.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ impl<'a, T: MyTrait + OtherTrait> PrintInOption for T where
770770
// ^ keyword.operator
771771
// ^^^ keyword.other
772772
// ^ entity.name.impl
773-
// ^^^^^ keyword.other
773+
// ^^^^^ meta.where keyword.other
774774
Option<T>: Debug {
775775
//^^^^^^^^^^^^^^^^^^^^ meta.impl
776776
fn print_in_option(self) {
@@ -948,7 +948,7 @@ pub fn new<T>() -> Fibonacci<T>
948948

949949
pub fn new<T>() -> Fibonacci<T>
950950
where for <'a> &'a T: Add<Output = T>,
951-
// ^^^^^ keyword.other.rust
951+
// ^^^^^ meta.where keyword.other.rust
952952
// ^^^ keyword.other.rust
953953
// ^ punctuation.definition.generic.begin.rust
954954
// ^^ storage.modifier.lifetime.rust
@@ -1066,3 +1066,33 @@ fn numbers() -> impl Iterator<Item = u64> {
10661066
Generator(move || for a in (0..10) { yield a; } })
10671067
// ^^^^^ keyword.control
10681068
}
1069+
1070+
pub struct IterHolder<A> where A: Number {
1071+
// ^^^ meta.struct meta.generic
1072+
// ^^^^^ meta.struct meta.where keyword.other
1073+
// ^^^^^^ meta.struct meta.where storage.type
1074+
// ^ meta.struct punctuation.definition.block.begin.rust
1075+
num: A
1076+
}
1077+
1078+
pub struct IterHolder<A>
1079+
// ^^^ meta.struct meta.generic
1080+
where
1081+
// <- meta.struct meta.where keyword.other
1082+
A: Number {
1083+
// ^^^^^^ meta.struct meta.where storage.type
1084+
num: A
1085+
}
1086+
1087+
struct A<T>(T) where T: AsRef<str>;
1088+
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.struct
1089+
// ^ punctuation.terminator
1090+
// ^^^^^ meta.struct meta.where keyword.other
1091+
pub struct A<T>(T)
1092+
//^^^^^^^^^^^^ meta.struct
1093+
// ^^^^^^ meta.struct storage.type
1094+
where
1095+
//^^^ meta.struct meta.where keyword.other
1096+
T: AsRef<str>;
1097+
//^^^^^^^^^^^^^^^ meta.struct
1098+
// ^ punctuation.terminator

0 commit comments

Comments
 (0)