Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggest path separator for single-colon typos #68681

Merged
merged 5 commits into from
Feb 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/librustc_parse/parser/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,23 @@ impl<'a> Parser<'a> {
debug!("parse_qpath: (decrement) count={:?}", self.unmatched_angle_bracket_count);
}

self.expect(&token::ModSep)?;
let lo_colon = self.token.span;
bobrippling marked this conversation as resolved.
Show resolved Hide resolved
if self.eat(&token::Colon) {
bobrippling marked this conversation as resolved.
Show resolved Hide resolved
// <Bar as Baz<T>>:Qux
// ^
let span = lo_colon.to(self.prev_span);
self.diagnostic()
.struct_span_err(span, "found single colon where type path was expected")
bobrippling marked this conversation as resolved.
Show resolved Hide resolved
.span_suggestion(
span,
"use double colon",
"::".to_string(),
Applicability::MachineApplicable,
)
.emit();
} else {
bobrippling marked this conversation as resolved.
Show resolved Hide resolved
self.expect(&token::ModSep)?;
}

let qself = QSelf { ty, path_span, position: path.segments.len() };
self.parse_path_segments(&mut path.segments, style)?;
Expand Down
19 changes: 19 additions & 0 deletions src/test/ui/parser/qualified-path-in-turbofish.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// run-rustfix
trait T {
type Ty;
}

struct Impl;

impl T for Impl {
type Ty = u32;
}

fn template<T>() -> i64 {
3
}

fn main() {
template::<<Impl as T>::Ty>();
//~^ ERROR found single colon where type path was expected
}
19 changes: 19 additions & 0 deletions src/test/ui/parser/qualified-path-in-turbofish.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// run-rustfix
trait T {
type Ty;
}

struct Impl;

impl T for Impl {
type Ty = u32;
}

fn template<T>() -> i64 {
3
}

fn main() {
template::<<Impl as T>:Ty>();
//~^ ERROR found single colon where type path was expected
}
8 changes: 8 additions & 0 deletions src/test/ui/parser/qualified-path-in-turbofish.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: found single colon where type path was expected
--> $DIR/qualified-path-in-turbofish.rs:17:27
|
LL | template::<<Impl as T>:Ty>();
| ^ help: use double colon: `::`

error: aborting due to previous error