Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Rust] scope support types in generics #1820

Merged
merged 1 commit into from
Jan 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Rust/Rust.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: '\+'
Expand Down
5 changes: 5 additions & 0 deletions Rust/syntax_test_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ struct PrintableStruct(Box<i32>);
//^^^^ storage.type.struct
// ^^^^^^^^^^^^^^^ entity.name.struct
// ^ punctuation.section.group.begin
// ^^^ support.type
// ^^^^^^^^ meta.generic
// ^ punctuation.definition.generic.begin
// ^^^ storage.type
Expand Down Expand Up @@ -808,6 +809,7 @@ pub trait Animal {

fn collect_vec() {
let _: Vec<(usize, usize)> = (0..10).enumerate().collect::<Vec<_>>();
// ^^^ support.type
// ^^^^^^^^^^^^^^^^^^^ meta.generic
// ^ punctuation.section.group.begin
// ^^^^^ storage.type
Expand All @@ -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!();
Expand All @@ -833,6 +836,8 @@ fn collect_vec() {
// ^^^^ support.macro
let _: Vec<(usize, usize)> = vec![];
// ^^^^ support.macro
let _: Vec<String> = vec![];
// ^^^^^^ meta.generic support.type
}

macro_rules! forward_ref_binop [
Expand Down