diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-07-13 15:33:32 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-13 15:33:32 +0100 |
commit | 853440775d72974585ca3fe39f9688a4d4302dd3 (patch) | |
tree | 89272d8f03145df99fe68f0e35f8892dc4ab2c72 /crates/ra_tt | |
parent | 4b1c3724364ff538acdcb44bdd23d501ef54cff3 (diff) | |
parent | 693ac892f2db5db1ce7cf86db7bf6207b3515c42 (diff) |
Merge #5342
5342: Don't copy-paste `impl_froms` into every crate r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_tt')
-rw-r--r-- | crates/ra_tt/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_tt/src/lib.rs | 19 |
2 files changed, 5 insertions, 15 deletions
diff --git a/crates/ra_tt/Cargo.toml b/crates/ra_tt/Cargo.toml index f7230a9ca..b5b12e3af 100644 --- a/crates/ra_tt/Cargo.toml +++ b/crates/ra_tt/Cargo.toml | |||
@@ -8,6 +8,7 @@ authors = ["rust-analyzer developers"] | |||
8 | doctest = false | 8 | doctest = false |
9 | 9 | ||
10 | [dependencies] | 10 | [dependencies] |
11 | stdx = { path = "../stdx" } | ||
11 | # ideally, `serde` should be enabled by `rust-analyzer`, but we enable it here | 12 | # ideally, `serde` should be enabled by `rust-analyzer`, but we enable it here |
12 | # to reduce number of compilations | 13 | # to reduce number of compilations |
13 | smol_str = { version = "0.1.15", features = ["serde"] } | 14 | 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 { |