diff options
Diffstat (limited to 'crates/ra_mbe/src/lib.rs')
-rw-r--r-- | crates/ra_mbe/src/lib.rs | 28 |
1 files changed, 8 insertions, 20 deletions
diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs index 2c8ad4429..b09837831 100644 --- a/crates/ra_mbe/src/lib.rs +++ b/crates/ra_mbe/src/lib.rs | |||
@@ -137,18 +137,12 @@ impl_froms!(TokenTree: Leaf, Subtree); | |||
137 | "#; | 137 | "#; |
138 | 138 | ||
139 | let source_file = ast::SourceFile::parse(macro_definition); | 139 | let source_file = ast::SourceFile::parse(macro_definition); |
140 | let macro_definition = source_file | 140 | let macro_definition = |
141 | .syntax() | 141 | source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap(); |
142 | .descendants() | ||
143 | .find_map(ast::MacroCall::cast) | ||
144 | .unwrap(); | ||
145 | 142 | ||
146 | let source_file = ast::SourceFile::parse(macro_invocation); | 143 | let source_file = ast::SourceFile::parse(macro_invocation); |
147 | let macro_invocation = source_file | 144 | let macro_invocation = |
148 | .syntax() | 145 | source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap(); |
149 | .descendants() | ||
150 | .find_map(ast::MacroCall::cast) | ||
151 | .unwrap(); | ||
152 | 146 | ||
153 | let definition_tt = ast_to_token_tree(macro_definition.token_tree().unwrap()).unwrap(); | 147 | let definition_tt = ast_to_token_tree(macro_definition.token_tree().unwrap()).unwrap(); |
154 | let invocation_tt = ast_to_token_tree(macro_invocation.token_tree().unwrap()).unwrap(); | 148 | let invocation_tt = ast_to_token_tree(macro_invocation.token_tree().unwrap()).unwrap(); |
@@ -163,11 +157,8 @@ impl_froms!(TokenTree: Leaf, Subtree); | |||
163 | 157 | ||
164 | fn create_rules(macro_definition: &str) -> MacroRules { | 158 | fn create_rules(macro_definition: &str) -> MacroRules { |
165 | let source_file = ast::SourceFile::parse(macro_definition); | 159 | let source_file = ast::SourceFile::parse(macro_definition); |
166 | let macro_definition = source_file | 160 | let macro_definition = |
167 | .syntax() | 161 | source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap(); |
168 | .descendants() | ||
169 | .find_map(ast::MacroCall::cast) | ||
170 | .unwrap(); | ||
171 | 162 | ||
172 | let definition_tt = ast_to_token_tree(macro_definition.token_tree().unwrap()).unwrap(); | 163 | let definition_tt = ast_to_token_tree(macro_definition.token_tree().unwrap()).unwrap(); |
173 | crate::MacroRules::parse(&definition_tt).unwrap() | 164 | crate::MacroRules::parse(&definition_tt).unwrap() |
@@ -175,11 +166,8 @@ impl_froms!(TokenTree: Leaf, Subtree); | |||
175 | 166 | ||
176 | fn assert_expansion(rules: &MacroRules, invocation: &str, expansion: &str) { | 167 | fn assert_expansion(rules: &MacroRules, invocation: &str, expansion: &str) { |
177 | let source_file = ast::SourceFile::parse(invocation); | 168 | let source_file = ast::SourceFile::parse(invocation); |
178 | let macro_invocation = source_file | 169 | let macro_invocation = |
179 | .syntax() | 170 | source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap(); |
180 | .descendants() | ||
181 | .find_map(ast::MacroCall::cast) | ||
182 | .unwrap(); | ||
183 | 171 | ||
184 | let invocation_tt = ast_to_token_tree(macro_invocation.token_tree().unwrap()).unwrap(); | 172 | let invocation_tt = ast_to_token_tree(macro_invocation.token_tree().unwrap()).unwrap(); |
185 | 173 | ||