diff --git a/Rust/Rust.sublime-syntax b/Rust/Rust.sublime-syntax index e07eb54eb8..43cd89c626 100644 --- a/Rust/Rust.sublime-syntax +++ b/Rust/Rust.sublime-syntax @@ -564,7 +564,6 @@ contexts: types: # matches stray identifiers as a types because a type is expected - include: comments - - include: impl-types - include: return-type - match: '&' scope: keyword.operator.rust @@ -590,6 +589,7 @@ contexts: - include: pattern-param - include: dyn-types - include: lifetime + - include: impl-trait - match: (?={{identifier}}::) push: type-path - match: (?=::) @@ -640,6 +640,7 @@ contexts: scope: punctuation.accessor.rust set: [type-path-second, path-after-accessor] - include: type-names + - include: generic-identifier-names - include: else-pop type-path-second: @@ -710,15 +711,6 @@ contexts: - match: '\b(?:r#)?_*{{type_identifier}}' scope: storage.type.rust - impl-types: - - match: '\bimpl\b' - scope: storage.type.impl.rust - push: - - include: comments - - include: impl-generic - - match: '(?=\S)' - pop: true - dyn-types: - match: '\bdyn\b(?=\s*(?:\(|{{lifetime}}|{{identifier}}))' scope: storage.type.trait.rust @@ -803,6 +795,40 @@ contexts: - match: '[-+%/*]' scope: keyword.operator.arithmetic.rust + impl-trait: + - match: '\bimpl\b' + scope: storage.type.impl.rust + push: impl-trait-types + + impl-trait-types: + - match: '\buse\b' + scope: keyword.other.rust + push: impl-trait-use + - include: types + - match: '(?=\S)' + pop: true + + impl-trait-use: + - match: '<' + scope: punctuation.definition.generic.begin.rust + set: impl-trait-use-generic-body + - match: '(?=\S)' + pop: true + + impl-trait-use-generic-body: + - meta_scope: meta.generic.rust + - match: '>' + scope: punctuation.definition.generic.end.rust + pop: true + - include: lifetime + - match: ',' + scope: punctuation.separator.rust + - match: '\bSelf\b' + scope: keyword.other.rust + - include: all-generic-type-names + - match: '(?=\S)' + pop: true + ##[ STRUCTS ]############################################################### struct-identifier: diff --git a/Rust/tests/syntax_test_generics.rs b/Rust/tests/syntax_test_generics.rs index 56892b72e6..5a304abc3a 100644 --- a/Rust/tests/syntax_test_generics.rs +++ b/Rust/tests/syntax_test_generics.rs @@ -442,8 +442,115 @@ fn function() { // ^^^ storage.type.numeric let b: Byte; // ^^^^^^ meta.function meta.block meta.generic -// ^^^^ string.quoted.single.rust +// ^^^^ string.quoted.single // ^ storage.type.string // ^ punctuation.definition.string.begin // ^ punctuation.definition.string.end } + +fn impl_trait_return_use_bound<'a>() -> impl for<'b> Trait1 + use<'a>> {} +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function meta.function.return-type +// ^^ punctuation.separator +// ^^^^ storage.type.impl +// ^^^ keyword.other +// ^ meta.generic punctuation.definition.generic.begin +// ^ meta.generic punctuation.definition.generic.end +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.generic +// ^ meta.generic punctuation.definition.generic.begin +// ^ meta.generic keyword.operator +// ^^^^ meta.generic storage.type.impl +// ^^^^ meta.generic meta.generic +// ^ punctuation.definition.generic.begin +// ^^ storage.modifier.lifetime +// ^ punctuation.definition.generic.end +// ^ keyword.operator +// ^^^ keyword.other +// ^^^^ meta.generic +// ^ punctuation.definition.generic.begin +// ^^ storage.modifier.lifetime +// ^ punctuation.definition.generic.end +// ^ punctuation.definition.generic.end + +fn impl_trait_use<'a, foo>() -> impl Trait1 + use<'a, Self, foo> {} +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function meta.function.return-type +// ^ keyword.operator +// ^^^ keyword.other +// ^ punctuation.definition.generic.begin +// ^^ storage.modifier.lifetime +// ^ punctuation.separator +// ^^^^ keyword.other +// ^ punctuation.separator +// ^^^ storage.type.rust +// ^ punctuation.definition.generic.end + +fn impl_trait_return1<'a, 'b>() -> impl Trait<&'a u8, Ty = impl Sized + 'b> {} +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function meta.function.return-type +// ^^ punctuation.separator +// ^^^^ storage.type.impl +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.generic +// ^ punctuation.definition.generic.begin +// ^ keyword.operator +// ^^ storage.modifier.lifetime +// ^^ storage.type +// ^ punctuation.separator +// ^ keyword.operator +// ^^^^ storage.type.impl +// ^^^^^ support.type +// ^ keyword.operator +// ^^ storage.modifier.lifetime +// ^ punctuation.definition.generic.end +fn impl_trait_return2() -> impl Debug + 'a {} +// ^^^^^^^^^^^^^^^^^^ meta.function meta.function.return-type +// ^^^^ storage.type.impl +// ^^^^^ storage.type.rust +// ^ keyword.operator +// ^^ storage.modifier.lifetime + +fn impl_trait_param(x: impl FnOnce(&[u8]) -> &[u8]) {} +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function meta.function.parameters +// ^^^^ storage.type.impl +// ^^^^^^ support.type +// ^ meta.group punctuation.section.group.begin +// ^ meta.group keyword.operator +// ^ meta.group punctuation.section.group.begin +// ^^ meta.group storage.type +// ^^ meta.group punctuation.section.group.end +// ^^^^^^^^ meta.function meta.function.parameters meta.function.return-type +// ^^ punctuation.separator +// ^ meta.function.parameters keyword.operator +// ^ meta.function.parameters punctuation.section.group.begin +// ^^ meta.function.parameters storage.type +// ^ meta.function.parameters punctuation.section.group.end + + +fn impl_trait_with_plus() -> impl Iterator> + Captures<'a> + Captures<'s> {} +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function meta.function.return-type +// ^^^^ storage.type.impl +// ^^^^^^^^ support.type +// ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.generic - meta.generic meta.generic +// ^^^^ storage.type.rust +// ^ keyword.operator +// ^^^ variable.other.rust +// ^^ punctuation.accessor.rust +// ^^^^^^^^^^^^ storage.type.rust +// ^^^^^^ meta.generic meta.generic +// ^^^^ storage.modifier.lifetime +// ^ meta.generic - meta.generic meta.generic +// ^ keyword.operator +// ^^^^^^^^ storage.type.rust +// ^^^^ meta.generic +// ^^ storage.modifier.lifetime +// ^ keyword.operator +// ^^^^^^^^ storage.type.rust +// ^^^^ meta.generic +// ^^ storage.modifier.lifetime + +fn impl_trait() -> impl Type use < {} +//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.rust +// ^^^^^^^^^^^^^^^^^^^ meta.function.return-type.rust +// ^^^^ storage.type.impl.rust +// ^^^^ storage.type.rust +// ^^^ keyword.other.rust +// ^^ meta.generic.rust +// ^ punctuation.definition.generic.begin.rust +// ^^ meta.block.rust