Skip to content

Commit 554a850

Browse files
committed
Syntax: Support dyn traits.
cc rust-lang#284
1 parent 7943659 commit 554a850

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

RustEnhanced.sublime-syntax

+2
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,8 @@ contexts:
411411
push: generic-angles
412412
- match: \b(Self|{{int_suffixes}}|{{float_suffixes}}|bool|char|str)\b
413413
scope: storage.type.rust
414+
- match: '\bdyn\b(?!\s*::)(?=\s*(?:\(|''?{{identifier}}))'
415+
scope: storage.type.trait.rust
414416

415417
generic-angles:
416418
- meta_scope: meta.generic.rust

syntax_test_rust.rs

+45-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extern extern crate simd_rng_derive;*/
3232
// This one is just to visually confirm the testing comments don't intefere
3333
#[macro_use]
3434
extern crate std_web;
35-
/*#[macro_use]
35+
/*#[macro_use]
3636
extern extern crate simd_rng_derive;*/
3737

3838
let c = 'c';
@@ -1221,3 +1221,47 @@ pub union Foo<'a, Y: Baz>
12211221
// that we don't accidentally interpret it as a keyword.
12221222
fn union() {}
12231223
// ^^^^^ meta.function entity.name.function
1224+
1225+
// dyn trait
1226+
fn f(x: dyn T, y: Box<dyn T + 'static>, z: &dyn T,
1227+
// ^^^ meta.function.parameters storage.type.trait
1228+
// ^^^ meta.function.parameters meta.generic storage.type.trait
1229+
// ^^^ meta.function.parameters storage.type.trait
1230+
f: &dyn Fn(CrateNum) -> bool) -> dyn T {
1231+
// ^^^ meta.function.parameters storage.type.trait
1232+
// ^^^ meta.function.return-type storage.type.trait
1233+
let x: &(dyn 'static + Display) = &BYTE;
1234+
// ^^^ meta.group storage.type.trait
1235+
let y: Box<dyn Display + 'static> = Box::new(BYTE);
1236+
// ^^^ meta.generic storage.type.trait
1237+
let _: &dyn (Display) = &BYTE;
1238+
// ^^^ storage.type.trait
1239+
let _: &dyn (::std::fmt::Display) = &BYTE;
1240+
// ^^^ storage.type.trait
1241+
const DT: &'static dyn C = &V;
1242+
// ^^^ storage.type.trait
1243+
struct S {
1244+
f: dyn T
1245+
// ^^^ meta.struct storage.type.trait
1246+
}
1247+
type D4 = dyn (::module::Trait);
1248+
// ^^^ storage.type.trait
1249+
}
1250+
1251+
// dyn is not a keyword in all situations (a "weak" keyword).
1252+
type A0 = dyn;
1253+
// ^^^ -storage.type.trait
1254+
type A1 = dyn::dyn;
1255+
// ^^^^^ meta.path -storage.type.trait
1256+
// ^^^ -storage.type.trait
1257+
type A2 = dyn<dyn, dyn>;
1258+
// ^^^ meta.generic -storage.type.trait
1259+
// ^^^ meta.generic -storage.type.trait
1260+
// ^^^ meta.generic -storage.type.trait
1261+
// This is incorrect. `identifier` should not match on the keyword `as`.
1262+
// However, avoiding keywords is a little complicated and slow.
1263+
type A3 = dyn<<dyn as dyn>::dyn>;
1264+
// ^^^ meta.generic -storage.type.trait
1265+
// ^^^ meta.generic storage.type.trait
1266+
// ^^^ meta.generic -storage.type.trait
1267+
// ^^^ meta.generic -storage.type.trait

0 commit comments

Comments
 (0)