aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/expand
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2022-03-18 11:34:39 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2022-03-18 12:40:05 +0100
commita64a5cf77c9685aa623ec69168e7f50324a102b9 (patch)
treeba9b636d9a2a21c4abaa2410d5efd20ac724fe87 /gcc/rust/expand
parent1bb9a29688ab4ddfec7f8d36ca2cee63c5f258d2 (diff)
downloadgcc-a64a5cf77c9685aa623ec69168e7f50324a102b9.zip
gcc-a64a5cf77c9685aa623ec69168e7f50324a102b9.tar.gz
gcc-a64a5cf77c9685aa623ec69168e7f50324a102b9.tar.bz2
macros: Do not propagate parse errors in match repetitions
Since parsing repetitions is very eager, the parser might accumulate bogus errors by trying to match more repetitions than there are. We can avoid this by clearing the parsing errors if parsing repetitions returned a valid result. This should not be an issue for previous matchers erroring out, as they would immediately return upon failure and not reach inside other match functions.
Diffstat (limited to 'gcc/rust/expand')
-rw-r--r--gcc/rust/expand/rust-macro-expand.cc11
1 files changed, 7 insertions, 4 deletions
diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc
index 3bdb8c6..6b26f98 100644
--- a/gcc/rust/expand/rust-macro-expand.cc
+++ b/gcc/rust/expand/rust-macro-expand.cc
@@ -505,9 +505,6 @@ MacroExpander::match_fragment (Parser<MacroInvocLexer> &parser,
return false;
}
- for (const auto &error : parser.get_errors ())
- error.emit_error ();
-
// it matches if the parser did not produce errors trying to parse that type
// of item
return !parser.has_errors ();
@@ -714,7 +711,13 @@ MacroExpander::match_n_matches (Parser<MacroInvocLexer> &parser,
bool did_meet_lo_bound = match_amount >= lo_bound;
bool did_meet_hi_bound = hi_bound ? match_amount <= hi_bound : true;
- return did_meet_lo_bound && did_meet_hi_bound;
+ // If the end-result is valid, then we can clear the parse errors: Since
+ // repetitions are parsed eagerly, it is okay to fail in some cases
+ auto res = did_meet_lo_bound && did_meet_hi_bound;
+ if (res)
+ parser.clear_errors ();
+
+ return res;
}
bool