Skip to content

Commit 92ef16c

Browse files
committed
Syntax: Support dyn traits.
cc rust-lang#284
1 parent fac7faa commit 92ef16c

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
@@ -1514,3 +1514,47 @@ fn f<L: IntoIterator<Item=(&'a i32, &'a i32)>>(lhs: L) {}
15141514
// ^ punctuation.definition.generic.begin
15151515
// ^ punctuation.definition.generic.end
15161516
// ^ meta.function meta.function.parameters punctuation.definition.parameters.begin
1517+
1518+
// dyn trait
1519+
fn f(x: dyn T, y: Box<dyn T + 'static>, z: &dyn T,
1520+
// ^^^ meta.function.parameters storage.type.trait
1521+
// ^^^ meta.function.parameters meta.generic storage.type.trait
1522+
// ^^^ meta.function.parameters storage.type.trait
1523+
f: &dyn Fn(CrateNum) -> bool) -> dyn T {
1524+
// ^^^ meta.function.parameters storage.type.trait
1525+
// ^^^ meta.function.return-type storage.type.trait
1526+
let x: &(dyn 'static + Display) = &BYTE;
1527+
// ^^^ meta.group storage.type.trait
1528+
let y: Box<dyn Display + 'static> = Box::new(BYTE);
1529+
// ^^^ meta.generic storage.type.trait
1530+
let _: &dyn (Display) = &BYTE;
1531+
// ^^^ storage.type.trait
1532+
let _: &dyn (::std::fmt::Display) = &BYTE;
1533+
// ^^^ storage.type.trait
1534+
const DT: &'static dyn C = &V;
1535+
// ^^^ storage.type.trait
1536+
struct S {
1537+
f: dyn T
1538+
// ^^^ meta.struct storage.type.trait
1539+
}
1540+
type D4 = dyn (::module::Trait);
1541+
// ^^^ storage.type.trait
1542+
}
1543+
1544+
// dyn is not a keyword in all situations (a "weak" keyword).
1545+
type A0 = dyn;
1546+
// ^^^ -storage.type.trait
1547+
type A1 = dyn::dyn;
1548+
// ^^^^^ meta.path -storage.type.trait
1549+
// ^^^ -storage.type.trait
1550+
type A2 = dyn<dyn, dyn>;
1551+
// ^^^ meta.generic -storage.type.trait
1552+
// ^^^ meta.generic -storage.type.trait
1553+
// ^^^ meta.generic -storage.type.trait
1554+
// This is incorrect. `identifier` should not match on the keyword `as`.
1555+
// However, avoiding keywords is a little complicated and slow.
1556+
type A3 = dyn<<dyn as dyn>::dyn>;
1557+
// ^^^ meta.generic -storage.type.trait
1558+
// ^^^ meta.generic storage.type.trait
1559+
// ^^^ meta.generic -storage.type.trait
1560+
// ^^^ meta.generic -storage.type.trait

0 commit comments

Comments
 (0)