diff options
| author | bors <bors@rust-lang.org> | 2020-10-23 09:31:44 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-10-23 09:31:44 +0000 |
| commit | 07a63e6d1fabf3560e8e1e17c1d56b10a06152d9 (patch) | |
| tree | 12243a35e4aa227ca4b935b9448a90a68ecf30d9 /compiler/rustc_parse/src | |
| parent | a9cd294cf2775441e713c7ee2918b728733b99f5 (diff) | |
| parent | b5d2ff0fd873ff2ee21d900fa455772f06600c6d (diff) | |
| download | rust-07a63e6d1fabf3560e8e1e17c1d56b10a06152d9.tar.gz rust-07a63e6d1fabf3560e8e1e17c1d56b10a06152d9.zip | |
Auto merge of #78270 - JohnTitor:rollup-bldrjh5, r=JohnTitor
Rollup of 17 pull requests Successful merges: - #77268 (Link to "Contributing to Rust" rather than "Getting Started".) - #77339 (Implement TryFrom between NonZero types.) - #77488 (Mark `repr128` as `incomplete_features`) - #77890 (Fixing escaping to ensure generation of welformed json.) - #77918 (Cleanup network tests) - #77920 (Avoid extraneous space between visibility kw and ident for statics) - #77969 (Doc formating consistency between slice sort and sort_unstable, and big O notation consistency) - #78098 (Clean up and improve some docs) - #78116 (Make inline const work in range patterns) - #78153 (Sync LLVM submodule if it has been initialized) - #78163 (Clean up lib docs) - #78169 (Update cargo) - #78231 (Make closures inherit the parent function's target features) - #78235 (Explain where the closure return type was inferred) - #78255 (Reduce diagram mess in 'match arms have incompatible types' error) - #78263 (Add regression test of issue-77668) - #78265 (Add some inference-related regression tests about incorrect diagnostics) Failed merges: r? `@ghost`
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/mod.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/pat.rs | 21 |
3 files changed, 21 insertions, 12 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 698a7e7d9cd..78c95428c72 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1062,8 +1062,8 @@ impl<'a> Parser<'a> { }) } else if self.eat_keyword(kw::Unsafe) { self.parse_block_expr(None, lo, BlockCheckMode::Unsafe(ast::UserProvided), attrs) - } else if self.check_inline_const() { - self.parse_const_expr(lo.to(self.token.span)) + } else if self.check_inline_const(0) { + self.parse_const_block(lo.to(self.token.span)) } else if self.is_do_catch_block() { self.recover_do_catch(attrs) } else if self.is_try_block() { diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index fb825256d92..8ff97453c14 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -522,9 +522,9 @@ impl<'a> Parser<'a> { self.check_or_expected(self.token.can_begin_const_arg(), TokenType::Const) } - fn check_inline_const(&mut self) -> bool { - self.check_keyword(kw::Const) - && self.look_ahead(1, |t| match t.kind { + fn check_inline_const(&self, dist: usize) -> bool { + self.is_keyword_ahead(dist, &[kw::Const]) + && self.look_ahead(dist + 1, |t| match t.kind { token::Interpolated(ref nt) => matches!(**nt, token::NtBlock(..)), token::OpenDelim(DelimToken::Brace) => true, _ => false, @@ -864,7 +864,7 @@ impl<'a> Parser<'a> { } /// Parses inline const expressions. - fn parse_const_expr(&mut self, span: Span) -> PResult<'a, P<Expr>> { + fn parse_const_block(&mut self, span: Span) -> PResult<'a, P<Expr>> { self.sess.gated_spans.gate(sym::inline_const, span); self.eat_keyword(kw::Const); let blk = self.parse_block()?; diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 15db2066a30..27fe75a23b6 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -313,9 +313,15 @@ impl<'a> Parser<'a> { let pat = self.parse_pat_with_range_pat(false, None)?; self.sess.gated_spans.gate(sym::box_patterns, lo.to(self.prev_token.span)); PatKind::Box(pat) - } else if self.check_inline_const() { + } else if self.check_inline_const(0) { // Parse `const pat` - PatKind::Lit(self.parse_const_expr(lo.to(self.token.span))?) + let const_expr = self.parse_const_block(lo.to(self.token.span))?; + + if let Some(re) = self.parse_range_end() { + self.parse_pat_range_begin_with(const_expr, re)? + } else { + PatKind::Lit(const_expr) + } } else if self.can_be_ident_pat() { // Parse `ident @ pat` // This can give false positives and parse nullary enums, @@ -717,16 +723,19 @@ impl<'a> Parser<'a> { /// Is the token `dist` away from the current suitable as the start of a range patterns end? fn is_pat_range_end_start(&self, dist: usize) -> bool { - self.look_ahead(dist, |t| { - t.is_path_start() // e.g. `MY_CONST`; + self.check_inline_const(dist) + || 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`. || t.is_whole_expr() - }) + }) } fn parse_pat_range_end(&mut self) -> PResult<'a, P<Expr>> { - if self.check_path() { + if self.check_inline_const(0) { + self.parse_const_block(self.token.span) + } else if self.check_path() { let lo = self.token.span; let (qself, path) = if self.eat_lt() { // Parse a qualified path |
