diff --git a/RustEnhanced.sublime-syntax b/RustEnhanced.sublime-syntax index adc156c8..dff18686 100644 --- a/RustEnhanced.sublime-syntax +++ b/RustEnhanced.sublime-syntax @@ -411,6 +411,8 @@ contexts: push: generic-angles - match: \b(Self|{{int_suffixes}}|{{float_suffixes}}|bool|char|str)\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 4426760b..86db7b07 100644 --- a/syntax_test_rust.rs +++ b/syntax_test_rust.rs @@ -32,7 +32,7 @@ extern extern crate simd_rng_derive;*/ // This one is just to visually confirm the testing comments don't intefere #[macro_use] extern crate std_web; -/*#[macro_use] +/*#[macro_use] extern extern crate simd_rng_derive;*/ let c = 'c'; @@ -1221,3 +1221,47 @@ pub union Foo<'a, Y: Baz> // that we don't accidentally interpret it as a keyword. fn union() {} // ^^^^^ meta.function entity.name.function + +// 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