Skip to content

Commit 991d2ee

Browse files
committed
Improve wording and docs for qualified path recovery
1 parent 45fb723 commit 991d2ee

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

src/librustc_parse/parser/path.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,24 @@ impl<'a> Parser<'a> {
8181
Ok((qself, Path { segments: path.segments, span: lo.to(self.prev_span) }))
8282
}
8383

84+
/// Recover from an invalid single colon, when the user likely meant a qualified path.
85+
///
86+
/// ```ignore (diagnostics)
87+
/// <Bar as Baz<T>>:Qux
88+
/// ^ help: use double colon
89+
/// ```
8490
fn recover_colon_before_qpath_proj(&mut self) -> bool {
8591
if self.token.kind != token::Colon {
8692
return false;
8793
}
8894

89-
// <Bar as Baz<T>>:Qux
90-
// ^
91-
self.bump();
95+
self.bump(); // colon
9296

9397
self.diagnostic()
94-
.struct_span_err(self.prev_span, "found single colon where type path was expected")
98+
.struct_span_err(
99+
self.prev_span,
100+
"found single colon before projection in qualified path",
101+
)
95102
.span_suggestion(
96103
self.prev_span,
97104
"use double colon",

src/test/ui/parser/qualified-path-in-turbofish.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ fn template<T>() -> i64 {
1515

1616
fn main() {
1717
template::<<Impl as T>::Ty>();
18-
//~^ ERROR found single colon where type path was expected
18+
//~^ ERROR found single colon before projection in qualified path
1919
}

src/test/ui/parser/qualified-path-in-turbofish.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ fn template<T>() -> i64 {
1515

1616
fn main() {
1717
template::<<Impl as T>:Ty>();
18-
//~^ ERROR found single colon where type path was expected
18+
//~^ ERROR found single colon before projection in qualified path
1919
}

src/test/ui/parser/qualified-path-in-turbofish.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: found single colon where type path was expected
1+
error: found single colon before projection in qualified path
22
--> $DIR/qualified-path-in-turbofish.rs:17:27
33
|
44
LL | template::<<Impl as T>:Ty>();

0 commit comments

Comments
 (0)