diff options
Diffstat (limited to 'crates/mbe')
-rw-r--r-- | crates/mbe/src/expander/matcher.rs | 8 | ||||
-rw-r--r-- | crates/mbe/src/expander/transcriber.rs | 2 | ||||
-rw-r--r-- | crates/mbe/src/lib.rs | 10 | ||||
-rw-r--r-- | crates/mbe/src/subtree_source.rs | 2 | ||||
-rw-r--r-- | crates/mbe/src/syntax_bridge.rs | 2 | ||||
-rw-r--r-- | crates/mbe/src/tt_iter.rs | 9 |
6 files changed, 17 insertions, 16 deletions
diff --git a/crates/mbe/src/expander/matcher.rs b/crates/mbe/src/expander/matcher.rs index b4f2fe9a4..0d694b1a7 100644 --- a/crates/mbe/src/expander/matcher.rs +++ b/crates/mbe/src/expander/matcher.rs | |||
@@ -645,7 +645,7 @@ fn match_loop(pattern: &MetaTemplate, src: &tt::Subtree) -> Match { | |||
645 | None if match_res.err.is_none() => { | 645 | None if match_res.err.is_none() => { |
646 | bindings_builder.push_optional(&mut item.bindings, name); | 646 | bindings_builder.push_optional(&mut item.bindings, name); |
647 | } | 647 | } |
648 | _ => {} | 648 | None => {} |
649 | } | 649 | } |
650 | if let Some(err) = match_res.err { | 650 | if let Some(err) = match_res.err { |
651 | res.add_err(err); | 651 | res.add_err(err); |
@@ -756,7 +756,7 @@ impl<'a> TtIter<'a> { | |||
756 | let ok = match separator { | 756 | let ok = match separator { |
757 | Separator::Ident(lhs) if idx == 0 => match fork.expect_ident_or_underscore() { | 757 | Separator::Ident(lhs) if idx == 0 => match fork.expect_ident_or_underscore() { |
758 | Ok(rhs) => rhs.text == lhs.text, | 758 | Ok(rhs) => rhs.text == lhs.text, |
759 | _ => false, | 759 | Err(_) => false, |
760 | }, | 760 | }, |
761 | Separator::Literal(lhs) if idx == 0 => match fork.expect_literal() { | 761 | Separator::Literal(lhs) if idx == 0 => match fork.expect_literal() { |
762 | Ok(rhs) => match rhs { | 762 | Ok(rhs) => match rhs { |
@@ -764,11 +764,11 @@ impl<'a> TtIter<'a> { | |||
764 | tt::Leaf::Ident(rhs) => rhs.text == lhs.text, | 764 | tt::Leaf::Ident(rhs) => rhs.text == lhs.text, |
765 | tt::Leaf::Punct(_) => false, | 765 | tt::Leaf::Punct(_) => false, |
766 | }, | 766 | }, |
767 | _ => false, | 767 | Err(_) => false, |
768 | }, | 768 | }, |
769 | Separator::Puncts(lhss) if idx < lhss.len() => match fork.expect_punct() { | 769 | Separator::Puncts(lhss) if idx < lhss.len() => match fork.expect_punct() { |
770 | Ok(rhs) => rhs.char == lhss[idx].char, | 770 | Ok(rhs) => rhs.char == lhss[idx].char, |
771 | _ => false, | 771 | Err(_) => false, |
772 | }, | 772 | }, |
773 | _ => false, | 773 | _ => false, |
774 | }; | 774 | }; |
diff --git a/crates/mbe/src/expander/transcriber.rs b/crates/mbe/src/expander/transcriber.rs index 49a137577..4894e2a0c 100644 --- a/crates/mbe/src/expander/transcriber.rs +++ b/crates/mbe/src/expander/transcriber.rs | |||
@@ -241,6 +241,6 @@ fn push_fragment(buf: &mut Vec<tt::TokenTree>, fragment: Fragment) { | |||
241 | fn push_subtree(buf: &mut Vec<tt::TokenTree>, tt: tt::Subtree) { | 241 | fn push_subtree(buf: &mut Vec<tt::TokenTree>, tt: tt::Subtree) { |
242 | match tt.delimiter { | 242 | match tt.delimiter { |
243 | None => buf.extend(tt.token_trees), | 243 | None => buf.extend(tt.token_trees), |
244 | _ => buf.push(tt.into()), | 244 | Some(_) => buf.push(tt.into()), |
245 | } | 245 | } |
246 | } | 246 | } |
diff --git a/crates/mbe/src/lib.rs b/crates/mbe/src/lib.rs index 8c8528aaf..fcc596756 100644 --- a/crates/mbe/src/lib.rs +++ b/crates/mbe/src/lib.rs | |||
@@ -135,7 +135,7 @@ impl Shift { | |||
135 | 135 | ||
136 | /// Shift given TokenTree token id | 136 | /// Shift given TokenTree token id |
137 | fn shift_all(self, tt: &mut tt::Subtree) { | 137 | fn shift_all(self, tt: &mut tt::Subtree) { |
138 | for t in tt.token_trees.iter_mut() { | 138 | for t in &mut tt.token_trees { |
139 | match t { | 139 | match t { |
140 | tt::TokenTree::Leaf(leaf) => match leaf { | 140 | tt::TokenTree::Leaf(leaf) => match leaf { |
141 | tt::Leaf::Ident(ident) => ident.id = self.shift(ident.id), | 141 | tt::Leaf::Ident(ident) => ident.id = self.shift(ident.id), |
@@ -188,7 +188,7 @@ impl MacroRules { | |||
188 | } | 188 | } |
189 | } | 189 | } |
190 | 190 | ||
191 | for rule in rules.iter() { | 191 | for rule in &rules { |
192 | validate(&rule.lhs)?; | 192 | validate(&rule.lhs)?; |
193 | } | 193 | } |
194 | 194 | ||
@@ -241,7 +241,7 @@ impl MacroDef { | |||
241 | } | 241 | } |
242 | rules.push(rule); | 242 | rules.push(rule); |
243 | } | 243 | } |
244 | for rule in rules.iter() { | 244 | for rule in &rules { |
245 | validate(&rule.lhs)?; | 245 | validate(&rule.lhs)?; |
246 | } | 246 | } |
247 | 247 | ||
@@ -268,7 +268,7 @@ impl MacroDef { | |||
268 | } | 268 | } |
269 | 269 | ||
270 | impl Rule { | 270 | impl Rule { |
271 | fn parse(src: &mut TtIter, expect_arrow: bool) -> Result<Rule, ParseError> { | 271 | fn parse(src: &mut TtIter, expect_arrow: bool) -> Result<Self, ParseError> { |
272 | let lhs = src | 272 | let lhs = src |
273 | .expect_subtree() | 273 | .expect_subtree() |
274 | .map_err(|()| ParseError::Expected("expected subtree".to_string()))?; | 274 | .map_err(|()| ParseError::Expected("expected subtree".to_string()))?; |
@@ -356,7 +356,7 @@ impl<T> ExpandResult<T> { | |||
356 | } | 356 | } |
357 | 357 | ||
358 | pub fn result(self) -> Result<T, ExpandError> { | 358 | pub fn result(self) -> Result<T, ExpandError> { |
359 | self.err.map(Err).unwrap_or(Ok(self.value)) | 359 | self.err.map_or(Ok(self.value), Err) |
360 | } | 360 | } |
361 | } | 361 | } |
362 | 362 | ||
diff --git a/crates/mbe/src/subtree_source.rs b/crates/mbe/src/subtree_source.rs index ee80807ad..ffc2a6017 100644 --- a/crates/mbe/src/subtree_source.rs +++ b/crates/mbe/src/subtree_source.rs | |||
@@ -115,7 +115,7 @@ impl<'a> TokenSource for SubtreeTokenSource { | |||
115 | fn is_keyword(&self, kw: &str) -> bool { | 115 | fn is_keyword(&self, kw: &str) -> bool { |
116 | match self.cached.get(self.curr.1) { | 116 | match self.cached.get(self.curr.1) { |
117 | Some(t) => t.text == *kw, | 117 | Some(t) => t.text == *kw, |
118 | _ => false, | 118 | None => false, |
119 | } | 119 | } |
120 | } | 120 | } |
121 | } | 121 | } |
diff --git a/crates/mbe/src/syntax_bridge.rs b/crates/mbe/src/syntax_bridge.rs index cdc22425d..7526bd8e6 100644 --- a/crates/mbe/src/syntax_bridge.rs +++ b/crates/mbe/src/syntax_bridge.rs | |||
@@ -283,7 +283,7 @@ trait TokenConvertor { | |||
283 | let (id, idx) = self.id_alloc().open_delim(range); | 283 | let (id, idx) = self.id_alloc().open_delim(range); |
284 | subtree.delimiter = Some(tt::Delimiter { id, kind }); | 284 | subtree.delimiter = Some(tt::Delimiter { id, kind }); |
285 | 285 | ||
286 | while self.peek().map(|it| it.kind() != closed).unwrap_or(false) { | 286 | while self.peek().map_or(false, |it| it.kind() != closed) { |
287 | self.collect_leaf(&mut subtree.token_trees); | 287 | self.collect_leaf(&mut subtree.token_trees); |
288 | } | 288 | } |
289 | let last_range = match self.bump() { | 289 | let last_range = match self.bump() { |
diff --git a/crates/mbe/src/tt_iter.rs b/crates/mbe/src/tt_iter.rs index 5a4eca7bf..65da83476 100644 --- a/crates/mbe/src/tt_iter.rs +++ b/crates/mbe/src/tt_iter.rs | |||
@@ -121,10 +121,11 @@ impl<'a> TtIter<'a> { | |||
121 | 121 | ||
122 | parser::parse_fragment(&mut src, &mut sink, fragment_kind); | 122 | parser::parse_fragment(&mut src, &mut sink, fragment_kind); |
123 | 123 | ||
124 | let mut err = None; | 124 | let mut err = if !sink.cursor.is_root() || sink.error { |
125 | if !sink.cursor.is_root() || sink.error { | 125 | Some(err!("expected {:?}", fragment_kind)) |
126 | err = Some(err!("expected {:?}", fragment_kind)); | 126 | } else { |
127 | } | 127 | None |
128 | }; | ||
128 | 129 | ||
129 | let mut curr = buffer.begin(); | 130 | let mut curr = buffer.begin(); |
130 | let mut res = vec![]; | 131 | let mut res = vec![]; |