aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_tt
diff options
context:
space:
mode:
authorZac Pullar-Strecker <[email protected]>2020-07-31 03:12:44 +0100
committerZac Pullar-Strecker <[email protected]>2020-07-31 03:12:44 +0100
commitf05d7b41a719d848844b054a16477b29d0f063c6 (patch)
tree0a8a0946e8aef2ce64d4c13d0035ba41cce2daf3 /crates/ra_tt
parent73ff610e41959e3e7c78a2b4b25b086883132956 (diff)
parent6b7cb8b5ab539fc4333ce34bc29bf77c976f232a (diff)
Merge remote-tracking branch 'upstream/master' into 503-hover-doc-links
Hasn't fixed tests yet.
Diffstat (limited to 'crates/ra_tt')
-rw-r--r--crates/ra_tt/Cargo.toml2
-rw-r--r--crates/ra_tt/src/lib.rs19
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"
3name = "ra_tt" 3name = "ra_tt"
4version = "0.1.0" 4version = "0.1.0"
5authors = ["rust-analyzer developers"] 5authors = ["rust-analyzer developers"]
6license = "MIT OR Apache-2.0"
6 7
7[lib] 8[lib]
8doctest = false 9doctest = false
9 10
10[dependencies] 11[dependencies]
12stdx = { 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
13smol_str = { version = "0.1.15", features = ["serde"] } 15smol_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
5macro_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
17use std::{ 4use std::{
18 fmt::{self, Debug}, 5 fmt::{self, Debug},
19 panic::RefUnwindSafe, 6 panic::RefUnwindSafe,
20}; 7};
21 8
9use stdx::impl_from;
10
22pub use smol_str::SmolStr; 11pub 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}
44impl_froms!(TokenTree: Leaf, Subtree); 33impl_from!(Leaf, Subtree for TokenTree);
45 34
46impl TokenTree { 35impl 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}
58impl_froms!(Leaf: Literal, Punct, Ident); 47impl_from!(Literal, Punct, Ident for Leaf);
59 48
60#[derive(Clone, PartialEq, Eq, Hash, Default)] 49#[derive(Clone, PartialEq, Eq, Hash, Default)]
61pub struct Subtree { 50pub struct Subtree {