diff options
Diffstat (limited to 'crates/ra_mbe/src/mbe_expander.rs')
-rw-r--r-- | crates/ra_mbe/src/mbe_expander.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs index d5189b537..1b579f319 100644 --- a/crates/ra_mbe/src/mbe_expander.rs +++ b/crates/ra_mbe/src/mbe_expander.rs | |||
@@ -206,8 +206,24 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Result<Bindings, | |||
206 | ); | 206 | ); |
207 | } | 207 | } |
208 | "vis" => { | 208 | "vis" => { |
209 | let vis = input.eat_vis().ok_or(ExpandError::UnexpectedToken)?.clone(); | 209 | // `vis` is optional |
210 | res.inner.insert(text.clone(), Binding::Simple(vis.into())); | 210 | if let Some(vis) = input.try_eat_vis() { |
211 | let vis = vis.clone(); | ||
212 | res.inner.insert(text.clone(), Binding::Simple(vis.into())); | ||
213 | } else { | ||
214 | // FIXME: Do we have a better way to represent an empty token ? | ||
215 | // Insert an empty subtree for empty token | ||
216 | res.inner.insert( | ||
217 | text.clone(), | ||
218 | Binding::Simple( | ||
219 | tt::Subtree { | ||
220 | delimiter: tt::Delimiter::None, | ||
221 | token_trees: vec![], | ||
222 | } | ||
223 | .into(), | ||
224 | ), | ||
225 | ); | ||
226 | } | ||
211 | } | 227 | } |
212 | 228 | ||
213 | _ => return Err(ExpandError::UnexpectedToken), | 229 | _ => return Err(ExpandError::UnexpectedToken), |