Skip to content

Commit d5370d9

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 fb5ba8a commit d5370d9

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
@@ -882,23 +882,23 @@ impl<'a> Parser<'a> {
882882
}
883883
}
884884

885-
/// Checks if the next token is contained within `kets`, and returns `true` if so.
885+
/// Checks if the next token is contained within `closes`, and returns `true` if so.
886886
fn expect_any_with_type(
887887
&mut self,
888-
kets_expected: &[&TokenKind],
889-
kets_not_expected: &[&TokenKind],
888+
closes_expected: &[&TokenKind],
889+
closes_not_expected: &[&TokenKind],
890890
) -> bool {
891-
kets_expected.iter().any(|k| self.check(k))
892-
|| kets_not_expected.iter().any(|k| self.check_noexpect(k))
891+
closes_expected.iter().any(|k| self.check(k))
892+
|| closes_not_expected.iter().any(|k| self.check_noexpect(k))
893893
}
894894

895895
/// Parses a sequence until the specified delimiters. The function
896896
/// `f` must consume tokens until reaching the next separator or
897897
/// closing bracket.
898898
fn parse_seq_to_before_tokens<T>(
899899
&mut self,
900-
kets_expected: &[&TokenKind],
901-
kets_not_expected: &[&TokenKind],
900+
closes_expected: &[&TokenKind],
901+
closes_not_expected: &[&TokenKind],
902902
sep: SeqSep,
903903
mut f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
904904
) -> PResult<'a, (ThinVec<T>, Trailing, Recovered)> {
@@ -907,7 +907,7 @@ impl<'a> Parser<'a> {
907907
let mut trailing = Trailing::No;
908908
let mut v = ThinVec::new();
909909

910-
while !self.expect_any_with_type(kets_expected, kets_not_expected) {
910+
while !self.expect_any_with_type(closes_expected, closes_not_expected) {
911911
if let token::CloseDelim(..) | token::Eof = self.token.kind {
912912
break;
913913
}
@@ -1006,7 +1006,7 @@ impl<'a> Parser<'a> {
10061006
// we will try to recover in `maybe_recover_struct_lit_bad_delims`
10071007
return Err(expect_err);
10081008
} else if let [token::CloseDelim(Delimiter::Parenthesis)] =
1009-
kets_expected
1009+
closes_expected
10101010
{
10111011
return Err(expect_err);
10121012
} else {
@@ -1020,7 +1020,7 @@ impl<'a> Parser<'a> {
10201020
}
10211021
}
10221022
if sep.trailing_sep_allowed
1023-
&& self.expect_any_with_type(kets_expected, kets_not_expected)
1023+
&& self.expect_any_with_type(closes_expected, closes_not_expected)
10241024
{
10251025
trailing = Trailing::Yes;
10261026
break;
@@ -1096,27 +1096,27 @@ impl<'a> Parser<'a> {
10961096
/// closing bracket.
10971097
fn parse_seq_to_before_end<T>(
10981098
&mut self,
1099-
ket: &TokenKind,
1099+
close: &TokenKind,
11001100
sep: SeqSep,
11011101
f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
11021102
) -> PResult<'a, (ThinVec<T>, Trailing, Recovered)> {
1103-
self.parse_seq_to_before_tokens(&[ket], &[], sep, f)
1103+
self.parse_seq_to_before_tokens(&[close], &[], sep, f)
11041104
}
11051105

11061106
/// Parses a sequence, including only the closing delimiter. The function
11071107
/// `f` must consume tokens until reaching the next separator or
11081108
/// closing bracket.
11091109
fn parse_seq_to_end<T>(
11101110
&mut self,
1111-
ket: &TokenKind,
1111+
close: &TokenKind,
11121112
sep: SeqSep,
11131113
f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
11141114
) -> PResult<'a, (ThinVec<T>, Trailing)> {
1115-
let (val, trailing, recovered) = self.parse_seq_to_before_end(ket, sep, f)?;
1116-
if matches!(recovered, Recovered::No) && !self.eat(ket) {
1115+
let (val, trailing, recovered) = self.parse_seq_to_before_end(close, sep, f)?;
1116+
if matches!(recovered, Recovered::No) && !self.eat(close) {
11171117
self.dcx().span_delayed_bug(
11181118
self.token.span,
1119-
"recovered but `parse_seq_to_before_end` did not give us the ket token",
1119+
"recovered but `parse_seq_to_before_end` did not give us the close token",
11201120
);
11211121
}
11221122
Ok((val, trailing))
@@ -1127,13 +1127,13 @@ impl<'a> Parser<'a> {
11271127
/// closing bracket.
11281128
fn parse_unspanned_seq<T>(
11291129
&mut self,
1130-
bra: &TokenKind,
1131-
ket: &TokenKind,
1130+
open: &TokenKind,
1131+
close: &TokenKind,
11321132
sep: SeqSep,
11331133
f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
11341134
) -> PResult<'a, (ThinVec<T>, Trailing)> {
1135-
self.expect(bra)?;
1136-
self.parse_seq_to_end(ket, sep, f)
1135+
self.expect(open)?;
1136+
self.parse_seq_to_end(close, sep, f)
11371137
}
11381138

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

0 commit comments

Comments
 (0)