diff options
| author | yukang <moorekang@gmail.com> | 2025-02-11 15:26:21 +0800 |
|---|---|---|
| committer | yukang <moorekang@gmail.com> | 2025-02-15 07:44:20 +0800 |
| commit | 0aa2e6b606fdca2c0166b6033e3ea0cb8484eeb7 (patch) | |
| tree | 6ed192cab064e2d9acaaefa9cb5431fc7fca6e87 /compiler/rustc_parse/src/parser/path.rs | |
| parent | d8810e3e2dab96778d20dd6d746ff95465515509 (diff) | |
| download | rust-0aa2e6b606fdca2c0166b6033e3ea0cb8484eeb7.tar.gz rust-0aa2e6b606fdca2c0166b6033e3ea0cb8484eeb7.zip | |
Try to recover from path sep error in parser
Diffstat (limited to 'compiler/rustc_parse/src/parser/path.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/path.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index 576711e6677..b241aa892db 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -246,8 +246,19 @@ impl<'a> Parser<'a> { segments.push(segment); if self.is_import_coupler() || !self.eat_path_sep() { - if style == PathStyle::Expr - && self.may_recover() + 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 && self.token == token::Colon && self.look_ahead(1, |token| token.is_ident() && !token.is_reserved_ident()) { |
