Make inline const work for half open ranges
This commit is contained in:
parent
f8842b9bac
commit
83abed9df6
4 changed files with 19 additions and 9 deletions
|
@ -1062,7 +1062,7 @@ impl<'a> Parser<'a> {
|
||||||
})
|
})
|
||||||
} else if self.eat_keyword(kw::Unsafe) {
|
} else if self.eat_keyword(kw::Unsafe) {
|
||||||
self.parse_block_expr(None, lo, BlockCheckMode::Unsafe(ast::UserProvided), attrs)
|
self.parse_block_expr(None, lo, BlockCheckMode::Unsafe(ast::UserProvided), attrs)
|
||||||
} else if self.check_inline_const() {
|
} else if self.check_inline_const(0) {
|
||||||
self.parse_const_block(lo.to(self.token.span))
|
self.parse_const_block(lo.to(self.token.span))
|
||||||
} else if self.is_do_catch_block() {
|
} else if self.is_do_catch_block() {
|
||||||
self.recover_do_catch(attrs)
|
self.recover_do_catch(attrs)
|
||||||
|
|
|
@ -522,9 +522,9 @@ impl<'a> Parser<'a> {
|
||||||
self.check_or_expected(self.token.can_begin_const_arg(), TokenType::Const)
|
self.check_or_expected(self.token.can_begin_const_arg(), TokenType::Const)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_inline_const(&mut self) -> bool {
|
fn check_inline_const(&self, dist: usize) -> bool {
|
||||||
self.check_keyword(kw::Const)
|
self.is_keyword_ahead(dist, &[kw::Const])
|
||||||
&& self.look_ahead(1, |t| match t.kind {
|
&& self.look_ahead(dist + 1, |t| match t.kind {
|
||||||
token::Interpolated(ref nt) => matches!(**nt, token::NtBlock(..)),
|
token::Interpolated(ref nt) => matches!(**nt, token::NtBlock(..)),
|
||||||
token::OpenDelim(DelimToken::Brace) => true,
|
token::OpenDelim(DelimToken::Brace) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
|
|
|
@ -313,7 +313,7 @@ impl<'a> Parser<'a> {
|
||||||
let pat = self.parse_pat_with_range_pat(false, None)?;
|
let pat = self.parse_pat_with_range_pat(false, None)?;
|
||||||
self.sess.gated_spans.gate(sym::box_patterns, lo.to(self.prev_token.span));
|
self.sess.gated_spans.gate(sym::box_patterns, lo.to(self.prev_token.span));
|
||||||
PatKind::Box(pat)
|
PatKind::Box(pat)
|
||||||
} else if self.check_inline_const() {
|
} else if self.check_inline_const(0) {
|
||||||
// Parse `const pat`
|
// Parse `const pat`
|
||||||
let const_expr = self.parse_const_block(lo.to(self.token.span))?;
|
let const_expr = self.parse_const_block(lo.to(self.token.span))?;
|
||||||
|
|
||||||
|
@ -722,8 +722,8 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Is the token `dist` away from the current suitable as the start of a range patterns end?
|
/// Is the token `dist` away from the current suitable as the start of a range patterns end?
|
||||||
fn is_pat_range_end_start(&mut self, dist: usize) -> bool {
|
fn is_pat_range_end_start(&self, dist: usize) -> bool {
|
||||||
self.check_inline_const()
|
self.check_inline_const(dist)
|
||||||
|| self.look_ahead(dist, |t| {
|
|| self.look_ahead(dist, |t| {
|
||||||
t.is_path_start() // e.g. `MY_CONST`;
|
t.is_path_start() // e.g. `MY_CONST`;
|
||||||
|| t.kind == token::Dot // e.g. `.5` for recovery;
|
|| t.kind == token::Dot // e.g. `.5` for recovery;
|
||||||
|
@ -733,7 +733,7 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_pat_range_end(&mut self) -> PResult<'a, P<Expr>> {
|
fn parse_pat_range_end(&mut self) -> PResult<'a, P<Expr>> {
|
||||||
if self.check_inline_const() {
|
if self.check_inline_const(0) {
|
||||||
self.parse_const_block(self.token.span)
|
self.parse_const_block(self.token.span)
|
||||||
} else if self.check_path() {
|
} else if self.check_path() {
|
||||||
let lo = self.token.span;
|
let lo = self.token.span;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// build-pass
|
// build-pass
|
||||||
|
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
#![feature(inline_const)]
|
#![feature(inline_const, half_open_range_patterns, exclusive_range_pattern)]
|
||||||
fn main() {
|
fn main() {
|
||||||
const N: u32 = 10;
|
const N: u32 = 10;
|
||||||
let x: u32 = 3;
|
let x: u32 = 3;
|
||||||
|
@ -20,4 +20,14 @@ fn main() {
|
||||||
1 ..= const { N + 1 } => {},
|
1 ..= const { N + 1 } => {},
|
||||||
_ => {},
|
_ => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
match x {
|
||||||
|
.. const { N + 1 } => {},
|
||||||
|
_ => {},
|
||||||
|
}
|
||||||
|
|
||||||
|
match x {
|
||||||
|
const { N - 1 } .. => {},
|
||||||
|
_ => {},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue