Skip to content

Commit 3d40897

Browse files
committed
Remove bra/ket naming.
This is a naming convention used in a handful of spots in the parser for delimiters. It confused me when I first saw it a long time ago, and I've never liked it. A web search says "Bra-ket notation" exists in linear algebra but the terminology has zero prior use in a programming context, as far as I can tell. This commit changes it to `open`/`close`, which is consistent with the rest of the compiler.
1 parent 533bdbc commit 3d40897

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1125,11 +1125,11 @@ impl<'a> Parser<'a> {
11251125
Ok(self.mk_expr_err(lo.to(self.token.span), guar))
11261126
}
11271127

1128-
/// Eats and discards tokens until one of `kets` is encountered. Respects token trees,
1128+
/// Eats and discards tokens until one of `closes` is encountered. Respects token trees,
11291129
/// passes through any errors encountered. Used for error recovery.
1130-
pub(super) fn eat_to_tokens(&mut self, kets: &[&TokenKind]) {
1131-
if let Err(err) =
1132-
self.parse_seq_to_before_tokens(kets, &[], SeqSep::none(), |p| Ok(p.parse_token_tree()))
1130+
pub(super) fn eat_to_tokens(&mut self, closes: &[&TokenKind]) {
1131+
if let Err(err) = self
1132+
.parse_seq_to_before_tokens(closes, &[], SeqSep::none(), |p| Ok(p.parse_token_tree()))
11331133
{
11341134
err.cancel();
11351135
}

compiler/rustc_parse/src/parser/mod.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -857,23 +857,23 @@ impl<'a> Parser<'a> {
857857
}
858858
}
859859

860-
/// Checks if the next token is contained within `kets`, and returns `true` if so.
860+
/// Checks if the next token is contained within `closes`, and returns `true` if so.
861861
fn expect_any_with_type(
862862
&mut self,
863-
kets_expected: &[&TokenKind],
864-
kets_not_expected: &[&TokenKind],
863+
closes_expected: &[&TokenKind],
864+
closes_not_expected: &[&TokenKind],
865865
) -> bool {
866-
kets_expected.iter().any(|k| self.check(k))
867-
|| kets_not_expected.iter().any(|k| self.check_noexpect(k))
866+
closes_expected.iter().any(|k| self.check(k))
867+
|| closes_not_expected.iter().any(|k| self.check_noexpect(k))
868868
}
869869

870870
/// Parses a sequence until the specified delimiters. The function
871871
/// `f` must consume tokens until reaching the next separator or
872872
/// closing bracket.
873873
fn parse_seq_to_before_tokens<T>(
874874
&mut self,
875-
kets_expected: &[&TokenKind],
876-
kets_not_expected: &[&TokenKind],
875+
closes_expected: &[&TokenKind],
876+
closes_not_expected: &[&TokenKind],
877877
sep: SeqSep,
878878
mut f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
879879
) -> PResult<'a, (ThinVec<T>, Trailing, Recovered)> {
@@ -882,7 +882,7 @@ impl<'a> Parser<'a> {
882882
let mut trailing = Trailing::No;
883883
let mut v = ThinVec::new();
884884

885-
while !self.expect_any_with_type(kets_expected, kets_not_expected) {
885+
while !self.expect_any_with_type(closes_expected, closes_not_expected) {
886886
if let token::CloseDelim(..) | token::Eof = self.token.kind {
887887
break;
888888
}
@@ -981,7 +981,7 @@ impl<'a> Parser<'a> {
981981
// we will try to recover in `maybe_recover_struct_lit_bad_delims`
982982
return Err(expect_err);
983983
} else if let [token::CloseDelim(Delimiter::Parenthesis)] =
984-
kets_expected
984+
closes_expected
985985
{
986986
return Err(expect_err);
987987
} else {
@@ -995,7 +995,7 @@ impl<'a> Parser<'a> {
995995
}
996996
}
997997
if sep.trailing_sep_allowed
998-
&& self.expect_any_with_type(kets_expected, kets_not_expected)
998+
&& self.expect_any_with_type(closes_expected, closes_not_expected)
999999
{
10001000
trailing = Trailing::Yes;
10011001
break;
@@ -1071,27 +1071,27 @@ impl<'a> Parser<'a> {
10711071
/// closing bracket.
10721072
fn parse_seq_to_before_end<T>(
10731073
&mut self,
1074-
ket: &TokenKind,
1074+
close: &TokenKind,
10751075
sep: SeqSep,
10761076
f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
10771077
) -> PResult<'a, (ThinVec<T>, Trailing, Recovered)> {
1078-
self.parse_seq_to_before_tokens(&[ket], &[], sep, f)
1078+
self.parse_seq_to_before_tokens(&[close], &[], sep, f)
10791079
}
10801080

10811081
/// Parses a sequence, including only the closing delimiter. The function
10821082
/// `f` must consume tokens until reaching the next separator or
10831083
/// closing bracket.
10841084
fn parse_seq_to_end<T>(
10851085
&mut self,
1086-
ket: &TokenKind,
1086+
close: &TokenKind,
10871087
sep: SeqSep,
10881088
f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
10891089
) -> PResult<'a, (ThinVec<T>, Trailing)> {
1090-
let (val, trailing, recovered) = self.parse_seq_to_before_end(ket, sep, f)?;
1091-
if matches!(recovered, Recovered::No) && !self.eat(ket) {
1090+
let (val, trailing, recovered) = self.parse_seq_to_before_end(close, sep, f)?;
1091+
if matches!(recovered, Recovered::No) && !self.eat(close) {
10921092
self.dcx().span_delayed_bug(
10931093
self.token.span,
1094-
"recovered but `parse_seq_to_before_end` did not give us the ket token",
1094+
"recovered but `parse_seq_to_before_end` did not give us the close token",
10951095
);
10961096
}
10971097
Ok((val, trailing))
@@ -1102,13 +1102,13 @@ impl<'a> Parser<'a> {
11021102
/// closing bracket.
11031103
fn parse_unspanned_seq<T>(
11041104
&mut self,
1105-
bra: &TokenKind,
1106-
ket: &TokenKind,
1105+
open: &TokenKind,
1106+
close: &TokenKind,
11071107
sep: SeqSep,
11081108
f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
11091109
) -> PResult<'a, (ThinVec<T>, Trailing)> {
1110-
self.expect(bra)?;
1111-
self.parse_seq_to_end(ket, sep, f)
1110+
self.expect(open)?;
1111+
self.parse_seq_to_end(close, sep, f)
11121112
}
11131113

11141114
/// Parses a comma-separated sequence, including both delimiters.

0 commit comments

Comments
 (0)