Skip to content

Commit 5e96f36

Browse files
authored
Merge pull request #533 from ehuss/use-bound
Add support for `use` bounds
2 parents 88623c5 + 654faff commit 5e96f36

File tree

2 files changed

+114
-8
lines changed

2 files changed

+114
-8
lines changed

RustEnhanced.sublime-syntax

+26-7
Original file line numberDiff line numberDiff line change
@@ -364,13 +364,6 @@ contexts:
364364
scope: support.type.rust
365365

366366
return-type:
367-
- match: '\bimpl\b'
368-
scope: storage.type.impl.rust
369-
push:
370-
- include: comments
371-
- include: impl-generic
372-
- match: '(?=\S)'
373-
pop: true
374367
- match: '->'
375368
scope: punctuation.separator.rust
376369
push:
@@ -578,6 +571,31 @@ contexts:
578571
- match: '[-+%/*]'
579572
scope: keyword.operator.arithmetic.rust
580573

574+
impl-trait:
575+
- match: '\bimpl\b'
576+
scope: storage.type.impl.rust
577+
push:
578+
- match: '\buse\b'
579+
scope: keyword.other.rust
580+
push:
581+
- match: '<'
582+
scope: punctuation.definition.generic.begin.rust
583+
set:
584+
- match: '>'
585+
scope: punctuation.definition.generic.end.rust
586+
pop: true
587+
- include: lifetime
588+
- match: ','
589+
scope: punctuation.separator.rust
590+
- match: \b(Self)\b
591+
scope: keyword.other.rust
592+
- match: '{{identifier}}'
593+
- match: '(?=\S)'
594+
pop: true
595+
- include: type-any-identifier
596+
- match: '(?=\S)'
597+
pop: true
598+
581599
type-any-identifier:
582600
- include: comments
583601
- include: support-type
@@ -604,6 +622,7 @@ contexts:
604622
pop: true
605623
- include: type-any-identifier
606624
- include: lifetime
625+
- include: impl-trait
607626
- match: '\b([[:upper:]]|_*[[:upper:]][[:alnum:]_]*[[:lower:]][[:alnum:]_]*)\b(::)'
608627
scope: meta.path.rust storage.type.rust
609628
captures:

tests/syntax-rust/syntax_test_generics.rs

+88-1
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,95 @@ fn function<const N: u16>() {
439439
// ^^^ storage.type.numeric
440440
let b: Byte<b'a'>;
441441
// ^^^^^^ meta.function meta.block meta.generic
442-
// ^^^^ string.quoted.single.rust
442+
// ^^^^ string.quoted.single
443443
// ^ storage.type.string
444444
// ^ punctuation.definition.string.begin
445445
// ^ punctuation.definition.string.end
446446
}
447+
448+
fn impl_trait_return_use_bound<'a>() -> impl for<'b> Trait1<Item = impl Trait2<'a> + use<'a>> {}
449+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function meta.function.return-type
450+
// ^^ punctuation.separator
451+
// ^^^^ storage.type.impl
452+
// ^^^ keyword.other
453+
// ^ meta.generic punctuation.definition.generic.begin
454+
// ^ meta.generic punctuation.definition.generic.end
455+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.generic
456+
// ^ meta.generic punctuation.definition.generic.begin
457+
// ^ meta.generic keyword.operator
458+
// ^^^^ meta.generic storage.type.impl
459+
// ^^^^^^^^^^ meta.generic meta.generic
460+
// ^ punctuation.definition.generic.begin
461+
// ^^ storage.modifier.lifetime
462+
// ^ punctuation.definition.generic.end
463+
// ^ keyword.operator
464+
// ^^^^^^^^ meta.generic
465+
// ^^^ keyword.other
466+
// ^ punctuation.definition.generic.begin
467+
// ^^ storage.modifier.lifetime
468+
// ^^ punctuation.definition.generic.end
469+
470+
fn impl_trait_use<'a, foo>() -> impl Trait1 + use<'a, Self, foo> {}
471+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function meta.function.return-type
472+
// ^ keyword.operator
473+
// ^^^ keyword.other
474+
// ^ punctuation.definition.generic.begin
475+
// ^^ storage.modifier.lifetime
476+
// ^ punctuation.separator
477+
// ^^^^ keyword.other
478+
// ^ punctuation.separator
479+
// ^ punctuation.definition.generic.end
480+
481+
fn impl_trait_return1<'a, 'b>() -> impl Trait<&'a u8, Ty = impl Sized + 'b> {}
482+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function meta.function.return-type
483+
// ^^ punctuation.separator
484+
// ^^^^ storage.type.impl
485+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.generic
486+
// ^ punctuation.definition.generic.begin
487+
// ^ keyword.operator
488+
// ^^ storage.modifier.lifetime
489+
// ^^ storage.type
490+
// ^ punctuation.separator
491+
// ^ keyword.operator
492+
// ^^^^ storage.type.impl
493+
// ^^^^^ support.type
494+
// ^ keyword.operator
495+
// ^^ storage.modifier.lifetime
496+
// ^ punctuation.definition.generic.end
497+
fn impl_trait_return2() -> impl Debug + 'a {}
498+
// ^^^^^^^^^^^^^^^^^^ meta.function meta.function.return-type
499+
// ^^^^ storage.type.impl
500+
// ^ keyword.operator
501+
// ^^ storage.modifier.lifetime
502+
503+
fn impl_trait_param(x: impl FnOnce(&[u8]) -> &[u8]) {}
504+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function meta.function.parameters
505+
// ^^^^ storage.type.impl
506+
// ^^^^^^ support.type
507+
// ^ meta.group punctuation.section.group.begin
508+
// ^ meta.group keyword.operator
509+
// ^ meta.group punctuation.section.group.begin
510+
// ^^ meta.group storage.type
511+
// ^^ meta.group punctuation.section.group.end
512+
// ^^^^^^^^ meta.function meta.function.parameters meta.function.return-type
513+
// ^^ punctuation.separator
514+
// ^ meta.function.parameters keyword.operator
515+
// ^ meta.function.parameters punctuation.section.group.begin
516+
// ^^ meta.function.parameters storage.type
517+
// ^ meta.function.parameters punctuation.section.group.end
518+
519+
520+
fn impl_trait_with_plus() -> impl Iterator<Item = hir::GenericParam<'hir>> + Captures<'a> + Captures<'s> {}
521+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function meta.function.return-type
522+
// ^^^^ storage.type.impl
523+
// ^^^^^^^^ support.type
524+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.generic
525+
// ^ keyword.operator
526+
// ^^^^ storage.modifier.lifetime
527+
// ^ keyword.operator
528+
// ^^^^^^^^^^^^ meta.generic
529+
// ^^ storage.modifier.lifetime
530+
// ^ keyword.operator
531+
// ^^^^^^^^^^^^ meta.generic
532+
// ^^ storage.modifier.lifetime
533+

0 commit comments

Comments
 (0)