Skip to content

Commit 120d76e

Browse files
bors[bot]matklad
andauthored
Merge #11179
11179: minor: simplify mbe matcher r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 29fc022 + 3038141 commit 120d76e

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

crates/mbe/src/expander/matcher.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ fn match_meta_var(kind: &str, input: &mut TtIter) -> ExpandResult<Option<Fragmen
697697
"block" => parser::PrefixEntryPoint::Block,
698698
"meta" => parser::PrefixEntryPoint::MetaItem,
699699
"item" => parser::PrefixEntryPoint::Item,
700+
"vis" => parser::PrefixEntryPoint::Vis,
700701
"expr" => {
701702
return input
702703
.expect_fragment(parser::PrefixEntryPoint::Expr)
@@ -706,33 +707,29 @@ fn match_meta_var(kind: &str, input: &mut TtIter) -> ExpandResult<Option<Fragmen
706707
let tt_result = match kind {
707708
"ident" => input
708709
.expect_ident()
709-
.map(|ident| Some(tt::Leaf::from(ident.clone()).into()))
710+
.map(|ident| tt::Leaf::from(ident.clone()).into())
710711
.map_err(|()| err!("expected ident")),
711-
"tt" => input.expect_tt().map(Some).map_err(|()| err!()),
712-
"lifetime" => {
713-
input.expect_lifetime().map(Some).map_err(|()| err!("expected lifetime"))
714-
}
712+
"tt" => input.expect_tt().map_err(|()| err!()),
713+
"lifetime" => input.expect_lifetime().map_err(|()| err!("expected lifetime")),
715714
"literal" => {
716715
let neg = input.eat_char('-');
717716
input
718717
.expect_literal()
719718
.map(|literal| {
720719
let lit = literal.clone();
721720
match neg {
722-
None => Some(lit.into()),
723-
Some(neg) => Some(tt::TokenTree::Subtree(tt::Subtree {
721+
None => lit.into(),
722+
Some(neg) => tt::TokenTree::Subtree(tt::Subtree {
724723
delimiter: None,
725724
token_trees: vec![neg, lit.into()],
726-
})),
725+
}),
727726
}
728727
})
729728
.map_err(|()| err!())
730729
}
731-
// `vis` is optional
732-
"vis" => Ok(input.expect_fragment(parser::PrefixEntryPoint::Vis).value),
733730
_ => Err(ExpandError::UnexpectedToken),
734731
};
735-
return tt_result.map(|it| it.map(Fragment::Tokens)).into();
732+
return tt_result.map(|it| Some(Fragment::Tokens(it))).into();
736733
}
737734
};
738735
input.expect_fragment(fragment).map(|it| it.map(Fragment::Tokens))

crates/mbe/src/tt_iter.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl<'a> TtIter<'a> {
114114
}
115115
}
116116

117-
let mut err = if !cursor.is_root() || error {
117+
let err = if error || !cursor.is_root() {
118118
Some(err!("expected {:?}", entry_point))
119119
} else {
120120
None
@@ -132,9 +132,6 @@ impl<'a> TtIter<'a> {
132132
}
133133
}
134134
self.inner = self.inner.as_slice()[res.len()..].iter();
135-
if res.is_empty() && err.is_none() {
136-
err = Some(err!("no tokens consumed"));
137-
}
138135
let res = match res.len() {
139136
1 => Some(res[0].cloned()),
140137
0 => None,

0 commit comments

Comments
 (0)