Skip to content

Commit f84bc79

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 cdfd69d commit f84bc79

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 4 additions & 4 deletions
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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -856,23 +856,23 @@ impl<'a> Parser<'a> {
856856
}
857857
}
858858

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

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

884-
while !self.expect_any_with_type(kets_expected, kets_not_expected) {
884+
while !self.expect_any_with_type(closes_expected, closes_not_expected) {
885885
if let token::CloseDelim(..) | token::Eof = self.token.kind {
886886
break;
887887
}
@@ -980,7 +980,7 @@ impl<'a> Parser<'a> {
980980
// we will try to recover in `maybe_recover_struct_lit_bad_delims`
981981
return Err(expect_err);
982982
} else if let [token::CloseDelim(Delimiter::Parenthesis)] =
983-
kets_expected
983+
closes_expected
984984
{
985985
return Err(expect_err);
986986
} else {
@@ -994,7 +994,7 @@ impl<'a> Parser<'a> {
994994
}
995995
}
996996
if sep.trailing_sep_allowed
997-
&& self.expect_any_with_type(kets_expected, kets_not_expected)
997+
&& self.expect_any_with_type(closes_expected, closes_not_expected)
998998
{
999999
trailing = Trailing::Yes;
10001000
break;
@@ -1070,27 +1070,27 @@ impl<'a> Parser<'a> {
10701070
/// closing bracket.
10711071
fn parse_seq_to_before_end<T>(
10721072
&mut self,
1073-
ket: &TokenKind,
1073+
close: &TokenKind,
10741074
sep: SeqSep,
10751075
f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
10761076
) -> PResult<'a, (ThinVec<T>, Trailing, Recovered)> {
1077-
self.parse_seq_to_before_tokens(&[ket], &[], sep, f)
1077+
self.parse_seq_to_before_tokens(&[close], &[], sep, f)
10781078
}
10791079

10801080
/// Parses a sequence, including only the closing delimiter. The function
10811081
/// `f` must consume tokens until reaching the next separator or
10821082
/// closing bracket.
10831083
fn parse_seq_to_end<T>(
10841084
&mut self,
1085-
ket: &TokenKind,
1085+
close: &TokenKind,
10861086
sep: SeqSep,
10871087
f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
10881088
) -> PResult<'a, (ThinVec<T>, Trailing)> {
1089-
let (val, trailing, recovered) = self.parse_seq_to_before_end(ket, sep, f)?;
1090-
if matches!(recovered, Recovered::No) && !self.eat(ket) {
1089+
let (val, trailing, recovered) = self.parse_seq_to_before_end(close, sep, f)?;
1090+
if matches!(recovered, Recovered::No) && !self.eat(close) {
10911091
self.dcx().span_delayed_bug(
10921092
self.token.span,
1093-
"recovered but `parse_seq_to_before_end` did not give us the ket token",
1093+
"recovered but `parse_seq_to_before_end` did not give us the close token",
10941094
);
10951095
}
10961096
Ok((val, trailing))
@@ -1101,13 +1101,13 @@ impl<'a> Parser<'a> {
11011101
/// closing bracket.
11021102
fn parse_unspanned_seq<T>(
11031103
&mut self,
1104-
bra: &TokenKind,
1105-
ket: &TokenKind,
1104+
open: &TokenKind,
1105+
close: &TokenKind,
11061106
sep: SeqSep,
11071107
f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
11081108
) -> PResult<'a, (ThinVec<T>, Trailing)> {
1109-
self.expect(bra)?;
1110-
self.parse_seq_to_end(ket, sep, f)
1109+
self.expect(open)?;
1110+
self.parse_seq_to_end(close, sep, f)
11111111
}
11121112

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

0 commit comments

Comments
 (0)