diff options
| author | bors <bors@rust-lang.org> | 2024-07-27 06:32:36 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-07-27 06:32:36 +0000 |
| commit | a6796c10a1e84b83d2f3c1eea8ea71c995290deb (patch) | |
| tree | 2e3af61e9cf97e5c33567d517ba2f5d53a1d2e64 /compiler/rustc_parse/src/parser/item.rs | |
| parent | adbb89e238640c3d3279ef3efb86c7bf46295858 (diff) | |
| parent | 822286f0758bea84b798e494b5b6103d288a3221 (diff) | |
| download | rust-a6796c10a1e84b83d2f3c1eea8ea71c995290deb.tar.gz rust-a6796c10a1e84b83d2f3c1eea8ea71c995290deb.zip | |
Auto merge of #3768 - rust-lang:rustup-2024-07-27, r=RalfJung
Automatic Rustup
Diffstat (limited to 'compiler/rustc_parse/src/parser/item.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 9aaf4b99243..112855e6d1f 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -2483,12 +2483,15 @@ impl<'a> Parser<'a> { /// `check_pub` adds additional `pub` to the checks in case users place it /// wrongly, can be used to ensure `pub` never comes after `default`. pub(super) fn check_fn_front_matter(&mut self, check_pub: bool, case: Case) -> bool { + const ALL_QUALS: &[Symbol] = + &[kw::Pub, kw::Gen, kw::Const, kw::Async, kw::Unsafe, kw::Safe, kw::Extern]; + // We use an over-approximation here. // `const const`, `fn const` won't parse, but we're not stepping over other syntax either. // `pub` is added in case users got confused with the ordering like `async pub fn`, // only if it wasn't preceded by `default` as `default pub` is invalid. let quals: &[Symbol] = if check_pub { - &[kw::Pub, kw::Gen, kw::Const, kw::Async, kw::Unsafe, kw::Safe, kw::Extern] + ALL_QUALS } else { &[kw::Gen, kw::Const, kw::Async, kw::Unsafe, kw::Safe, kw::Extern] }; @@ -2518,9 +2521,9 @@ impl<'a> Parser<'a> { || self.check_keyword_case(kw::Extern, case) && 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 + // this branch is only for better diagnostics; `pub`, `unsafe`, etc. are not allowed here (self.may_recover() - && self.look_ahead(2, |t| t.is_keyword(kw::Pub)) + && self.look_ahead(2, |t| ALL_QUALS.iter().any(|&kw| t.is_keyword(kw))) && self.look_ahead(3, |t| t.is_keyword_case(kw::Fn, case)))) } |
