Rollup merge of #140228 - fmease:revert-overzealous-colon-recovery, r=jieyouxu
Revert overzealous parse recovery for single colons in paths Basically manually reverts #136808, cc ``@chenyukang`` ``@estebank.`` Reopens #129273. Fixes [after beta backport] #140227.
This commit is contained in:
@@ -2058,6 +2058,17 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
self.expect_field_ty_separator()?;
|
||||
let ty = self.parse_ty()?;
|
||||
if self.token == token::Colon && self.look_ahead(1, |&t| t != token::Colon) {
|
||||
self.dcx()
|
||||
.struct_span_err(self.token.span, "found single colon in a struct field type path")
|
||||
.with_span_suggestion_verbose(
|
||||
self.token.span,
|
||||
"write a path separator here",
|
||||
"::",
|
||||
Applicability::MaybeIncorrect,
|
||||
)
|
||||
.emit();
|
||||
}
|
||||
let default = if self.token == token::Eq {
|
||||
self.bump();
|
||||
let const_expr = self.parse_expr_anon_const()?;
|
||||
|
||||
@@ -248,19 +248,13 @@ impl<'a> Parser<'a> {
|
||||
segments.push(segment);
|
||||
|
||||
if self.is_import_coupler() || !self.eat_path_sep() {
|
||||
let ok_for_recovery = self.may_recover()
|
||||
&& match style {
|
||||
PathStyle::Expr => true,
|
||||
PathStyle::Type if let Some((ident, _)) = self.prev_token.ident() => {
|
||||
self.token == token::Colon
|
||||
&& ident.as_str().chars().all(|c| c.is_lowercase())
|
||||
&& self.token.span.lo() == self.prev_token.span.hi()
|
||||
&& self
|
||||
.look_ahead(1, |token| self.token.span.hi() == token.span.lo())
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
if ok_for_recovery
|
||||
// IMPORTANT: We can *only ever* treat single colons as typo'ed double colons in
|
||||
// expression contexts (!) since only there paths cannot possibly be followed by
|
||||
// a colon and still form a syntactically valid construct. In pattern contexts,
|
||||
// a path may be followed by a type annotation. E.g., `let pat:ty`. In type
|
||||
// contexts, a path may be followed by a list of bounds. E.g., `where ty:bound`.
|
||||
if self.may_recover()
|
||||
&& style == PathStyle::Expr // (!)
|
||||
&& self.token == token::Colon
|
||||
&& self.look_ahead(1, |token| token.is_ident() && !token.is_reserved_ident())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user