Skip to content

Commit 3d40966

Browse files
chenyukangfmease
andcommitted
Update compiler/rustc_parse/src/parser/path.rs
Co-authored-by: León Orell Valerian Liehr <[email protected]>
1 parent 57ceeb3 commit 3d40966

File tree

2 files changed

+14
-26
lines changed

2 files changed

+14
-26
lines changed

compiler/rustc_parse/src/parser/path.rs

+12-17
Original file line numberDiff line numberDiff line change
@@ -246,23 +246,18 @@ impl<'a> Parser<'a> {
246246
segments.push(segment);
247247

248248
if self.is_import_coupler() || !self.eat_path_sep() {
249-
let ok_for_recovery = match style {
250-
PathStyle::Expr => self.may_recover(),
251-
PathStyle::Type => {
252-
self.may_recover()
253-
&& if let Some((ident, _)) = self.prev_token.ident() {
254-
ident.as_str().chars().all(|c| c.is_lowercase())
255-
&& self.token == token::Colon
256-
&& self.token.span.lo() == self.prev_token.span.hi()
257-
&& self.look_ahead(1, |token| {
258-
self.token.span.hi() == token.span.lo()
259-
})
260-
} else {
261-
false
262-
}
263-
}
264-
_ => false,
265-
};
249+
let ok_for_recovery = self.may_recover()
250+
&& match style {
251+
PathStyle::Expr => true,
252+
PathStyle::Type if let Some((ident, _)) = self.prev_token.ident() => {
253+
self.token == token::Colon
254+
&& ident.as_str().chars().all(|c| c.is_lowercase())
255+
&& self.token.span.lo() == self.prev_token.span.hi()
256+
&& self
257+
.look_ahead(1, |token| self.token.span.hi() == token.span.lo())
258+
}
259+
_ => false,
260+
};
266261
if ok_for_recovery
267262
&& self.token == token::Colon
268263
&& self.look_ahead(1, |token| token.is_ident() && !token.is_reserved_ident())

tests/ui/suggestions/struct-field-type-including-single-colon.stderr

+2-9
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ LL | a: foo:A,
77
= note: if you meant to annotate an expression with a type, the type ascription syntax has been removed, see issue #101728 <https://github.com/rust-lang/rust/issues/101728>
88
help: use a double colon instead
99
|
10-
LL - a: foo:A,
11-
LL + a: foo::A,
12-
|
10+
LL | a: foo::A,
11+
| +
1312

1413
error: path separator must be a double colon
1514
--> $DIR/struct-field-type-including-single-colon.rs:15:16
@@ -20,14 +19,8 @@ LL | b: foo::bar:B,
2019
= note: if you meant to annotate an expression with a type, the type ascription syntax has been removed, see issue #101728 <https://github.com/rust-lang/rust/issues/101728>
2120
help: use a double colon instead
2221
|
23-
<<<<<<< HEAD
24-
LL - b: foo::bar:B,
25-
LL + b: foo::bar::B,
26-
|
27-
=======
2822
LL | b: foo::bar::B,
2923
| +
30-
>>>>>>> 949333b7f9a (Try to recover from path sep error in parser)
3124

3225
error[E0603]: struct `A` is private
3326
--> $DIR/struct-field-type-including-single-colon.rs:9:12

0 commit comments

Comments
 (0)