diff options
| author | Michael Goulet <michael@errs.io> | 2023-02-03 14:15:22 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-03 14:15:22 -0800 |
| commit | e99e05d13592d2e9868fa69f98dc01f9766f05ed (patch) | |
| tree | faa84e1df772ee6c48b73321bf6ba08931a456ef /compiler/rustc_parse/src/parser/mod.rs | |
| parent | beb5cc9cf79b782094bb75fe41df3b7bdbb05bd7 (diff) | |
| parent | b886a4de157873c6a3e536a517fd6b097a4ab11b (diff) | |
| download | rust-e99e05d13592d2e9868fa69f98dc01f9766f05ed.tar.gz rust-e99e05d13592d2e9868fa69f98dc01f9766f05ed.zip | |
Rollup merge of #107551 - fee1-dead-contrib:rm_const_fnmut_helper, r=oli-obk
Replace `ConstFnMutClosure` with const closures Also fixes a parser bug. cc `@oli-obk` for compiler changes
Diffstat (limited to 'compiler/rustc_parse/src/parser/mod.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/mod.rs | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 2ea55f838a3..0cb88f3c3a9 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -732,9 +732,10 @@ impl<'a> Parser<'a> { fn check_const_closure(&self) -> bool { self.is_keyword_ahead(0, &[kw::Const]) && self.look_ahead(1, |t| match &t.kind { - token::Ident(kw::Move | kw::Static | kw::Async, _) - | token::OrOr - | token::BinOp(token::Or) => true, + // async closures do not work with const closures, so we do not parse that here. + token::Ident(kw::Move | kw::Static, _) | token::OrOr | token::BinOp(token::Or) => { + true + } _ => false, }) } @@ -1198,8 +1199,18 @@ impl<'a> Parser<'a> { /// Parses constness: `const` or nothing. fn parse_constness(&mut self, case: Case) -> Const { - // Avoid const blocks to be parsed as const items - if self.look_ahead(1, |t| t != &token::OpenDelim(Delimiter::Brace)) + self.parse_constness_(case, false) + } + + /// Parses constness for closures + fn parse_closure_constness(&mut self, case: Case) -> Const { + self.parse_constness_(case, true) + } + + fn parse_constness_(&mut self, case: Case, is_closure: bool) -> Const { + // Avoid const blocks and const closures to be parsed as const items + if (self.check_const_closure() == is_closure) + && self.look_ahead(1, |t| t != &token::OpenDelim(Delimiter::Brace)) && self.eat_keyword_case(kw::Const, case) { Const::Yes(self.prev_token.uninterpolated_span()) |
