diff options
Diffstat (limited to 'crates/ra_mbe/src/mbe_expander/matcher.rs')
-rw-r--r-- | crates/ra_mbe/src/mbe_expander/matcher.rs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/crates/ra_mbe/src/mbe_expander/matcher.rs b/crates/ra_mbe/src/mbe_expander/matcher.rs index ae65fb69a..f40d55d4e 100644 --- a/crates/ra_mbe/src/mbe_expander/matcher.rs +++ b/crates/ra_mbe/src/mbe_expander/matcher.rs | |||
@@ -255,7 +255,7 @@ impl<'a> TtIter<'a> { | |||
255 | pub(crate) fn expect_fragment( | 255 | pub(crate) fn expect_fragment( |
256 | &mut self, | 256 | &mut self, |
257 | fragment_kind: ra_parser::FragmentKind, | 257 | fragment_kind: ra_parser::FragmentKind, |
258 | ) -> ExpandResult<tt::TokenTree> { | 258 | ) -> ExpandResult<Option<tt::TokenTree>> { |
259 | pub(crate) struct OffsetTokenSink<'a> { | 259 | pub(crate) struct OffsetTokenSink<'a> { |
260 | pub(crate) cursor: Cursor<'a>, | 260 | pub(crate) cursor: Cursor<'a>, |
261 | pub(crate) error: bool, | 261 | pub(crate) error: bool, |
@@ -297,12 +297,16 @@ impl<'a> TtIter<'a> { | |||
297 | } | 297 | } |
298 | } | 298 | } |
299 | self.inner = self.inner.as_slice()[res.len()..].iter(); | 299 | self.inner = self.inner.as_slice()[res.len()..].iter(); |
300 | if res.len() == 0 && err.is_none() { | ||
301 | err = Some(err!("no tokens consumed")); | ||
302 | } | ||
300 | let res = match res.len() { | 303 | let res = match res.len() { |
301 | 1 => res[0].clone(), | 304 | 1 => Some(res[0].clone()), |
302 | _ => tt::TokenTree::Subtree(tt::Subtree { | 305 | 0 => None, |
306 | _ => Some(tt::TokenTree::Subtree(tt::Subtree { | ||
303 | delimiter: None, | 307 | delimiter: None, |
304 | token_trees: res.into_iter().cloned().collect(), | 308 | token_trees: res.into_iter().cloned().collect(), |
305 | }), | 309 | })), |
306 | }; | 310 | }; |
307 | (res, err) | 311 | (res, err) |
308 | } | 312 | } |
@@ -312,7 +316,7 @@ impl<'a> TtIter<'a> { | |||
312 | match fork.expect_fragment(Visibility) { | 316 | match fork.expect_fragment(Visibility) { |
313 | (tt, None) => { | 317 | (tt, None) => { |
314 | *self = fork; | 318 | *self = fork; |
315 | Some(tt) | 319 | tt |
316 | } | 320 | } |
317 | (_, Some(_)) => None, | 321 | (_, Some(_)) => None, |
318 | } | 322 | } |
@@ -419,8 +423,8 @@ fn match_meta_var(kind: &str, input: &mut TtIter) -> ExpandResult<Option<Fragmen | |||
419 | } | 423 | } |
420 | }; | 424 | }; |
421 | let (tt, err) = input.expect_fragment(fragment); | 425 | let (tt, err) = input.expect_fragment(fragment); |
422 | let fragment = if kind == "expr" { Fragment::Ast(tt) } else { Fragment::Tokens(tt) }; | 426 | let fragment = if kind == "expr" { tt.map(Fragment::Ast) } else { tt.map(Fragment::Tokens) }; |
423 | (Some(fragment), err) | 427 | (fragment, err) |
424 | } | 428 | } |
425 | 429 | ||
426 | fn collect_vars(buf: &mut Vec<SmolStr>, pattern: &tt::Subtree) -> Result<(), ExpandError> { | 430 | fn collect_vars(buf: &mut Vec<SmolStr>, pattern: &tt::Subtree) -> Result<(), ExpandError> { |