diff options
Diffstat (limited to 'crates/ra_tt/src')
-rw-r--r-- | crates/ra_tt/src/lib.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/crates/ra_tt/src/lib.rs b/crates/ra_tt/src/lib.rs index df31f72f3..c1f37b889 100644 --- a/crates/ra_tt/src/lib.rs +++ b/crates/ra_tt/src/lib.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | /// `tt` crate defines a `TokenTree` datastructure: 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 | 4 | ||
@@ -18,6 +18,21 @@ use std::fmt; | |||
18 | 18 | ||
19 | use smol_str::SmolStr; | 19 | use smol_str::SmolStr; |
20 | 20 | ||
21 | /// Represents identity of the token. | ||
22 | /// | ||
23 | /// For hygiene purposes, we need to track which expanded tokens originated from | ||
24 | /// which source tokens. We do it by assigning an distinct identity to each | ||
25 | /// source token and making sure that identities are preserved during macro | ||
26 | /// expansion. | ||
27 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
28 | pub struct TokenId(pub u32); | ||
29 | |||
30 | impl TokenId { | ||
31 | pub const fn unspecified() -> TokenId { | ||
32 | TokenId(!0) | ||
33 | } | ||
34 | } | ||
35 | |||
21 | #[derive(Debug, Clone)] | 36 | #[derive(Debug, Clone)] |
22 | pub enum TokenTree { | 37 | pub enum TokenTree { |
23 | Leaf(Leaf), | 38 | Leaf(Leaf), |
@@ -67,6 +82,7 @@ pub enum Spacing { | |||
67 | #[derive(Debug, Clone)] | 82 | #[derive(Debug, Clone)] |
68 | pub struct Ident { | 83 | pub struct Ident { |
69 | pub text: SmolStr, | 84 | pub text: SmolStr, |
85 | pub id: TokenId, | ||
70 | } | 86 | } |
71 | 87 | ||
72 | impl fmt::Display for TokenTree { | 88 | impl fmt::Display for TokenTree { |