From c670a15345467ad394df850bd3b81f76ca7e8cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Rouill=C3=A9?= Date: Mon, 30 Dec 2019 17:07:23 +0100 Subject: [PATCH] Details about macro NestingState hit and at_end fields --- crates/ra_mbe/src/mbe_expander/transcriber.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/crates/ra_mbe/src/mbe_expander/transcriber.rs b/crates/ra_mbe/src/mbe_expander/transcriber.rs index 8bb1a25a31..7662020f36 100644 --- a/crates/ra_mbe/src/mbe_expander/transcriber.rs +++ b/crates/ra_mbe/src/mbe_expander/transcriber.rs @@ -18,16 +18,16 @@ impl Bindings { let mut b = self.inner.get(name).ok_or_else(|| { ExpandError::BindingError(format!("could not find binding `{}`", name)) })?; - for s in nesting.iter_mut() { - s.hit = true; + for nesting_state in nesting.iter_mut() { + nesting_state.hit = true; b = match b { Binding::Fragment(_) => break, - Binding::Nested(bs) => bs.get(s.idx).ok_or_else(|| { - s.at_end = true; + Binding::Nested(bs) => bs.get(nesting_state.idx).ok_or_else(|| { + nesting_state.at_end = true; ExpandError::BindingError(format!("could not find nested binding `{}`", name)) })?, Binding::Empty => { - s.at_end = true; + nesting_state.at_end = true; return Err(ExpandError::BindingError(format!( "could not find empty binding `{}`", name @@ -61,7 +61,11 @@ pub(super) fn transcribe( #[derive(Debug)] struct NestingState { idx: usize, + /// `hit` is currently necessary to tell `expand_repeat` if it should stop + /// because there is no variable in use by the current repetition hit: bool, + /// `at_end` is currently necessary to tell `expand_repeat` if it should stop + /// because there is no more value avaible for the current repetition at_end: bool, } @@ -130,8 +134,7 @@ fn expand_var(ctx: &mut ExpandCtx, v: &SmolStr) -> Result .into(); Fragment::Tokens(tt) } else { - let fragment = ctx.bindings.get(&v, &mut ctx.nesting)?.clone(); - fragment + ctx.bindings.get(&v, &mut ctx.nesting)?.clone() }; Ok(res) }