Skip to content

Commit 4b98900

Browse files
committed
CONST LOOPS ARE HERE
1 parent 6f6580d commit 4b98900

File tree

8 files changed

+38
-29
lines changed

8 files changed

+38
-29
lines changed

crates/parser/src/grammar/expressions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ fn expr_bp(p: &mut Parser, mut r: Restrictions, bp: u8) -> (Option<CompletedMark
316316
}
317317

318318
const LHS_FIRST: TokenSet =
319-
atom::ATOM_EXPR_FIRST.union(token_set![T![&], T![*], T![!], T![.], T![-]]);
319+
atom::ATOM_EXPR_FIRST.union(TokenSet::new(&[T![&], T![*], T![!], T![.], T![-]]));
320320

321321
fn lhs(p: &mut Parser, r: Restrictions) -> Option<(CompletedMarker, BlockLike)> {
322322
let m;

crates/parser/src/grammar/expressions/atom.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use super::*;
1515
// let _ = b"e";
1616
// let _ = br"f";
1717
// }
18-
pub(crate) const LITERAL_FIRST: TokenSet = token_set![
18+
pub(crate) const LITERAL_FIRST: TokenSet = TokenSet::new(&[
1919
TRUE_KW,
2020
FALSE_KW,
2121
INT_NUMBER,
@@ -25,8 +25,8 @@ pub(crate) const LITERAL_FIRST: TokenSet = token_set![
2525
STRING,
2626
RAW_STRING,
2727
BYTE_STRING,
28-
RAW_BYTE_STRING
29-
];
28+
RAW_BYTE_STRING,
29+
]);
3030

3131
pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> {
3232
if !p.at_ts(LITERAL_FIRST) {
@@ -39,7 +39,7 @@ pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> {
3939

4040
// E.g. for after the break in `if break {}`, this should not match
4141
pub(super) const ATOM_EXPR_FIRST: TokenSet =
42-
LITERAL_FIRST.union(paths::PATH_FIRST).union(token_set![
42+
LITERAL_FIRST.union(paths::PATH_FIRST).union(TokenSet::new(&[
4343
T!['('],
4444
T!['{'],
4545
T!['['],
@@ -59,9 +59,9 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet =
5959
T![loop],
6060
T![for],
6161
LIFETIME,
62-
]);
62+
]));
6363

64-
const EXPR_RECOVERY_SET: TokenSet = token_set![LET_KW, R_DOLLAR];
64+
const EXPR_RECOVERY_SET: TokenSet = TokenSet::new(&[LET_KW, R_DOLLAR]);
6565

6666
pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMarker, BlockLike)> {
6767
if let Some(m) = literal(p) {

crates/parser/src/grammar/items.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) {
2626
}
2727
}
2828

29-
pub(super) const ITEM_RECOVERY_SET: TokenSet = token_set![
29+
pub(super) const ITEM_RECOVERY_SET: TokenSet = TokenSet::new(&[
3030
FN_KW,
3131
STRUCT_KW,
3232
ENUM_KW,
@@ -41,7 +41,7 @@ pub(super) const ITEM_RECOVERY_SET: TokenSet = token_set![
4141
USE_KW,
4242
MACRO_KW,
4343
T![;],
44-
];
44+
]);
4545

4646
pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool) {
4747
let m = p.start();

crates/parser/src/grammar/paths.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use super::*;
44

55
pub(super) const PATH_FIRST: TokenSet =
6-
token_set![IDENT, T![self], T![super], T![crate], T![:], T![<]];
6+
TokenSet::new(&[IDENT, T![self], T![super], T![crate], T![:], T![<]]);
77

88
pub(super) fn is_path_start(p: &Parser) -> bool {
99
is_use_path_start(p) || p.at(T![<])

crates/parser/src/grammar/patterns.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@
22
33
use super::*;
44

5-
pub(super) const PATTERN_FIRST: TokenSet = expressions::LITERAL_FIRST
6-
.union(paths::PATH_FIRST)
7-
.union(token_set![T![box], T![ref], T![mut], T!['('], T!['['], T![&], T![_], T![-], T![.]]);
5+
pub(super) const PATTERN_FIRST: TokenSet =
6+
expressions::LITERAL_FIRST.union(paths::PATH_FIRST).union(TokenSet::new(&[
7+
T![box],
8+
T![ref],
9+
T![mut],
10+
T!['('],
11+
T!['['],
12+
T![&],
13+
T![_],
14+
T![-],
15+
T![.],
16+
]));
817

918
pub(crate) fn pattern(p: &mut Parser) {
1019
pattern_r(p, PAT_RECOVERY_SET);
@@ -74,7 +83,7 @@ fn pattern_single_r(p: &mut Parser, recovery_set: TokenSet) {
7483
}
7584

7685
const PAT_RECOVERY_SET: TokenSet =
77-
token_set![LET_KW, IF_KW, WHILE_KW, LOOP_KW, MATCH_KW, R_PAREN, COMMA];
86+
TokenSet::new(&[LET_KW, IF_KW, WHILE_KW, LOOP_KW, MATCH_KW, R_PAREN, COMMA]);
7887

7988
fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
8089
let m = match p.nth(0) {

crates/parser/src/grammar/types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use super::*;
44

5-
pub(super) const TYPE_FIRST: TokenSet = paths::PATH_FIRST.union(token_set![
5+
pub(super) const TYPE_FIRST: TokenSet = paths::PATH_FIRST.union(TokenSet::new(&[
66
T!['('],
77
T!['['],
88
T![<],
@@ -16,16 +16,16 @@ pub(super) const TYPE_FIRST: TokenSet = paths::PATH_FIRST.union(token_set![
1616
T![for],
1717
T![impl],
1818
T![dyn],
19-
]);
19+
]));
2020

21-
const TYPE_RECOVERY_SET: TokenSet = token_set![
21+
const TYPE_RECOVERY_SET: TokenSet = TokenSet::new(&[
2222
T![')'],
2323
T![,],
2424
L_DOLLAR,
2525
// test_err struct_field_recover
2626
// struct S { f pub g: () }
2727
T![pub],
28-
];
28+
]);
2929

3030
pub(crate) fn type_(p: &mut Parser) {
3131
type_with_bounds_cond(p, true);

crates/parser/src/token_set.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,21 @@ pub(crate) struct TokenSet(u128);
99
impl TokenSet {
1010
pub(crate) const EMPTY: TokenSet = TokenSet(0);
1111

12-
pub(crate) const fn singleton(kind: SyntaxKind) -> TokenSet {
13-
TokenSet(mask(kind))
12+
pub(crate) const fn new(kinds: &[SyntaxKind]) -> TokenSet {
13+
let mut res = 0u128;
14+
let mut i = 0;
15+
while i < kinds.len() {
16+
res |= mask(kinds[i]);
17+
i += 1
18+
}
19+
TokenSet(res)
1420
}
1521

1622
pub(crate) const fn union(self, other: TokenSet) -> TokenSet {
1723
TokenSet(self.0 | other.0)
1824
}
1925

20-
pub(crate) fn contains(&self, kind: SyntaxKind) -> bool {
26+
pub(crate) const fn contains(&self, kind: SyntaxKind) -> bool {
2127
self.0 & mask(kind) != 0
2228
}
2329
}
@@ -26,16 +32,10 @@ const fn mask(kind: SyntaxKind) -> u128 {
2632
1u128 << (kind as usize)
2733
}
2834

29-
#[macro_export]
30-
macro_rules! token_set {
31-
($($t:expr),*) => { TokenSet::EMPTY$(.union(TokenSet::singleton($t)))* };
32-
($($t:expr),* ,) => { token_set!($($t),*) };
33-
}
34-
3535
#[test]
3636
fn token_set_works_for_tokens() {
3737
use crate::SyntaxKind::*;
38-
let ts = token_set![EOF, SHEBANG];
38+
let ts = TokenSet::new(&[EOF, SHEBANG]);
3939
assert!(ts.contains(EOF));
4040
assert!(ts.contains(SHEBANG));
4141
assert!(!ts.contains(PLUS));

xtask/src/install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use anyhow::{bail, format_err, Context, Result};
77
use crate::not_bash::{pushd, run};
88

99
// Latest stable, feel free to send a PR if this lags behind.
10-
const REQUIRED_RUST_VERSION: u32 = 43;
10+
const REQUIRED_RUST_VERSION: u32 = 46;
1111

1212
pub struct InstallCmd {
1313
pub client: Option<ClientOpt>,

0 commit comments

Comments
 (0)