1
Fork 0

Improve wording and docs for qualified path recovery

This commit is contained in:
Rob Pilling 2020-02-01 19:21:54 +00:00
parent 45fb7232ab
commit 991d2ee282
4 changed files with 14 additions and 7 deletions

View file

@ -81,17 +81,24 @@ impl<'a> Parser<'a> {
Ok((qself, Path { segments: path.segments, span: lo.to(self.prev_span) }))
}
/// Recover from an invalid single colon, when the user likely meant a qualified path.
///
/// ```ignore (diagnostics)
/// <Bar as Baz<T>>:Qux
/// ^ help: use double colon
/// ```
fn recover_colon_before_qpath_proj(&mut self) -> bool {
if self.token.kind != token::Colon {
return false;
}
// <Bar as Baz<T>>:Qux
// ^
self.bump();
self.bump(); // colon
self.diagnostic()
.struct_span_err(self.prev_span, "found single colon where type path was expected")
.struct_span_err(
self.prev_span,
"found single colon before projection in qualified path",
)
.span_suggestion(
self.prev_span,
"use double colon",

View file

@ -15,5 +15,5 @@ fn template<T>() -> i64 {
fn main() {
template::<<Impl as T>::Ty>();
//~^ ERROR found single colon where type path was expected
//~^ ERROR found single colon before projection in qualified path
}

View file

@ -15,5 +15,5 @@ fn template<T>() -> i64 {
fn main() {
template::<<Impl as T>:Ty>();
//~^ ERROR found single colon where type path was expected
//~^ ERROR found single colon before projection in qualified path
}

View file

@ -1,4 +1,4 @@
error: found single colon where type path was expected
error: found single colon before projection in qualified path
--> $DIR/qualified-path-in-turbofish.rs:17:27
|
LL | template::<<Impl as T>:Ty>();