diff options
| author | Rob Pilling <robpilling@gmail.com> | 2020-01-29 20:34:28 +0000 |
|---|---|---|
| committer | Rob Pilling <robpilling@gmail.com> | 2020-01-30 22:41:07 +0000 |
| commit | 3c91bdca1d552055e2b92ecac5275c1ebe9a4ee8 (patch) | |
| tree | b7040d4271515c92ffb98f23c45098d2e01ee2b3 /src/librustc_parse/parser | |
| parent | 212b2c7da87f3086af535b33a9ca6b5242f2d5a7 (diff) | |
| download | rust-3c91bdca1d552055e2b92ecac5275c1ebe9a4ee8.tar.gz rust-3c91bdca1d552055e2b92ecac5275c1ebe9a4ee8.zip | |
Suggest path separator for single-colon typos
This commit adds guidance for when a user means to type a path, but ends up typing a single colon, such as `<<Impl as T>:Ty>`. This change seemed pertinent as the current error message is particularly misleading, emitting `error: unmatched angle bracket`, despite the angle bracket being matched later on, leaving the user to track down the typo'd colon.
Diffstat (limited to 'src/librustc_parse/parser')
| -rw-r--r-- | src/librustc_parse/parser/path.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/librustc_parse/parser/path.rs b/src/librustc_parse/parser/path.rs index 0358458c099..25ba571a6a4 100644 --- a/src/librustc_parse/parser/path.rs +++ b/src/librustc_parse/parser/path.rs @@ -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; + if self.eat(&token::Colon) { + // <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") + .span_suggestion( + span, + "use double colon", + "::".to_string(), + Applicability::MachineApplicable, + ) + .emit(); + } else { + self.expect(&token::ModSep)?; + } let qself = QSelf { ty, path_span, position: path.segments.len() }; self.parse_path_segments(&mut path.segments, style)?; |
