diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-04-03 02:14:56 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-04-03 02:14:56 +0100 |
commit | bf695c487a05efecf64475ff4c34a16e90629ff1 (patch) | |
tree | b02702c17749c958434ee465530555b335abe2b8 /crates/mbe | |
parent | eb264fb81963d9ec08b2797818073e8ae2993a41 (diff) | |
parent | 5742cdf3f1c591709e68d65c5701257cb77583db (diff) |
Merge #8304
8304: Support the new `panic!()` macro r=jonas-schievink a=jonas-schievink
Includes a minor fixup to macro 2.0 parsing.
bors r+
Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/mbe')
-rw-r--r-- | crates/mbe/src/lib.rs | 6 | ||||
-rw-r--r-- | crates/mbe/src/tests/expand.rs | 15 | ||||
-rw-r--r-- | crates/mbe/src/tt_iter.rs | 11 |
3 files changed, 30 insertions, 2 deletions
diff --git a/crates/mbe/src/lib.rs b/crates/mbe/src/lib.rs index e74f8cf3f..3af5bc18b 100644 --- a/crates/mbe/src/lib.rs +++ b/crates/mbe/src/lib.rs | |||
@@ -220,9 +220,11 @@ impl MacroDef { | |||
220 | while src.len() > 0 { | 220 | while src.len() > 0 { |
221 | let rule = Rule::parse(&mut src, true)?; | 221 | let rule = Rule::parse(&mut src, true)?; |
222 | rules.push(rule); | 222 | rules.push(rule); |
223 | if let Err(()) = src.expect_char(';') { | 223 | if let Err(()) = src.expect_any_char(&[';', ',']) { |
224 | if src.len() > 0 { | 224 | if src.len() > 0 { |
225 | return Err(ParseError::Expected("expected `;`".to_string())); | 225 | return Err(ParseError::Expected( |
226 | "expected `;` or `,` to delimit rules".to_string(), | ||
227 | )); | ||
226 | } | 228 | } |
227 | break; | 229 | break; |
228 | } | 230 | } |
diff --git a/crates/mbe/src/tests/expand.rs b/crates/mbe/src/tests/expand.rs index 8951f3813..e02d038b6 100644 --- a/crates/mbe/src/tests/expand.rs +++ b/crates/mbe/src/tests/expand.rs | |||
@@ -663,6 +663,21 @@ macro foo { | |||
663 | } | 663 | } |
664 | 664 | ||
665 | #[test] | 665 | #[test] |
666 | fn test_macro_2_0_panic_2015() { | ||
667 | parse_macro2( | ||
668 | r#" | ||
669 | macro panic_2015 { | ||
670 | () => ( | ||
671 | ), | ||
672 | (bar) => ( | ||
673 | ), | ||
674 | } | ||
675 | "#, | ||
676 | ) | ||
677 | .assert_expand_items("panic_2015!(bar);", ""); | ||
678 | } | ||
679 | |||
680 | #[test] | ||
666 | fn test_path() { | 681 | fn test_path() { |
667 | parse_macro( | 682 | parse_macro( |
668 | r#" | 683 | r#" |
diff --git a/crates/mbe/src/tt_iter.rs b/crates/mbe/src/tt_iter.rs index 319a40f2a..195b8cf30 100644 --- a/crates/mbe/src/tt_iter.rs +++ b/crates/mbe/src/tt_iter.rs | |||
@@ -34,6 +34,17 @@ impl<'a> TtIter<'a> { | |||
34 | } | 34 | } |
35 | } | 35 | } |
36 | 36 | ||
37 | pub(crate) fn expect_any_char(&mut self, chars: &[char]) -> Result<(), ()> { | ||
38 | match self.next() { | ||
39 | Some(tt::TokenTree::Leaf(tt::Leaf::Punct(tt::Punct { char: c, .. }))) | ||
40 | if chars.contains(c) => | ||
41 | { | ||
42 | Ok(()) | ||
43 | } | ||
44 | _ => Err(()), | ||
45 | } | ||
46 | } | ||
47 | |||
37 | pub(crate) fn expect_subtree(&mut self) -> Result<&'a tt::Subtree, ()> { | 48 | pub(crate) fn expect_subtree(&mut self) -> Result<&'a tt::Subtree, ()> { |
38 | match self.next() { | 49 | match self.next() { |
39 | Some(tt::TokenTree::Subtree(it)) => Ok(it), | 50 | Some(tt::TokenTree::Subtree(it)) => Ok(it), |