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] Sync with Rust Enhanced #2305

Merged
merged 6 commits into from
Jan 8, 2022
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
1,229 changes: 809 additions & 420 deletions Rust/Rust.sublime-syntax

Large diffs are not rendered by default.

1,151 changes: 0 additions & 1,151 deletions Rust/syntax_test_rust.rs

This file was deleted.

142 changes: 142 additions & 0 deletions Rust/tests/syntax_test_attributes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// SYNTAX TEST "Packages/Rust/Rust.sublime-syntax"

#![warn(unused)]
// <- meta.annotation punctuation.definition.annotation
//^^^^^^^^^^^^^^ meta.annotation
//^ punctuation.section.group.begin
// ^^^^ variable.annotation
// ^^^^^^^^ meta.annotation.parameters meta.group
// ^ punctuation.section.group.begin
// ^ punctuation.section.group.end
// ^ punctuation.section.group.end

# [ macro_use ]
//^^^^^^^^^^^^^^^ meta.annotation
//^ punctuation.definition.annotation
// ^ punctuation.section.group.begin
// ^^^^^^^^^ variable.annotation
// ^ punctuation.section.group.end

#[cfg(all(unix, not(target_os = "haiku")))]
// <- meta.annotation punctuation.definition.annotation
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.annotation
//^^^ variable.annotation
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.annotation.parameters meta.group
// ^ punctuation.section.group.begin
// ^^^ meta.function-call variable.function
// ^ meta.annotation.parameters meta.group meta.function-call meta.group punctuation.section.group.begin
// ^ punctuation.separator
// ^^^ meta.function-call meta.function-call variable.function
// ^ punctuation.section.group.begin
// ^ keyword.operator.assignment
// ^^^^^^^ string.quoted.double
// ^ punctuation.section.group.end
// ^ punctuation.section.group.end
// ^ punctuation.section.group.end
// ^ punctuation.section.group.end

// Test highlighting/scope with struct field attributes
// https://github.com/rust-lang/sublime-rust/issues/120
pub struct Claim {
// ^^^^^^^^ meta.struct
pub claim_id: String,
// ^^^ storage.modifier
pub patient_id: String,
#[serde(skip_serializing_if="Option::is_none")]
// ^^^^^^^^^^^^^^^ string.quoted.double
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.annotation
pub referring: Option<String>,
#[serde(skip_serializing_if="Option::is_none")]
// ^^^^^ variable.annotation
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.annotation
pub drug: Option<Vec<String>>,
#[serde(skip_serializing_if="Option::is_none")]
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.annotation
pub ndc: Option<Vec<String>>,
#[serde(skip_serializing_if="Option::is_none")]
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.annotation
pub rendering: Option<String>,
pub date: String,
}

enum E {
#[allow(dead_code)]
// ^^^^^^^^^^^^^^^^^^^ meta.enum meta.annotation
// ^^^^^ variable.annotation
A(i32),
// ^^^ meta.enum meta.struct meta.group storage.type
}

// Generic parameters.
unsafe impl<#[may_dangle] T: ?Sized> Drop for Box<T> { }
// ^^^^^^^^^^^^^ meta.annotation
// ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.impl meta.generic

#[test = "foo ] bar"]
//^^^^^^^^^^^^^^^^^^^^^ meta.annotation
//^ punctuation.definition.annotation
// ^ punctuation.section.group.begin
// ^^^^ variable.annotation
// ^ keyword.operator.assignment
// ^^^^^^^^^^^ string.quoted.double
// ^ punctuation.section.group.end

// All the things.
# ! [
//^^^^^^ meta.annotation
//^ punctuation.definition.annotation
// ^ punctuation.definition.annotation
// ^ punctuation.section.group.begin
// comment
// ^^^^^^^^^^^ comment.line.double-slash
attr_name (
// ^^^^^^^^^ variable.annotation
// ^ meta.annotation.parameters meta.group punctuation.section.group.begin
// comment
// ^^^^^^^^^^^ comment.line.double-slash
"string",
// ^^^^^^^^ string.quoted.double
// ^ punctuation.separator
r##"raw"##,
// ^^^^^^^^^^ string.quoted.double.raw
b"bytes",
// ^ storage.type.string
// ^^^^^^^^ string.quoted.double
br"raw byte",
// ^^^^^^^^^^^^ string.quoted.double.raw
'c',
// ^^^ string.quoted.single
b'c',
// ^^^^ string.quoted.single
1_000,
// ^^^^^ constant.numeric.integer.decimal
1.618,
// ^^^^^ constant.numeric.float
true,
// ^^^^ constant.language
struct,
// ^^^^^^ storage.type.struct
1 + 1,
// ^ constant.numeric.integer.decimal
// ^ keyword.operator.arithmetic
// ^ constant.numeric.integer.decimal
)
// ^ punctuation.section.group.end
]
//^ punctuation.section.group.end

