Skip to content

Commit 41e189a

Browse files
ehussJayflux
authored andcommitted
Add fmt-style formatting for additional macros in the standard library. (#181)
Adds panic!, format_args!, and unreachable! to the list of fmt-taking macros. Fixes #178
1 parent 75b02cf commit 41e189a

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

RustEnhanced.sublime-syntax

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ contexts:
156156
- match: '\b[[:lower:]_][[:lower:][:digit:]_]*(?=\()'
157157
scope: support.function.rust
158158

159-
- match: '\b((?:format|print|println)!)\s*(\()'
159+
- match: '\b((?:format|print|println|panic|format_args|unreachable)!)\s*(\()'
160160
captures:
161161
1: support.macro.rust
162162
2: meta.group.rust punctuation.definition.group.begin.rust
@@ -234,7 +234,7 @@ contexts:
234234
- match: '#!?\['
235235
push:
236236
# https://github.com/sublimehq/Packages/issues/709#issuecomment-266835130
237-
- meta_scope: meta.annotation.rust
237+
- meta_scope: meta.annotation.rust
238238
- include: statements
239239
- match: '\]'
240240
pop: true

syntax_test_rust.rs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,10 @@ struct PrintableStruct(Box<i32>);
215215
// fixes https://github.com/rust-lang/sublime-rust/issues/144
216216
fn factory() -> Box<Fn(i32) -> i32> {
217217
// <- storage.type.function
218-
// ^^^^^^^ entity.name.function
218+
// ^^^^^^^ entity.name.function
219219
// ^^^^^^^^^^^^^^ meta.generic
220-
// ^^ storage.type
221-
// ^^ storage.type
220+
// ^^ storage.type
221+
// ^^ storage.type
222222
// ^^ punctuation.separator.generic
223223

224224
Box::new(|x| x + 1)
@@ -924,7 +924,7 @@ pub fn next_lex2</* block */T/* comments */:/* everywhere */
924924
/* help */ PartialOrd // Possibly too many comments
925925
// ^^^^^^^^^^ comment.block.rust
926926
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.double-slash.rust
927-
> (
927+
> (
928928
/* block2 */ data2: &mut [T] // line
929929
// ^^^^^^^^^^^^ source.rust meta.function.rust meta.function.parameters.rust comment.block.rust
930930
// ^^^^^^^ source.rust meta.function.rust meta.function.parameters.rust comment.line.double-slash.rust
@@ -989,3 +989,33 @@ impl<T> Iterator for Fibonacci<T>
989989
pub const FOO: Option<[i32; 1]> = Some([1]);
990990
// ^ punctuation.definition.group.begin.rust
991991
// ^ punctuation.definition.group.end.rust
992+
993+
pub fn macro_tests() {
994+
println!();
995+
// ^^^^^^^^ support.macro.rust
996+
println!("Example");
997+
// ^^^^^^^^ support.macro.rust
998+
// ^ punctuation.definition.group.begin
999+
// ^^^^^^^^^ string.quoted.double.rust
1000+
// ^ punctuation.definition.group.end
1001+
println!("Example {} {message}", "test", message="hi");
1002+
// ^^ constant.other.placeholder.rust
1003+
// ^^^^^^^^^ constant.other.placeholder.rust
1004+
panic!();
1005+
// ^^^^^^ support.macro.rust
1006+
panic!("Example");
1007+
// ^^^^^^ support.macro.rust
1008+
// ^ punctuation.definition.group.begin
1009+
// ^^^^^^^^^ string.quoted.double.rust
1010+
// ^ punctuation.definition.group.end
1011+
panic!("Example {} {message}", "test", message="hi");
1012+
// ^^ constant.other.placeholder.rust
1013+
// ^^^^^^^^^ constant.other.placeholder.rust
1014+
format_args!("invalid type: {}, expected {}", unexp, exp);
1015+
// ^^^^^^^^^^^^ support.macro.rust
1016+
// ^^ constant.other.placeholder.rust
1017+
// ^^ constant.other.placeholder.rust
1018+
unreachable!("{:?}", e);
1019+
// ^^^^^^^^^^^^ support.macro.rust
1020+
// ^^^^ constant.other.placeholder.rust
1021+
}

0 commit comments

Comments
 (0)