X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_parse%2Fsrc%2Fparser%2Fdiagnostics.rs;h=c609aa93da3a75b0d9cb50637ef85e18dce8bfe5;hb=2b9e099a83f558423909c11522c77eccb8b88e10;hp=887a4a6de33b1c3d7722763c63a7de85bf0c44b6;hpb=ec7ffdfbafefae52948176d67aa88119ee984f78;p=rust.git diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 887a4a6de33..c609aa93da3 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -769,6 +769,10 @@ pub(super) fn check_trailing_angle_brackets( segment: &PathSegment, end: &[&TokenKind], ) -> bool { + if !self.may_recover() { + return false; + } + // This function is intended to be invoked after parsing a path segment where there are two // cases: // @@ -863,6 +867,10 @@ pub(super) fn check_trailing_angle_brackets( /// Check if a method call with an intended turbofish has been written without surrounding /// angle brackets. pub(super) fn check_turbofish_missing_angle_brackets(&mut self, segment: &mut PathSegment) { + if !self.may_recover() { + return; + } + if token::ModSep == self.token.kind && segment.args.is_none() { let snapshot = self.create_snapshot_for_diagnostic(); self.bump(); @@ -1396,6 +1404,10 @@ pub(super) fn maybe_recover_from_bad_qpath( &mut self, base: P, ) -> PResult<'a, P> { + if !self.may_recover() { + return Ok(base); + } + // Do not add `::` to expected tokens. if self.token == token::ModSep { if let Some(ty) = base.to_ty() { @@ -2456,11 +2468,15 @@ pub(crate) fn maybe_recover_colon_colon_in_pat_typo( } pub(crate) fn maybe_recover_unexpected_block_label(&mut self) -> bool { - let Some(label) = self.eat_label().filter(|_| { - self.eat(&token::Colon) && self.token.kind == token::OpenDelim(Delimiter::Brace) - }) else { + // Check for `'a : {` + if !(self.check_lifetime() + && self.look_ahead(1, |tok| tok.kind == token::Colon) + && self.look_ahead(2, |tok| tok.kind == token::OpenDelim(Delimiter::Brace))) + { return false; - }; + } + let label = self.eat_label().expect("just checked if a label exists"); + self.bump(); // eat `:` let span = label.ident.span.to(self.prev_token.span); let mut err = self.struct_span_err(span, "block label not supported here"); err.span_label(span, "not supported here");