Skip to content

Commit c670a15

Browse files
committed
Details about macro NestingState hit and at_end fields
1 parent 6d84dee commit c670a15

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

crates/ra_mbe/src/mbe_expander/transcriber.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ impl Bindings {
1818
let mut b = self.inner.get(name).ok_or_else(|| {
1919
ExpandError::BindingError(format!("could not find binding `{}`", name))
2020
})?;
21-
for s in nesting.iter_mut() {
22-
s.hit = true;
21+
for nesting_state in nesting.iter_mut() {
22+
nesting_state.hit = true;
2323
b = match b {
2424
Binding::Fragment(_) => break,
25-
Binding::Nested(bs) => bs.get(s.idx).ok_or_else(|| {
26-
s.at_end = true;
25+
Binding::Nested(bs) => bs.get(nesting_state.idx).ok_or_else(|| {
26+
nesting_state.at_end = true;
2727
ExpandError::BindingError(format!("could not find nested binding `{}`", name))
2828
})?,
2929
Binding::Empty => {
30-
s.at_end = true;
30+
nesting_state.at_end = true;
3131
return Err(ExpandError::BindingError(format!(
3232
"could not find empty binding `{}`",
3333
name
@@ -61,7 +61,11 @@ pub(super) fn transcribe(
6161
#[derive(Debug)]
6262
struct NestingState {
6363
idx: usize,
64+
/// `hit` is currently necessary to tell `expand_repeat` if it should stop
65+
/// because there is no variable in use by the current repetition
6466
hit: bool,
67+
/// `at_end` is currently necessary to tell `expand_repeat` if it should stop
68+
/// because there is no more value avaible for the current repetition
6569
at_end: bool,
6670
}
6771

@@ -130,8 +134,7 @@ fn expand_var(ctx: &mut ExpandCtx, v: &SmolStr) -> Result<Fragment, ExpandError>
130134
.into();
131135
Fragment::Tokens(tt)
132136
} else {
133-
let fragment = ctx.bindings.get(&v, &mut ctx.nesting)?.clone();
134-
fragment
137+
ctx.bindings.get(&v, &mut ctx.nesting)?.clone()
135138
};
136139
Ok(res)
137140
}

0 commit comments

Comments
 (0)