diff options
| author | yukang <moorekang@gmail.com> | 2023-07-05 16:25:46 +0800 |
|---|---|---|
| committer | yukang <moorekang@gmail.com> | 2023-07-05 16:25:46 +0800 |
| commit | f25463e8483d8dcfb64cda4e96d5b4fbd11a19c8 (patch) | |
| tree | 85c89a023ace276cea7b768c742c87d353572c9d /compiler/rustc_parse | |
| parent | b7bc6f88ac771e1197ac9e06bf20586eeb5d0bdf (diff) | |
| download | rust-f25463e8483d8dcfb64cda4e96d5b4fbd11a19c8.tar.gz rust-f25463e8483d8dcfb64cda4e96d5b4fbd11a19c8.zip | |
Fix the issue of wrong diagnosis for extern pub fn
Diffstat (limited to 'compiler/rustc_parse')
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 3783ec41b7e..1470180dea7 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -2182,7 +2182,11 @@ 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(2, |t| t.is_keyword_case(kw::Fn, case)) + && (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() + && self.look_ahead(2, |t| t.is_keyword(kw::Pub)) + && self.look_ahead(3, |t| t.is_keyword_case(kw::Fn, case)))) } /// Parses all the "front matter" (or "qualifiers") for a `fn` declaration, |
