Skip to content

Commit 5f95a84

Browse files
committed
Syntax: Support dyn traits.
cc rust-lang#284
1 parent f653ba3 commit 5f95a84

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

RustEnhanced.sublime-syntax

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,8 @@ contexts:
416416
push: generic-angles
417417
- match: \b(Self|{{int_suffixes}}|{{float_suffixes}}|bool|char|str)\b
418418
scope: storage.type.rust
419+
- match: '\bdyn\b(?!\s*::)(?=\s*(?:\(|''?{{identifier}}))'
420+
scope: storage.type.trait.rust
419421

420422
generic-angles:
421423
- meta_scope: meta.generic.rust

syntax_test_rust.rs

Lines changed: 45 additions & 1 deletion
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';
@@ -1352,3 +1352,47 @@ impl<A> Thing for &'a mut A {}
13521352
// ^^ meta.impl storage.modifier.lifetime
13531353
// ^^^ meta.impl storage.modifier
13541354
// ^ meta.impl entity.name.impl
1355+
1356+
// dyn trait
1357+
fn f(x: dyn T, y: Box<dyn T + 'static>, z: &dyn T,
1358+
// ^^^ meta.function.parameters storage.type.trait
1359+
// ^^^ meta.function.parameters meta.generic storage.type.trait
1360+
// ^^^ meta.function.parameters storage.type.trait
1361+
f: &dyn Fn(CrateNum) -> bool) -> dyn T {
1362+
// ^^^ meta.function.parameters storage.type.trait
1363+
// ^^^ meta.function.return-type storage.type.trait
1364+
let x: &(dyn 'static + Display) = &BYTE;
1365+
// ^^^ meta.group storage.type.trait
1366+
let y: Box<dyn Display + 'static> = Box::new(BYTE);
1367+
// ^^^ meta.generic storage.type.trait
1368+
let _: &dyn (Display) = &BYTE;
1369+
// ^^^ storage.type.trait
1370+
let _: &dyn (::std::fmt::Display) = &BYTE;
1371+
// ^^^ storage.type.trait
1372+
const DT: &'static dyn C = &V;
1373+
// ^^^ storage.type.trait
1374+
struct S {
1375+
f: dyn T
1376+
// ^^^ meta.struct storage.type.trait
1377+
}
1378+
type D4 = dyn (::module::Trait);
1379+
// ^^^ storage.type.trait
1380+
}
1381+
1382+
// dyn is not a keyword in all situations (a "weak" keyword).
1383+
type A0 = dyn;
1384+
// ^^^ -storage.type.trait
1385+
type A1 = dyn::dyn;
1386+
// ^^^^^ meta.path -storage.type.trait
1387+
// ^^^ -storage.type.trait
1388+
type A2 = dyn<dyn, dyn>;
1389+
// ^^^ meta.generic -storage.type.trait
1390+
// ^^^ meta.generic -storage.type.trait
1391+
// ^^^ meta.generic -storage.type.trait
1392+
// This is incorrect. `identifier` should not match on the keyword `as`.
1393+
// However, avoiding keywords is a little complicated and slow.
1394+
type A3 = dyn<<dyn as dyn>::dyn>;
1395+
// ^^^ meta.generic -storage.type.trait
1396+
// ^^^ meta.generic storage.type.trait
1397+
// ^^^ meta.generic -storage.type.trait
1398+
// ^^^ meta.generic -storage.type.trait

0 commit comments

Comments
 (0)