From 45fb7232abc893a06272550ebcad7b39a3cb26c1 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sat, 1 Feb 2020 19:10:42 +0000 Subject: [PATCH] Move colon-check to recover_colon_before_qpath_proj() --- src/librustc_parse/parser/path.rs | 38 +++++++++++++++++++------------ 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/librustc_parse/parser/path.rs b/src/librustc_parse/parser/path.rs index a4541046c6c1..027380eaa2a6 100644 --- a/src/librustc_parse/parser/path.rs +++ b/src/librustc_parse/parser/path.rs @@ -71,21 +71,7 @@ impl<'a> Parser<'a> { debug!("parse_qpath: (decrement) count={:?}", self.unmatched_angle_bracket_count); } - if self.token.kind == token::Colon { - // >:Qux - // ^ - self.bump(); - - self.diagnostic() - .struct_span_err(self.prev_span, "found single colon where type path was expected") - .span_suggestion( - self.prev_span, - "use double colon", - "::".to_string(), - Applicability::MachineApplicable, - ) - .emit(); - } else { + if !self.recover_colon_before_qpath_proj() { self.expect(&token::ModSep)?; } @@ -95,6 +81,28 @@ impl<'a> Parser<'a> { Ok((qself, Path { segments: path.segments, span: lo.to(self.prev_span) })) } + fn recover_colon_before_qpath_proj(&mut self) -> bool { + if self.token.kind != token::Colon { + return false; + } + + // >:Qux + // ^ + self.bump(); + + self.diagnostic() + .struct_span_err(self.prev_span, "found single colon where type path was expected") + .span_suggestion( + self.prev_span, + "use double colon", + "::".to_string(), + Applicability::MachineApplicable, + ) + .emit(); + + true + } + /// Parses simple paths. /// /// `path = [::] segment+`