aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_tt/src/lib.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-02-11 18:32:18 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-02-11 18:32:18 +0000
commita78142cc648cd0c95dcaabc598d614f0edc24eb6 (patch)
tree6547cd1d0e5b7494ac6b9ec9b446ba0db4c149ad /crates/ra_tt/src/lib.rs
parentb356ab46f2b7482bf1ae0c0f6cd5a87ece8742bf (diff)
parentae312680d6d7bb0cc00d2b8d9799249d36e0136e (diff)
Merge #791
791: docs r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_tt/src/lib.rs')
-rw-r--r--crates/ra_tt/src/lib.rs18
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
19use smol_str::SmolStr; 19use 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)]
28pub struct TokenId(pub u32);
29
30impl TokenId {
31 pub const fn unspecified() -> TokenId {
32 TokenId(!0)
33 }
34}
35
21#[derive(Debug, Clone)] 36#[derive(Debug, Clone)]
22pub enum TokenTree { 37pub enum TokenTree {
23 Leaf(Leaf), 38 Leaf(Leaf),
@@ -67,6 +82,7 @@ pub enum Spacing {
67#[derive(Debug, Clone)] 82#[derive(Debug, Clone)]
68pub struct Ident { 83pub struct Ident {
69 pub text: SmolStr, 84 pub text: SmolStr,
85 pub id: TokenId,
70} 86}
71 87
72impl fmt::Display for TokenTree { 88impl fmt::Display for TokenTree {