Skip to content

Commit b01b50b

Browse files
committed
Syntax: Support dyn traits.
cc rust-lang#284
1 parent f5d998b commit b01b50b

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

RustEnhanced.sublime-syntax

+2
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,8 @@ contexts:
437437
__m(?:64|128|256)[di]? # __m512 should come later
438438
)\b
439439
scope: storage.type.rust
440+
- match: '\bdyn\b(?!\s*::)(?=\s*(?:\(|''?{{identifier}}))'
441+
scope: storage.type.trait.rust
440442

441443
generic-angles:
442444
- meta_scope: meta.generic.rust

syntax_test_rust.rs

+44
Original file line numberDiff line numberDiff line change
@@ -1442,3 +1442,47 @@ struct S (
14421442
// ^ meta.struct punctuation.definition.group.end
14431443
// ^^^ meta.struct storage.type
14441444
);
1445+
1446+
// dyn trait
1447+
fn f(x: dyn T, y: Box<dyn T + 'static>, z: &dyn T,
1448+
// ^^^ meta.function.parameters storage.type.trait
1449+
// ^^^ meta.function.parameters meta.generic storage.type.trait
1450+
// ^^^ meta.function.parameters storage.type.trait
1451+
f: &dyn Fn(CrateNum) -> bool) -> dyn T {
1452+
// ^^^ meta.function.parameters storage.type.trait
1453+
// ^^^ meta.function.return-type storage.type.trait
1454+
let x: &(dyn 'static + Display) = &BYTE;
1455+
// ^^^ meta.group storage.type.trait
1456+
let y: Box<dyn Display + 'static> = Box::new(BYTE);
1457+
// ^^^ meta.generic storage.type.trait
1458+
let _: &dyn (Display) = &BYTE;
1459+
// ^^^ storage.type.trait
1460+
let _: &dyn (::std::fmt::Display) = &BYTE;
1461+
// ^^^ storage.type.trait
1462+
const DT: &'static dyn C = &V;
1463+
// ^^^ storage.type.trait
1464+
struct S {
1465+
f: dyn T
1466+
// ^^^ meta.struct storage.type.trait
1467+
}
1468+
type D4 = dyn (::module::Trait);
1469+
// ^^^ storage.type.trait
1470+
}
1471+
1472+
// dyn is not a keyword in all situations (a "weak" keyword).
1473+
type A0 = dyn;
1474+
// ^^^ -storage.type.trait
1475+
type A1 = dyn::dyn;
1476+
// ^^^^^ meta.path -storage.type.trait
1477+
// ^^^ -storage.type.trait
1478+
type A2 = dyn<dyn, dyn>;
1479+
// ^^^ meta.generic -storage.type.trait
1480+
// ^^^ meta.generic -storage.type.trait
1481+
// ^^^ meta.generic -storage.type.trait
1482+
// This is incorrect. `identifier` should not match on the keyword `as`.
1483+
// However, avoiding keywords is a little complicated and slow.
1484+
type A3 = dyn<<dyn as dyn>::dyn>;
1485+
// ^^^ meta.generic -storage.type.trait
1486+
// ^^^ meta.generic storage.type.trait
1487+
// ^^^ meta.generic -storage.type.trait
1488+
// ^^^ meta.generic -storage.type.trait

0 commit comments

Comments
 (0)