Minor fixups related to ambiguity errors
diff --git a/compiler/rustc_expand/src/mbe/diagnostics.rs b/compiler/rustc_expand/src/mbe/diagnostics.rs index 5a88d57..c53c3e0 100644 --- a/compiler/rustc_expand/src/mbe/diagnostics.rs +++ b/compiler/rustc_expand/src/mbe/diagnostics.rs
@@ -221,7 +221,7 @@ fn after_arm(&mut self, which_matcher: WhichMatcher, result: &NamedParseResult<S } Ambiguity => { if self.result.is_none() { - bug!("`Error(..)` is only constructed through `Self::ambiguity()`"); + bug!("An ambiguity error occurred but `Self::ambiguity()` was not called"); } } ErrorReported(guar) => self.result = Some((self.root_span, guar)),
diff --git a/compiler/rustc_expand/src/mbe/macro_parser.rs b/compiler/rustc_expand/src/mbe/macro_parser.rs index 641c50b..22f27df 100644 --- a/compiler/rustc_expand/src/mbe/macro_parser.rs +++ b/compiler/rustc_expand/src/mbe/macro_parser.rs
@@ -302,6 +302,8 @@ pub(crate) enum ParseResult<T, F> { /// The usize is the approximate position of the token in the input token stream. Failure(F), /// The input could be parsed in multiple distinct ways. + /// + /// [`Tracker::ambiguity()`] will be called beforehand. Ambiguity, ErrorReported(ErrorGuaranteed), }
diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index a6acccd..43863b3 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs
@@ -374,6 +374,9 @@ pub(super) trait Tracker<'matcher> { /// this is called, `before_match_loc` was called at least once (with a `MatcherLoc::Eof`). fn after_arm(&mut self, which_matcher: WhichMatcher, result: &NamedParseResult<Self::Failure>); + /// An ambiguity error occurred. + /// + /// The parser will return [`NamedParseResult::Ambiguity`] after calling this. fn ambiguity( &mut self, parser: &Parser<'_>,