From c784c8ec766edf4c7ab558f71d3f87e6c7c870b9 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 26 Nov 2020 16:04:23 +0100 Subject: Use named fields in `ExpandResult` --- crates/mbe/src/mbe_expander/matcher.rs | 9 +++++---- crates/mbe/src/mbe_expander/transcriber.rs | 18 +++++++++++------- 2 files changed, 16 insertions(+), 11 deletions(-) (limited to 'crates/mbe/src/mbe_expander') diff --git a/crates/mbe/src/mbe_expander/matcher.rs b/crates/mbe/src/mbe_expander/matcher.rs index 39a8eefbd..3f8445897 100644 --- a/crates/mbe/src/mbe_expander/matcher.rs +++ b/crates/mbe/src/mbe_expander/matcher.rs @@ -158,7 +158,8 @@ fn match_subtree( continue; } }; - let ExpandResult(matched, match_err) = match_meta_var(kind.as_str(), src); + let ExpandResult { value: matched, err: match_err } = + match_meta_var(kind.as_str(), src); match matched { Some(fragment) => { res.bindings.inner.insert(name.clone(), Binding::Fragment(fragment)); @@ -342,17 +343,17 @@ impl<'a> TtIter<'a> { token_trees: res.into_iter().cloned().collect(), })), }; - ExpandResult(res, err) + ExpandResult { value: res, err } } pub(crate) fn eat_vis(&mut self) -> Option { let mut fork = self.clone(); match fork.expect_fragment(Visibility) { - ExpandResult(tt, None) => { + ExpandResult { value: tt, err: None } => { *self = fork; tt } - ExpandResult(_, Some(_)) => None, + ExpandResult { value: _, err: Some(_) } => None, } } } diff --git a/crates/mbe/src/mbe_expander/transcriber.rs b/crates/mbe/src/mbe_expander/transcriber.rs index c9525c5bf..616119ba9 100644 --- a/crates/mbe/src/mbe_expander/transcriber.rs +++ b/crates/mbe/src/mbe_expander/transcriber.rs @@ -93,17 +93,18 @@ fn expand_subtree( match op { Op::TokenTree(tt @ tt::TokenTree::Leaf(..)) => arena.push(tt.clone()), Op::TokenTree(tt::TokenTree::Subtree(tt)) => { - let ExpandResult(tt, e) = expand_subtree(ctx, tt, arena); + let ExpandResult { value: tt, err: e } = expand_subtree(ctx, tt, arena); err = err.or(e); arena.push(tt.into()); } Op::Var { name, kind: _ } => { - let ExpandResult(fragment, e) = expand_var(ctx, name); + let ExpandResult { value: fragment, err: e } = expand_var(ctx, name); err = err.or(e); push_fragment(arena, fragment); } Op::Repeat { subtree, kind, separator } => { - let ExpandResult(fragment, e) = expand_repeat(ctx, subtree, kind, separator, arena); + let ExpandResult { value: fragment, err: e } = + expand_repeat(ctx, subtree, kind, separator, arena); err = err.or(e); push_fragment(arena, fragment) } @@ -111,7 +112,7 @@ fn expand_subtree( } // drain the elements added in this instance of expand_subtree let tts = arena.drain(start_elements..arena.len()).collect(); - ExpandResult(tt::Subtree { delimiter: template.delimiter, token_trees: tts }, err) + ExpandResult { value: tt::Subtree { delimiter: template.delimiter, token_trees: tts }, err } } fn expand_var(ctx: &mut ExpandCtx, v: &SmolStr) -> ExpandResult { @@ -152,7 +153,7 @@ fn expand_var(ctx: &mut ExpandCtx, v: &SmolStr) -> ExpandResult { ExpandResult::ok(Fragment::Tokens(tt)) } else { ctx.bindings.get(&v, &mut ctx.nesting).map_or_else( - |e| ExpandResult(Fragment::Tokens(tt::TokenTree::empty()), Some(e)), + |e| ExpandResult { value: Fragment::Tokens(tt::TokenTree::empty()), err: Some(e) }, |b| ExpandResult::ok(b.clone()), ) } @@ -174,7 +175,7 @@ fn expand_repeat( let mut counter = 0; loop { - let ExpandResult(mut t, e) = expand_subtree(ctx, template, arena); + let ExpandResult { value: mut t, err: e } = expand_subtree(ctx, template, arena); let nesting_state = ctx.nesting.last_mut().unwrap(); if nesting_state.at_end || !nesting_state.hit { break; @@ -234,7 +235,10 @@ fn expand_repeat( let tt = tt::Subtree { delimiter: None, token_trees: buf }.into(); if RepeatKind::OneOrMore == kind && counter == 0 { - return ExpandResult(Fragment::Tokens(tt), Some(ExpandError::UnexpectedToken)); + return ExpandResult { + value: Fragment::Tokens(tt), + err: Some(ExpandError::UnexpectedToken), + }; } ExpandResult::ok(Fragment::Tokens(tt)) } -- cgit v1.2.3