Skip to content

Commit b96152e

Browse files
Auto merge of #145830 - nnethercote:TokenKind-unref, r=<try>
Remove the lifetime from `ExpTokenPair`/`SeqSep`.
2 parents 809200e + a06c388 commit b96152e

File tree

5 files changed

+49
-49
lines changed

5 files changed

+49
-49
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,8 @@ impl<'a> Parser<'a> {
463463

464464
pub(super) fn expected_one_of_not_found(
465465
&mut self,
466-
edible: &[ExpTokenPair<'_>],
467-
inedible: &[ExpTokenPair<'_>],
466+
edible: &[ExpTokenPair],
467+
inedible: &[ExpTokenPair],
468468
) -> PResult<'a, ErrorGuaranteed> {
469469
debug!("expected_one_of_not_found(edible: {:?}, inedible: {:?})", edible, inedible);
470470
fn tokens_to_string(tokens: &[TokenType]) -> String {
@@ -1092,7 +1092,7 @@ impl<'a> Parser<'a> {
10921092

10931093
/// Eats and discards tokens until one of `closes` is encountered. Respects token trees,
10941094
/// passes through any errors encountered. Used for error recovery.
1095-
pub(super) fn eat_to_tokens(&mut self, closes: &[ExpTokenPair<'_>]) {
1095+
pub(super) fn eat_to_tokens(&mut self, closes: &[ExpTokenPair]) {
10961096
if let Err(err) = self
10971097
.parse_seq_to_before_tokens(closes, &[], SeqSep::none(), |p| Ok(p.parse_token_tree()))
10981098
{
@@ -1113,7 +1113,7 @@ impl<'a> Parser<'a> {
11131113
pub(super) fn check_trailing_angle_brackets(
11141114
&mut self,
11151115
segment: &PathSegment,
1116-
end: &[ExpTokenPair<'_>],
1116+
end: &[ExpTokenPair],
11171117
) -> Option<ErrorGuaranteed> {
11181118
if !self.may_recover() {
11191119
return None;
@@ -1196,7 +1196,7 @@ impl<'a> Parser<'a> {
11961196
// second case.
11971197
if self.look_ahead(position, |t| {
11981198
trace!("check_trailing_angle_brackets: t={:?}", t);
1199-
end.iter().any(|exp| exp.tok == &t.kind)
1199+
end.iter().any(|exp| exp.tok == t.kind)
12001200
}) {
12011201
// Eat from where we started until the end token so that parsing can continue
12021202
// as if we didn't have those extra angle brackets.
@@ -2120,8 +2120,8 @@ impl<'a> Parser<'a> {
21202120

21212121
pub(super) fn recover_seq_parse_error(
21222122
&mut self,
2123-
open: ExpTokenPair<'_>,
2124-
close: ExpTokenPair<'_>,
2123+
open: ExpTokenPair,
2124+
close: ExpTokenPair,
21252125
lo: Span,
21262126
err: Diag<'a>,
21272127
) -> Box<Expr> {
@@ -2386,8 +2386,8 @@ impl<'a> Parser<'a> {
23862386

23872387
pub(super) fn consume_block(
23882388
&mut self,
2389-
open: ExpTokenPair<'_>,
2390-
close: ExpTokenPair<'_>,
2389+
open: ExpTokenPair,
2390+
close: ExpTokenPair,
23912391
consume_close: ConsumeClosingDelim,
23922392
) {
23932393
let mut brace_depth = 0;

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,7 @@ impl<'a> Parser<'a> {
15981598
self.maybe_recover_from_bad_qpath(expr)
15991599
}
16001600

1601-
fn parse_expr_array_or_repeat(&mut self, close: ExpTokenPair<'_>) -> PResult<'a, Box<Expr>> {
1601+
fn parse_expr_array_or_repeat(&mut self, close: ExpTokenPair) -> PResult<'a, Box<Expr>> {
16021602
let lo = self.token.span;
16031603
self.bump(); // `[` or other open delim
16041604

@@ -3661,7 +3661,7 @@ impl<'a> Parser<'a> {
36613661
&mut self,
36623662
pth: ast::Path,
36633663
recover: bool,
3664-
close: ExpTokenPair<'_>,
3664+
close: ExpTokenPair,
36653665
) -> PResult<
36663666
'a,
36673667
(
@@ -3680,8 +3680,8 @@ impl<'a> Parser<'a> {
36803680
errors::HelpUseLatestEdition::new().add_to_diag(e);
36813681
};
36823682

3683-
while self.token != *close.tok {
3684-
if self.eat(exp!(DotDot)) || self.recover_struct_field_dots(close.tok) {
3683+
while self.token != close.tok {
3684+
if self.eat(exp!(DotDot)) || self.recover_struct_field_dots(&close.tok) {
36853685
let exp_span = self.prev_token.span;
36863686
// We permit `.. }` on the left-hand side of a destructuring assignment.
36873687
if self.check(close) {

compiler/rustc_parse/src/parser/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl<'a> Parser<'a> {
5454
/// - `}` for mod items
5555
pub fn parse_mod(
5656
&mut self,
57-
term: ExpTokenPair<'_>,
57+
term: ExpTokenPair,
5858
) -> PResult<'a, (AttrVec, ThinVec<Box<Item>>, ModSpans)> {
5959
let lo = self.token.span;
6060
let attrs = self.parse_inner_attributes()?;
@@ -1201,7 +1201,7 @@ impl<'a> Parser<'a> {
12011201
}?;
12021202

12031203
let dash = exp!(Minus);
1204-
if self.token != *dash.tok {
1204+
if self.token != dash.tok {
12051205
return Ok(ident);
12061206
}
12071207

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -261,19 +261,19 @@ struct CaptureState {
261261

262262
/// A sequence separator.
263263
#[derive(Debug)]
264-
struct SeqSep<'a> {
264+
struct SeqSep {
265265
/// The separator token.
266-
sep: Option<ExpTokenPair<'a>>,
266+
sep: Option<ExpTokenPair>,
267267
/// `true` if a trailing separator is allowed.
268268
trailing_sep_allowed: bool,
269269
}
270270

271-
impl<'a> SeqSep<'a> {
272-
fn trailing_allowed(sep: ExpTokenPair<'a>) -> SeqSep<'a> {
271+
impl SeqSep {
272+
fn trailing_allowed(sep: ExpTokenPair) -> SeqSep {
273273
SeqSep { sep: Some(sep), trailing_sep_allowed: true }
274274
}
275275

276-
fn none() -> SeqSep<'a> {
276+
fn none() -> SeqSep {
277277
SeqSep { sep: None, trailing_sep_allowed: false }
278278
}
279279
}
@@ -425,13 +425,13 @@ impl<'a> Parser<'a> {
425425
}
426426

427427
/// Expects and consumes the token `t`. Signals an error if the next token is not `t`.
428-
pub fn expect(&mut self, exp: ExpTokenPair<'_>) -> PResult<'a, Recovered> {
428+
pub fn expect(&mut self, exp: ExpTokenPair) -> PResult<'a, Recovered> {
429429
if self.expected_token_types.is_empty() {
430-
if self.token == *exp.tok {
430+
if self.token == exp.tok {
431431
self.bump();
432432
Ok(Recovered::No)
433433
} else {
434-
self.unexpected_try_recover(exp.tok)
434+
self.unexpected_try_recover(&exp.tok)
435435
}
436436
} else {
437437
self.expect_one_of(slice::from_ref(&exp), &[])
@@ -443,13 +443,13 @@ impl<'a> Parser<'a> {
443443
/// anything. Signal a fatal error if next token is unexpected.
444444
fn expect_one_of(
445445
&mut self,
446-
edible: &[ExpTokenPair<'_>],
447-
inedible: &[ExpTokenPair<'_>],
446+
edible: &[ExpTokenPair],
447+
inedible: &[ExpTokenPair],
448448
) -> PResult<'a, Recovered> {
449-
if edible.iter().any(|exp| exp.tok == &self.token.kind) {
449+
if edible.iter().any(|exp| exp.tok == self.token.kind) {
450450
self.bump();
451451
Ok(Recovered::No)
452-
} else if inedible.iter().any(|exp| exp.tok == &self.token.kind) {
452+
} else if inedible.iter().any(|exp| exp.tok == self.token.kind) {
453453
// leave it in the input
454454
Ok(Recovered::No)
455455
} else if self.token != token::Eof
@@ -494,8 +494,8 @@ impl<'a> Parser<'a> {
494494
/// This method will automatically add `tok` to `expected_token_types` if `tok` is not
495495
/// encountered.
496496
#[inline]
497-
pub fn check(&mut self, exp: ExpTokenPair<'_>) -> bool {
498-
let is_present = self.token == *exp.tok;
497+
pub fn check(&mut self, exp: ExpTokenPair) -> bool {
498+
let is_present = self.token == exp.tok;
499499
if !is_present {
500500
self.expected_token_types.insert(exp.token_type);
501501
}
@@ -542,7 +542,7 @@ impl<'a> Parser<'a> {
542542
/// Consumes a token 'tok' if it exists. Returns whether the given token was present.
543543
#[inline]
544544
#[must_use]
545-
pub fn eat(&mut self, exp: ExpTokenPair<'_>) -> bool {
545+
pub fn eat(&mut self, exp: ExpTokenPair) -> bool {
546546
let is_present = self.check(exp);
547547
if is_present {
548548
self.bump()
@@ -745,13 +745,13 @@ impl<'a> Parser<'a> {
745745
/// Eats the expected token if it's present possibly breaking
746746
/// compound tokens like multi-character operators in process.
747747
/// Returns `true` if the token was eaten.
748-
fn break_and_eat(&mut self, exp: ExpTokenPair<'_>) -> bool {
749-
if self.token == *exp.tok {
748+
fn break_and_eat(&mut self, exp: ExpTokenPair) -> bool {
749+
if self.token == exp.tok {
750750
self.bump();
751751
return true;
752752
}
753753
match self.token.kind.break_two_token_op(1) {
754-
Some((first, second)) if first == *exp.tok => {
754+
Some((first, second)) if first == exp.tok => {
755755
let first_span = self.psess.source_map().start_point(self.token.span);
756756
let second_span = self.token.span.with_lo(first_span.hi());
757757
self.token = Token::new(first, first_span);
@@ -826,7 +826,7 @@ impl<'a> Parser<'a> {
826826
/// Checks if the next token is contained within `closes`, and returns `true` if so.
827827
fn expect_any_with_type(
828828
&mut self,
829-
closes_expected: &[ExpTokenPair<'_>],
829+
closes_expected: &[ExpTokenPair],
830830
closes_not_expected: &[&TokenKind],
831831
) -> bool {
832832
closes_expected.iter().any(|&close| self.check(close))
@@ -838,9 +838,9 @@ impl<'a> Parser<'a> {
838838
/// closing bracket.
839839
fn parse_seq_to_before_tokens<T>(
840840
&mut self,
841-
closes_expected: &[ExpTokenPair<'_>],
841+
closes_expected: &[ExpTokenPair],
842842
closes_not_expected: &[&TokenKind],
843-
sep: SeqSep<'_>,
843+
sep: SeqSep,
844844
mut f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
845845
) -> PResult<'a, (ThinVec<T>, Trailing, Recovered)> {
846846
let mut first = true;
@@ -869,7 +869,7 @@ impl<'a> Parser<'a> {
869869
}
870870
Err(mut expect_err) => {
871871
let sp = self.prev_token.span.shrink_to_hi();
872-
let token_str = pprust::token_kind_to_string(exp.tok);
872+
let token_str = pprust::token_kind_to_string(&exp.tok);
873873

874874
match self.current_closure.take() {
875875
Some(closure_spans) if self.token == TokenKind::Semi => {
@@ -1039,8 +1039,8 @@ impl<'a> Parser<'a> {
10391039
/// closing bracket.
10401040
fn parse_seq_to_before_end<T>(
10411041
&mut self,
1042-
close: ExpTokenPair<'_>,
1043-
sep: SeqSep<'_>,
1042+
close: ExpTokenPair,
1043+
sep: SeqSep,
10441044
f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
10451045
) -> PResult<'a, (ThinVec<T>, Trailing, Recovered)> {
10461046
self.parse_seq_to_before_tokens(&[close], &[], sep, f)
@@ -1051,8 +1051,8 @@ impl<'a> Parser<'a> {
10511051
/// closing bracket.
10521052
fn parse_seq_to_end<T>(
10531053
&mut self,
1054-
close: ExpTokenPair<'_>,
1055-
sep: SeqSep<'_>,
1054+
close: ExpTokenPair,
1055+
sep: SeqSep,
10561056
f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
10571057
) -> PResult<'a, (ThinVec<T>, Trailing)> {
10581058
let (val, trailing, recovered) = self.parse_seq_to_before_end(close, sep, f)?;
@@ -1070,9 +1070,9 @@ impl<'a> Parser<'a> {
10701070
/// closing bracket.
10711071
fn parse_unspanned_seq<T>(
10721072
&mut self,
1073-
open: ExpTokenPair<'_>,
1074-
close: ExpTokenPair<'_>,
1075-
sep: SeqSep<'_>,
1073+
open: ExpTokenPair,
1074+
close: ExpTokenPair,
1075+
sep: SeqSep,
10761076
f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
10771077
) -> PResult<'a, (ThinVec<T>, Trailing)> {
10781078
self.expect(open)?;
@@ -1084,8 +1084,8 @@ impl<'a> Parser<'a> {
10841084
/// closing bracket.
10851085
fn parse_delim_comma_seq<T>(
10861086
&mut self,
1087-
open: ExpTokenPair<'_>,
1088-
close: ExpTokenPair<'_>,
1087+
open: ExpTokenPair,
1088+
close: ExpTokenPair,
10891089
f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
10901090
) -> PResult<'a, (ThinVec<T>, Trailing)> {
10911091
self.parse_unspanned_seq(open, close, SeqSep::trailing_allowed(exp!(Comma)), f)

compiler/rustc_parse/src/parser/token_type.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,8 @@ impl TokenType {
416416
/// is always by used those methods. The second field is only used when the
417417
/// first field doesn't match.
418418
#[derive(Clone, Copy, Debug)]
419-
pub struct ExpTokenPair<'a> {
420-
pub tok: &'a TokenKind,
419+
pub struct ExpTokenPair {
420+
pub tok: TokenKind,
421421
pub token_type: TokenType,
422422
}
423423

@@ -444,7 +444,7 @@ macro_rules! exp {
444444
// `ExpTokenPair` helper rules.
445445
(@tok, $tok:ident) => {
446446
$crate::parser::token_type::ExpTokenPair {
447-
tok: &rustc_ast::token::$tok,
447+
tok: rustc_ast::token::$tok,
448448
token_type: $crate::parser::token_type::TokenType::$tok
449449
}
450450
};

0 commit comments

Comments
 (0)