Skip to content

Commit

Permalink
Syntax: Support dyn traits. (rust-lang#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss authored Jul 30, 2018
1 parent fac7faa commit 3663f1e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions RustEnhanced.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions syntax_test_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1514,3 +1514,47 @@ fn f<L: IntoIterator<Item=(&'a i32, &'a i32)>>(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<dyn T + 'static>, 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<dyn Display + 'static> = 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<dyn, 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 as dyn>::dyn>;
// ^^^ meta.generic -storage.type.trait
// ^^^ meta.generic storage.type.trait
// ^^^ meta.generic -storage.type.trait
// ^^^ meta.generic -storage.type.trait

0 comments on commit 3663f1e

Please sign in to comment.