diff options
Diffstat (limited to 'crates/ra_tt')
-rw-r--r-- | crates/ra_tt/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_tt/src/lib.rs | 19 |
2 files changed, 6 insertions, 15 deletions
diff --git a/crates/ra_tt/Cargo.toml b/crates/ra_tt/Cargo.toml index f7230a9ca..3c45248c3 100644 --- a/crates/ra_tt/Cargo.toml +++ b/crates/ra_tt/Cargo.toml | |||
@@ -3,11 +3,13 @@ edition = "2018" | |||
3 | name = "ra_tt" | 3 | name = "ra_tt" |
4 | version = "0.1.0" | 4 | version = "0.1.0" |
5 | authors = ["rust-analyzer developers"] | 5 | authors = ["rust-analyzer developers"] |
6 | license = "MIT OR Apache-2.0" | ||
6 | 7 | ||
7 | [lib] | 8 | [lib] |
8 | doctest = false | 9 | doctest = false |
9 | 10 | ||
10 | [dependencies] | 11 | [dependencies] |
12 | stdx = { path = "../stdx" } | ||
11 | # ideally, `serde` should be enabled by `rust-analyzer`, but we enable it here | 13 | # ideally, `serde` should be enabled by `rust-analyzer`, but we enable it here |
12 | # to reduce number of compilations | 14 | # to reduce number of compilations |
13 | smol_str = { version = "0.1.15", features = ["serde"] } | 15 | smol_str = { version = "0.1.15", features = ["serde"] } |
diff --git a/crates/ra_tt/src/lib.rs b/crates/ra_tt/src/lib.rs index 342ddbe32..8faf1cc67 100644 --- a/crates/ra_tt/src/lib.rs +++ b/crates/ra_tt/src/lib.rs | |||
@@ -1,24 +1,13 @@ | |||
1 | //! `tt` crate defines a `TokenTree` data structure: this is the interface (both | 1 | //! `tt` crate defines a `TokenTree` data structure: this is the interface (both |
2 | //! input and output) of macros. It closely mirrors `proc_macro` crate's | 2 | //! input and output) of macros. It closely mirrors `proc_macro` crate's |
3 | //! `TokenTree`. | 3 | //! `TokenTree`. |
4 | |||
5 | macro_rules! impl_froms { | ||
6 | ($e:ident: $($v:ident), *) => { | ||
7 | $( | ||
8 | impl From<$v> for $e { | ||
9 | fn from(it: $v) -> $e { | ||
10 | $e::$v(it) | ||
11 | } | ||
12 | } | ||
13 | )* | ||
14 | } | ||
15 | } | ||
16 | |||
17 | use std::{ | 4 | use std::{ |
18 | fmt::{self, Debug}, | 5 | fmt::{self, Debug}, |
19 | panic::RefUnwindSafe, | 6 | panic::RefUnwindSafe, |
20 | }; | 7 | }; |
21 | 8 | ||
9 | use stdx::impl_from; | ||
10 | |||
22 | pub use smol_str::SmolStr; | 11 | pub use smol_str::SmolStr; |
23 | 12 | ||
24 | /// Represents identity of the token. | 13 | /// Represents identity of the token. |
@@ -41,7 +30,7 @@ pub enum TokenTree { | |||
41 | Leaf(Leaf), | 30 | Leaf(Leaf), |
42 | Subtree(Subtree), | 31 | Subtree(Subtree), |
43 | } | 32 | } |
44 | impl_froms!(TokenTree: Leaf, Subtree); | 33 | impl_from!(Leaf, Subtree for TokenTree); |
45 | 34 | ||
46 | impl TokenTree { | 35 | impl TokenTree { |
47 | pub fn empty() -> Self { | 36 | pub fn empty() -> Self { |
@@ -55,7 +44,7 @@ pub enum Leaf { | |||
55 | Punct(Punct), | 44 | Punct(Punct), |
56 | Ident(Ident), | 45 | Ident(Ident), |
57 | } | 46 | } |
58 | impl_froms!(Leaf: Literal, Punct, Ident); | 47 | impl_from!(Literal, Punct, Ident for Leaf); |
59 | 48 | ||
60 | #[derive(Clone, PartialEq, Eq, Hash, Default)] | 49 | #[derive(Clone, PartialEq, Eq, Hash, Default)] |
61 | pub struct Subtree { | 50 | pub struct Subtree { |