diff options
author | Owen Avery <powerboat9.gamer@gmail.com> | 2023-05-28 23:44:57 -0400 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2023-05-30 08:33:50 +0000 |
commit | 0162ff3900ae032958d16c0a4af6c76ca3dd4335 (patch) | |
tree | 0f425776e9a63efc548ca2a2d05bf6f9771b45ab /gcc | |
parent | 2d806801404fc7628a3d022da92b73cd06197f49 (diff) | |
download | gcc-0162ff3900ae032958d16c0a4af6c76ca3dd4335.zip gcc-0162ff3900ae032958d16c0a4af6c76ca3dd4335.tar.gz gcc-0162ff3900ae032958d16c0a4af6c76ca3dd4335.tar.bz2 |
Fix handling of single fragments in repetitions
gcc/rust/ChangeLog:
* expand/rust-macro-substitute-ctx.cc
(SubstituteCtx::check_repetition_amount):
Ignore single fragments while checking repetition amount.
gcc/testsuite/ChangeLog:
* rust/compile/issue-2207.rs: New test.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/expand/rust-macro-substitute-ctx.cc | 36 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/issue-2207.rs | 12 |
2 files changed, 31 insertions, 17 deletions
diff --git a/gcc/rust/expand/rust-macro-substitute-ctx.cc b/gcc/rust/expand/rust-macro-substitute-ctx.cc index 0a38578..85c9d7e 100644 --- a/gcc/rust/expand/rust-macro-substitute-ctx.cc +++ b/gcc/rust/expand/rust-macro-substitute-ctx.cc @@ -77,31 +77,33 @@ SubstituteCtx::check_repetition_amount (size_t pattern_start, auto &fragment = it->second; - size_t repeat_amount = fragment.get_match_amount (); - if (!first_fragment_found) + if (!fragment.is_single_fragment ()) { - first_fragment_found = true; - expected_repetition_amount = repeat_amount; - } - else - { - if (repeat_amount != expected_repetition_amount - && !fragment.is_single_fragment ()) + size_t repeat_amount = fragment.get_match_amount (); + if (!first_fragment_found) + { + first_fragment_found = true; + expected_repetition_amount = repeat_amount; + } + else { - rust_error_at ( - frag_token->get_locus (), - "different amount of matches used in merged " - "repetitions: expected %lu, got %lu", - (unsigned long) expected_repetition_amount, - (unsigned long) repeat_amount); - is_valid = false; + if (repeat_amount != expected_repetition_amount) + { + rust_error_at ( + frag_token->get_locus (), + "different amount of matches used in merged " + "repetitions: expected %lu, got %lu", + (unsigned long) expected_repetition_amount, + (unsigned long) repeat_amount); + is_valid = false; + } } } } } } - return is_valid; + return is_valid && first_fragment_found; } std::vector<std::unique_ptr<AST::Token>> diff --git a/gcc/testsuite/rust/compile/issue-2207.rs b/gcc/testsuite/rust/compile/issue-2207.rs new file mode 100644 index 0000000..cdc64fa --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2207.rs @@ -0,0 +1,12 @@ +macro_rules! finish { + (+ - + * + /) => {} +} + +macro_rules! foo { + () => { foo!(+ - * /); }; + ($a:tt $($b:tt)*) => { finish!($($a $b)*); } +} + +pub fn bar() { + foo!(); +} |