From f3c6a2e3dbe477a7e0ac714a5bdbda6e8838fcfa Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 15 Mar 2020 15:15:56 +0100 Subject: [PATCH] Fix remaining test failure --- crates/ra_mbe/src/mbe_expander.rs | 2 -- crates/ra_mbe/src/mbe_expander/matcher.rs | 18 +++++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs index 1328e4349b..204c30e3d0 100644 --- a/crates/ra_mbe/src/mbe_expander.rs +++ b/crates/ra_mbe/src/mbe_expander.rs @@ -21,9 +21,7 @@ fn expand_rules(rules: &[crate::Rule], input: &tt::Subtree) -> ExpandResult TtIter<'a> { pub(crate) fn expect_fragment( &mut self, fragment_kind: ra_parser::FragmentKind, - ) -> ExpandResult { + ) -> ExpandResult> { pub(crate) struct OffsetTokenSink<'a> { pub(crate) cursor: Cursor<'a>, pub(crate) error: bool, @@ -297,12 +297,16 @@ impl<'a> TtIter<'a> { } } self.inner = self.inner.as_slice()[res.len()..].iter(); + if res.len() == 0 && err.is_none() { + err = Some(err!("no tokens consumed")); + } let res = match res.len() { - 1 => res[0].clone(), - _ => tt::TokenTree::Subtree(tt::Subtree { + 1 => Some(res[0].clone()), + 0 => None, + _ => Some(tt::TokenTree::Subtree(tt::Subtree { delimiter: None, token_trees: res.into_iter().cloned().collect(), - }), + })), }; (res, err) } @@ -312,7 +316,7 @@ impl<'a> TtIter<'a> { match fork.expect_fragment(Visibility) { (tt, None) => { *self = fork; - Some(tt) + tt } (_, Some(_)) => None, } @@ -419,8 +423,8 @@ fn match_meta_var(kind: &str, input: &mut TtIter) -> ExpandResult, pattern: &tt::Subtree) -> Result<(), ExpandError> {