aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_expand/src
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2019-12-12 13:47:54 +0000
committerEdwin Cheng <[email protected]>2019-12-18 03:20:22 +0000
commitaceb9d7fb0809ccf364514d9177342edea144c59 (patch)
tree138ee608477eb951072eeac6ace239647e3d01a3 /crates/ra_hir_expand/src
parent46ca40ccfced6945e05a25979a2703ad967d2fe0 (diff)
Add token ids for all tt::Leaf
Diffstat (limited to 'crates/ra_hir_expand/src')
-rw-r--r--crates/ra_hir_expand/src/builtin_derive.rs28
-rw-r--r--crates/ra_hir_expand/src/quote.rs13
2 files changed, 32 insertions, 9 deletions
diff --git a/crates/ra_hir_expand/src/builtin_derive.rs b/crates/ra_hir_expand/src/builtin_derive.rs
index b26441253..62c60e336 100644
--- a/crates/ra_hir_expand/src/builtin_derive.rs
+++ b/crates/ra_hir_expand/src/builtin_derive.rs
@@ -97,11 +97,24 @@ fn parse_adt(tt: &tt::Subtree) -> Result<BasicAdtInfo, mbe::ExpandError> {
97 97
98fn make_type_args(n: usize, bound: Vec<tt::TokenTree>) -> Vec<tt::TokenTree> { 98fn make_type_args(n: usize, bound: Vec<tt::TokenTree>) -> Vec<tt::TokenTree> {
99 let mut result = Vec::<tt::TokenTree>::new(); 99 let mut result = Vec::<tt::TokenTree>::new();
100 result.push(tt::Leaf::Punct(tt::Punct { char: '<', spacing: tt::Spacing::Alone }).into()); 100 result.push(
101 tt::Leaf::Punct(tt::Punct {
102 char: '<',
103 spacing: tt::Spacing::Alone,
104 id: tt::TokenId::unspecified(),
105 })
106 .into(),
107 );
101 for i in 0..n { 108 for i in 0..n {
102 if i > 0 { 109 if i > 0 {
103 result 110 result.push(
104 .push(tt::Leaf::Punct(tt::Punct { char: ',', spacing: tt::Spacing::Alone }).into()); 111 tt::Leaf::Punct(tt::Punct {
112 char: ',',
113 spacing: tt::Spacing::Alone,
114 id: tt::TokenId::unspecified(),
115 })
116 .into(),
117 );
105 } 118 }
106 result.push( 119 result.push(
107 tt::Leaf::Ident(tt::Ident { 120 tt::Leaf::Ident(tt::Ident {
@@ -112,7 +125,14 @@ fn make_type_args(n: usize, bound: Vec<tt::TokenTree>) -> Vec<tt::TokenTree> {
112 ); 125 );
113 result.extend(bound.iter().cloned()); 126 result.extend(bound.iter().cloned());
114 } 127 }
115 result.push(tt::Leaf::Punct(tt::Punct { char: '>', spacing: tt::Spacing::Alone }).into()); 128 result.push(
129 tt::Leaf::Punct(tt::Punct {
130 char: '>',
131 spacing: tt::Spacing::Alone,
132 id: tt::TokenId::unspecified(),
133 })
134 .into(),
135 );
116 result 136 result
117} 137}
118 138
diff --git a/crates/ra_hir_expand/src/quote.rs b/crates/ra_hir_expand/src/quote.rs
index aa8a5f23f..bce38cc67 100644
--- a/crates/ra_hir_expand/src/quote.rs
+++ b/crates/ra_hir_expand/src/quote.rs
@@ -29,6 +29,7 @@ macro_rules! __quote {
29 tt::Leaf::Punct(tt::Punct { 29 tt::Leaf::Punct(tt::Punct {
30 char: $first, 30 char: $first,
31 spacing: tt::Spacing::Alone, 31 spacing: tt::Spacing::Alone,
32 id: tt::TokenId::unspecified(),
32 }).into() 33 }).into()
33 ] 34 ]
34 } 35 }
@@ -40,10 +41,12 @@ macro_rules! __quote {
40 tt::Leaf::Punct(tt::Punct { 41 tt::Leaf::Punct(tt::Punct {
41 char: $first, 42 char: $first,
42 spacing: tt::Spacing::Joint, 43 spacing: tt::Spacing::Joint,
44 id: tt::TokenId::unspecified(),
43 }).into(), 45 }).into(),
44 tt::Leaf::Punct(tt::Punct { 46 tt::Leaf::Punct(tt::Punct {
45 char: $sec, 47 char: $sec,
46 spacing: tt::Spacing::Alone, 48 spacing: tt::Spacing::Alone,
49 id: tt::TokenId::unspecified(),
47 }).into() 50 }).into()
48 ] 51 ]
49 } 52 }
@@ -179,15 +182,15 @@ macro_rules! impl_to_to_tokentrees {
179} 182}
180 183
181impl_to_to_tokentrees! { 184impl_to_to_tokentrees! {
182 u32 => self { tt::Literal{text: self.to_string().into()} }; 185 u32 => self { tt::Literal{text: self.to_string().into(), id: tt::TokenId::unspecified()} };
183 usize => self { tt::Literal{text: self.to_string().into()}}; 186 usize => self { tt::Literal{text: self.to_string().into(), id: tt::TokenId::unspecified()}};
184 i32 => self { tt::Literal{text: self.to_string().into()}}; 187 i32 => self { tt::Literal{text: self.to_string().into(), id: tt::TokenId::unspecified()}};
185 tt::Leaf => self { self }; 188 tt::Leaf => self { self };
186 tt::Literal => self { self }; 189 tt::Literal => self { self };
187 tt::Ident => self { self }; 190 tt::Ident => self { self };
188 tt::Punct => self { self }; 191 tt::Punct => self { self };
189 &str => self { tt::Literal{text: format!("{:?}", self.escape_default().to_string()).into()}}; 192 &str => self { tt::Literal{text: format!("{:?}", self.escape_default().to_string()).into(), id: tt::TokenId::unspecified()}};
190 String => self { tt::Literal{text: format!("{:?}", self.escape_default().to_string()).into()}} 193 String => self { tt::Literal{text: format!("{:?}", self.escape_default().to_string()).into(), id: tt::TokenId::unspecified()}}
191} 194}
192 195
193#[cfg(test)] 196#[cfg(test)]