From 3663f1ee11db74e994b604dcb20195473c6d3fb5 Mon Sep 17 00:00:00 2001 From: ehuss Date: Mon, 30 Jul 2018 10:16:56 -0700 Subject: [PATCH] Syntax: Support `dyn` traits. (#308) cc #284 --- RustEnhanced.sublime-syntax | 2 ++ syntax_test_rust.rs | 44 +++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/RustEnhanced.sublime-syntax b/RustEnhanced.sublime-syntax index 6387665d..0f33dd5b 100644 --- a/RustEnhanced.sublime-syntax +++ b/RustEnhanced.sublime-syntax @@ -437,6 +437,8 @@ contexts: __m(?:64|128|256)[di]? # __m512 should come later )\b scope: storage.type.rust + - match: '\bdyn\b(?!\s*::)(?=\s*(?:\(|''?{{identifier}}))' + scope: storage.type.trait.rust generic-angles: - meta_scope: meta.generic.rust diff --git a/syntax_test_rust.rs b/syntax_test_rust.rs index 4c05303a..2b065b1b 100644 --- a/syntax_test_rust.rs +++ b/syntax_test_rust.rs @@ -1514,3 +1514,47 @@ fn f>(lhs: L) {} // ^ punctuation.definition.generic.begin // ^ punctuation.definition.generic.end // ^ meta.function meta.function.parameters punctuation.definition.parameters.begin + +// dyn trait +fn f(x: dyn T, y: Box, z: &dyn T, +// ^^^ meta.function.parameters storage.type.trait +// ^^^ meta.function.parameters meta.generic storage.type.trait +// ^^^ meta.function.parameters storage.type.trait + f: &dyn Fn(CrateNum) -> bool) -> dyn T { +// ^^^ meta.function.parameters storage.type.trait +// ^^^ meta.function.return-type storage.type.trait + let x: &(dyn 'static + Display) = &BYTE; +// ^^^ meta.group storage.type.trait + let y: Box = Box::new(BYTE); +// ^^^ meta.generic storage.type.trait + let _: &dyn (Display) = &BYTE; +// ^^^ storage.type.trait + let _: &dyn (::std::fmt::Display) = &BYTE; +// ^^^ storage.type.trait + const DT: &'static dyn C = &V; +// ^^^ storage.type.trait + struct S { + f: dyn T +// ^^^ meta.struct storage.type.trait + } + type D4 = dyn (::module::Trait); +// ^^^ storage.type.trait +} + +// dyn is not a keyword in all situations (a "weak" keyword). +type A0 = dyn; +// ^^^ -storage.type.trait +type A1 = dyn::dyn; +// ^^^^^ meta.path -storage.type.trait +// ^^^ -storage.type.trait +type A2 = dyn; +// ^^^ meta.generic -storage.type.trait +// ^^^ meta.generic -storage.type.trait +// ^^^ meta.generic -storage.type.trait +// This is incorrect. `identifier` should not match on the keyword `as`. +// However, avoiding keywords is a little complicated and slow. +type A3 = dyn<::dyn>; +// ^^^ meta.generic -storage.type.trait +// ^^^ meta.generic storage.type.trait +// ^^^ meta.generic -storage.type.trait +// ^^^ meta.generic -storage.type.trait