Skip to content

Commit 45fb723

Browse files
committed
Move colon-check to recover_colon_before_qpath_proj()
1 parent 88d64a0 commit 45fb723

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

src/librustc_parse/parser/path.rs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,7 @@ impl<'a> Parser<'a> {
7171
debug!("parse_qpath: (decrement) count={:?}", self.unmatched_angle_bracket_count);
7272
}
7373

74-
if self.token.kind == token::Colon {
75-
// <Bar as Baz<T>>:Qux
76-
// ^
77-
self.bump();
78-
79-
self.diagnostic()
80-
.struct_span_err(self.prev_span, "found single colon where type path was expected")
81-
.span_suggestion(
82-
self.prev_span,
83-
"use double colon",
84-
"::".to_string(),
85-
Applicability::MachineApplicable,
86-
)
87-
.emit();
88-
} else {
74+
if !self.recover_colon_before_qpath_proj() {
8975
self.expect(&token::ModSep)?;
9076
}
9177

@@ -95,6 +81,28 @@ impl<'a> Parser<'a> {
9581
Ok((qself, Path { segments: path.segments, span: lo.to(self.prev_span) }))
9682
}
9783

84+
fn recover_colon_before_qpath_proj(&mut self) -> bool {
85+
if self.token.kind != token::Colon {
86+
return false;
87+
}
88+
89+
// <Bar as Baz<T>>:Qux
90+
// ^
91+
self.bump();
92+
93+
self.diagnostic()
94+
.struct_span_err(self.prev_span, "found single colon where type path was expected")
95+
.span_suggestion(
96+
self.prev_span,
97+
"use double colon",
98+
"::".to_string(),
99+
Applicability::MachineApplicable,
100+
)
101+
.emit();
102+
103+
true
104+
}
105+
98106
/// Parses simple paths.
99107
///
100108
/// `path = [::] segment+`

0 commit comments

Comments
 (0)