From 2c2772bc8dd537ee071cc8e2777e4e9b974ef639 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Mon, 7 Jan 2019 19:36:16 +0200 Subject: [PATCH] [Rust] scope support types in generics (#1820) --- Rust/Rust.sublime-syntax | 9 +++++++-- Rust/syntax_test_rust.rs | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Rust/Rust.sublime-syntax b/Rust/Rust.sublime-syntax index 368cd67f18..6c1c617110 100644 --- a/Rust/Rust.sublime-syntax +++ b/Rust/Rust.sublime-syntax @@ -10,6 +10,7 @@ variables: escaped_byte: '\\(x\h{2}|n|r|t|0|"|''|\\)' escaped_char: '\\(x\h{2}|n|r|t|0|"|''|\\|u\{\h{1,6}\})' int_suffixes: 'i8|i16|i32|i64|isize|u8|u16|u32|u64|usize' + support_type: \b(Copy|Send|Sized|Sync|Drop|Fn|FnMut|FnOnce|Box|ToOwned|Clone|PartialEq|PartialOrd|Eq|Ord|AsRef|AsMut|Into|From|Default|Iterator|Extend|IntoIterator|DoubleEndedIterator|ExactSizeIterator|Option|Some|None|Result|Ok|Err|SliceConcatExt|String|ToString|Vec)\b contexts: main: - include: statements @@ -188,7 +189,7 @@ contexts: - match: '\b[[:lower:]_][[:lower:][:digit:]_]*!(?=\s*(\(|\{|\[))' scope: support.macro.rust - - match: \b(Copy|Send|Sized|Sync|Drop|Fn|FnMut|FnOnce|Box|ToOwned|Clone|PartialEq|PartialOrd|Eq|Ord|AsRef|AsMut|Into|From|Default|Iterator|Extend|IntoIterator|DoubleEndedIterator|ExactSizeIterator|Option|Some|None|Result|Ok|Err|SliceConcatExt|String|ToString|Vec)\b + - match: '{{support_type}}' scope: support.type.rust - include: basic-identifiers @@ -427,7 +428,9 @@ contexts: - include: block type: - - match: '{{identifier}}(?=<)' + - match: (?:{{support_type}}|{{identifier}})(?=<) + captures: + 1: support.type.rust push: generic-angles - match: \b(Self|i8|i16|i32|i64|isize|u8|u16|u32|u64|usize|f32|f64|bool|char|str)\b scope: storage.type.rust @@ -484,6 +487,8 @@ contexts: pop: true - include: generic-angles-contents - include: type-any-identifier + - match: '{{support_type}}' + scope: support.type.rust - match: ':' scope: punctuation.separator.rust - match: '\+' diff --git a/Rust/syntax_test_rust.rs b/Rust/syntax_test_rust.rs index 76fdb23f84..3ee4f38bf4 100644 --- a/Rust/syntax_test_rust.rs +++ b/Rust/syntax_test_rust.rs @@ -214,6 +214,7 @@ struct PrintableStruct(Box); //^^^^ storage.type.struct // ^^^^^^^^^^^^^^^ entity.name.struct // ^ punctuation.section.group.begin +// ^^^ support.type // ^^^^^^^^ meta.generic // ^ punctuation.definition.generic.begin // ^^^ storage.type @@ -808,6 +809,7 @@ pub trait Animal { fn collect_vec() { let _: Vec<(usize, usize)> = (0..10).enumerate().collect::>(); +// ^^^ support.type // ^^^^^^^^^^^^^^^^^^^ meta.generic // ^ punctuation.section.group.begin // ^^^^^ storage.type @@ -825,6 +827,7 @@ fn collect_vec() { // ^ punctuation.accessor.dot // ^^ punctuation.accessor // ^^^^^^^^ meta.generic +// ^^^ support.type // ^^^^^^ meta.generic meta.generic // ^ keyword.operator let _: Vec<(usize, usize)> = vec!(); @@ -833,6 +836,8 @@ fn collect_vec() { // ^^^^ support.macro let _: Vec<(usize, usize)> = vec![]; // ^^^^ support.macro + let _: Vec = vec![]; +// ^^^^^^ meta.generic support.type } macro_rules! forward_ref_binop [