// quote! uses #var syntax
#[doc=#foo]
//^^^^^^^^^ meta.annotation
// ^ keyword.operator.assignment

// Macros often use replacement.
#[doc = $doc]
//^^^^^^^^^^^ meta.annotation
// ^ punctuation.section.group.end
// ^ keyword.operator.assignment

#[rustfmt::skip]
//^^^^^^^^^^^^^^ meta.annotation
//^^^^^^^^^^^^^ meta.path
// ^^^^ variable.annotation
199 changes: 199 additions & 0 deletions Rust/tests/syntax_test_closures.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
// SYNTAX TEST "Packages/Rust/Rust.sublime-syntax"

let inferred_closure = |i, j: u32| i + 1;
// ^^^^^^^^^^^^^^^^ entity.name.function
// ^^^^^^^^^^^^^^^^^ meta.function.closure
// ^^^^^^^^^^^ meta.function.parameters
// ^ punctuation.section.parameters.begin
// ^ variable.parameter
// ^ punctuation.separator
// ^ variable.parameter
// ^ punctuation.separator
// ^^^ storage.type
// ^ punctuation.section.parameters.end
let closure = || -> i32 { | | 1 + 2 };
// ^^^^^^^ entity.name.function
// ^^^^^^^^^^^^^^^^^^^^^^^ meta.function.closure
// ^^ meta.function.parameters
// ^ punctuation.section.parameters.begin
// ^ punctuation.section.parameters.end
// ^^^ storage.type
// ^^^^^^^^^^^^^ meta.block
// ^ meta.block punctuation.section.block.begin
// ^ constant.numeric.integer.decimal
// ^ constant.numeric.integer.decimal
// ^ meta.block punctuation.section.block.end

// Make sure "or" is not confused with closure.
let c = a | b;
// ^ keyword.operator.bitwise

call_func(|c| 1 + 2 + c);
// ^^^^^^^^^^^^^ meta.function.closure
// ^^^ meta.function.parameters

fn lambdas() {
let c = |foo,
// ^ meta.function.closure meta.function.parameters punctuation.section.parameters.begin
// ^^^ meta.function.parameters variable.parameter
bar| {};
// ^^^ meta.function.parameters variable.parameter
// ^ meta.function.closure meta.function.parameters punctuation.section.parameters.end
let c = |foo, // weird, but should work
// ^ meta.function.closure meta.function.parameters punctuation.section.parameters.begin
// ^^^ meta.function.parameters variable.parameter
// ^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line
bar| {};
// ^^^ meta.function.parameters variable.parameter
// ^ meta.function.closure meta.function.parameters punctuation.section.parameters.end
}


