diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-06-20 07:52:45 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-20 07:52:45 +0200 |
| commit | c979535aa5455b4ad90ff7f3c671c2cd87a89805 (patch) | |
| tree | 293cb56fd5e21c6ab35d91714191469dd7d290d2 /compiler/rustc_parse/src/parser | |
| parent | af073e4e88629e70f4194fcd43b48a8c5b411029 (diff) | |
| parent | c6f78270b66b2ffc78742006445df76105b7d558 (diff) | |
| download | rust-c979535aa5455b4ad90ff7f3c671c2cd87a89805.tar.gz rust-c979535aa5455b4ad90ff7f3c671c2cd87a89805.zip | |
Rollup merge of #126708 - nnethercote:minimize-can_begin_literal_maybe_minus, r=compiler-errors
Minimize `can_begin_literal_maybe_minus` usage `can_begin_literal_maybe_minus` is used in a few confusing ways. This PR makes them clearer. r? ``@spastorino``
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/pat.rs | 3 |
2 files changed, 4 insertions, 3 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 2db777a9f70..3e1ea7b129d 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1259,7 +1259,7 @@ impl<'a> Parser<'a> { self.token.is_keyword(kw::Unsafe) && self.is_keyword_ahead(1, &[kw::Extern]) && self.look_ahead( - 2 + self.look_ahead(2, |t| t.can_begin_literal_maybe_minus() as usize), + 2 + self.look_ahead(2, |t| t.can_begin_string_literal() as usize), |t| t.kind == token::OpenDelim(Delimiter::Brace), ) } @@ -2448,7 +2448,7 @@ impl<'a> Parser<'a> { }) // `extern ABI fn` || self.check_keyword_case(kw::Extern, case) - && self.look_ahead(1, |t| t.can_begin_literal_maybe_minus()) + && self.look_ahead(1, |t| t.can_begin_string_literal()) && (self.look_ahead(2, |t| t.is_keyword_case(kw::Fn, case)) || // this branch is only for better diagnostic in later, `pub` is not allowed here (self.may_recover() diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 03aea0888d9..6f2b7177159 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -939,7 +939,8 @@ impl<'a> Parser<'a> { || self.look_ahead(dist, |t| { t.is_path_start() // e.g. `MY_CONST`; || t.kind == token::Dot // e.g. `.5` for recovery; - || t.can_begin_literal_maybe_minus() // e.g. `42`. + || matches!(t.kind, token::Literal(..) | token::BinOp(token::Minus)) + || t.is_bool_lit() || t.is_whole_expr() || t.is_lifetime() // recover `'a` instead of `'a'` || (self.may_recover() // recover leading `(` |