let x = |self, _, _foo, foo: 'static str| {};
// ^^^^^^^^^^^^^^^^^^^^ meta.function.closure meta.function.parameters
// ^^^^ variable.parameter
// ^^^^ variable.parameter
// ^^^ variable.parameter
// ^ punctuation.separator
// ^^^^^^^ storage.modifier.lifetime
// ^^^ storage.type
let x = |&a, &mut b, ref c, mut d, ref mut e| {};
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.closure meta.function.parameters
// ^ keyword.operator
// ^ variable.parameter
// ^ keyword.operator
// ^^^ storage.modifier
// ^ variable.parameter
// ^^^ storage.modifier
// ^ variable.parameter
// ^^^ storage.modifier
// ^ variable.parameter
// ^^^ storage.modifier
// ^^^ storage.modifier
// ^ variable.parameter
let x = |foo @ Some{}| {};
// ^^^^^^^^^^^^^^ meta.function.closure meta.function.parameters
// ^^^ variable.parameter
// ^ keyword.operator
// ^ meta.block punctuation.section.block.begin
// ^ meta.block punctuation.section.block.end
let x = |path :: to :: Struct{a, b, ..},
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.closure meta.function.parameters
// ^^^^^^^^^^ meta.block
// ^ punctuation.section.block.begin
// ^ variable.parameter
// ^ variable.parameter
// ^^ keyword.operator
// ^ punctuation.section.block.end
self::Struct{c}, super::Struct{d}| {};
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.closure meta.function.parameters
// ^^^^ keyword.other
// ^^^ meta.block
// ^ variable.parameter
// ^^^^^ keyword.other
// ^^^ meta.block
// ^ variable.parameter
let x = |Struct{ref mut a}| {};
// ^^^^^^^^^^^^^^^^^^^ meta.function.closure meta.function.parameters
// ^^^^^^^^^^^ meta.block
// ^^^ storage.modifier
// ^^^ storage.modifier
// ^ variable.parameter
let x = |Struct{0: (x, y), 1: z}| {};
// ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.closure meta.function.parameters
// ^^^^^^^^^^^^^^^^^ meta.block
// ^ constant.numeric.integer.decimal
// ^ punctuation.separator
// ^^^^^^ meta.group
// ^ punctuation.section.group.begin
// ^ variable.parameter
// ^ variable.parameter
// ^ punctuation.section.group.end
// ^ constant.numeric.integer.decimal
// ^ punctuation.separator
// ^ variable.parameter
let x = |Struct{field: (x, y), field2: z}| {};
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.closure meta.function.parameters
// ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block
// ^^^^^^ meta.group
// ^ variable.parameter
// ^ variable.parameter
// ^ variable.parameter
let x = |path::to::TupleStruct(x, (y, z), ..)| {};
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.closure meta.function.parameters
// ^^^^^^^^^^^^^^^ meta.group
// ^ variable.parameter
// ^^^^^^ meta.group meta.group
// ^ variable.parameter
// ^ variable.parameter
// ^^ keyword.operator
let x = |(x, (y, z)), (Foo{&mut i, ..}, foo @ Some{})| {};
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.closure meta.function.parameters
// ^^^^^^^^^^^ meta.group
// ^ variable.parameter
// ^^^^^^ meta.group meta.group
// ^ variable.parameter
// ^ meta.group variable.parameter
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group
// ^^^^^^^^^^^^ meta.block
// ^ keyword.operator
// ^^^ storage.modifier
// ^ variable.parameter
// ^^ keyword.operator
// ^^^ variable.parameter
// ^ keyword.operator
let x = |[ref mut a, (x, y)]| {};
// ^^^^^^^^^^^^^^^^^^^^^ meta.function.closure meta.function.parameters
// ^^^^^^^^^^^^^^^^^^^ meta.brackets
// ^ punctuation.section.brackets.begin
// ^^^ storage.modifier
// ^^^ storage.modifier
// ^ variable.parameter
// ^^^^^^ meta.group
// ^ variable.parameter
// ^ variable.parameter
let x = |a: i32, b: Foo, c: Option<i32>, d: extern "C" fn (), e: *const u8| {};
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.closure meta.function.parameters
// ^ variable.parameter
// ^^^ storage.type
// ^ variable.parameter
// ^ variable.parameter
// ^^^^^^ meta.generic support.type
// ^^^ meta.generic storage.type
// ^ variable.parameter
// ^^^^^^ keyword.other
// ^^^ string.quoted.double
// ^^ storage.type.function
// ^^ meta.group
// ^ variable.parameter
// ^^^^^^ storage.modifier
// ^^ storage.type
let x = |/*comment*/(/*c*/a, [b/*c*/], S{/*c*/f: c})| {};
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.closure meta.function.parameters
// ^^^^^^^^^^^ comment.block
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group
// ^^^^^ comment.block
// ^ variable.parameter
// ^^^^^^^^ meta.brackets
// ^ variable.parameter
// ^^^^^ comment.block
// ^^^^^^^^^^^ meta.block
// ^^^^^ comment.block
// ^ variable.parameter

let f = |(x, y): (u32, &mut u32)| { x + y };
// ^ punctuation.section.parameters.begin
// ^^^^^^ meta.group
// ^ variable.parameter
// ^ punctuation.separator
// ^ variable.parameter
// ^ punctuation.section.group.end
// ^ punctuation.separator
// ^ punctuation.section.group.begin
// ^^^ storage.type
// ^ punctuation.separator
// ^ keyword.operator
// ^^^ storage.modifier
// ^^^ storage.type
// ^ punctuation.section.group.end
// ^ punctuation.section.parameters.end
37 changes: 37 additions & 0 deletions Rust/tests/syntax_test_comments.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SYNTAX TEST "Packages/Rust/Rust.sublime-syntax"

// Line comments
// <- comment.line.double-slash punctuation.definition.comment
// ^^^^^^^^^^^^^^ comment.line.double-slash

// <- -comment

/// Line doc comments
// <- comment.line.documentation
// ^^^^^^^^^^^^^ comment.line.documentation

/*!
// <- comment.block.documentation punctuation.definition.comment
// <- comment.block.documentation
//^ comment.block.documentation
Block doc comments
// ^^^^^^^^^^^^^^^^ comment.block.documentation
/* Nested comments */
// ^^^^^^^^^^^^^^^^^^ comment.block.documentation comment.block
*/

/**
*
// ^ comment.block.documentation punctuation.definition.comment
*/

// Verify comment is cleared.
mod a {}
// ^^^^^ -comment

fn foo<F: FnMut(i32, i32 /*asd*/) -> i32>(f: F) {
// ^^^^^^^ meta.generic comment
let lam = |time: i32 /* comment */, other: i32| {
// ^^^^^^^^^^^^^ meta.function.parameters comment
};
}
Loading