Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 6e56900

Browse files
committed
Impl Copy for Token and TokenKind.
1 parent 44a6662 commit 6e56900

File tree

19 files changed

+57
-58
lines changed

19 files changed

+57
-58
lines changed

compiler/rustc_ast/src/token.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ impl From<IdentIsRaw> for bool {
345345
}
346346
}
347347

348-
#[derive(Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
348+
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
349349
pub enum TokenKind {
350350
/* Expression-operator symbols. */
351351
/// `=`
@@ -443,7 +443,7 @@ pub enum TokenKind {
443443
Eof,
444444
}
445445

446-
#[derive(Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
446+
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
447447
pub struct Token {
448448
pub kind: TokenKind,
449449
pub span: Span,

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ impl TokenStream {
465465
Delimiter::Invisible(InvisibleOrigin::FlattenToken),
466466
TokenStream::token_alone(token::Lifetime(ident.name, is_raw), ident.span),
467467
),
468-
_ => TokenTree::Token(token.clone(), spacing),
468+
_ => TokenTree::Token(*token, spacing),
469469
}
470470
}
471471

compiler/rustc_expand/src/mbe/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl<'dcx, 'matcher> Tracker<'matcher> for CollectTrackerAndEmitter<'dcx, 'match
161161
.map_or(true, |failure| failure.is_better_position(*approx_position))
162162
{
163163
self.best_failure = Some(BestFailure {
164-
token: token.clone(),
164+
token: *token,
165165
position_in_tokenstream: *approx_position,
166166
msg,
167167
remaining_matcher: self

compiler/rustc_expand/src/mbe/macro_parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ pub(super) fn compute_locs(matcher: &[TokenTree]) -> Vec<MatcherLoc> {
180180
for tt in tts {
181181
match tt {
182182
TokenTree::Token(token) => {
183-
locs.push(MatcherLoc::Token { token: token.clone() });
183+
locs.push(MatcherLoc::Token { token: *token });
184184
}
185185
TokenTree::Delimited(span, _, delimited) => {
186186
let open_token = Token::new(token::OpenDelim(delimited.delim), span.open);
@@ -649,7 +649,7 @@ impl TtParser {
649649
// There are no possible next positions AND we aren't waiting for the black-box
650650
// parser: syntax error.
651651
return Failure(T::build_failure(
652-
parser.token.clone(),
652+
parser.token,
653653
parser.approx_token_stream_pos(),
654654
"no rules expected this token in macro call",
655655
));

compiler/rustc_expand/src/mbe/macro_rules.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ impl<'tt> FirstSets<'tt> {
796796
// token could be the separator token itself.
797797

798798
if let (Some(sep), true) = (&seq_rep.separator, subfirst.maybe_empty) {
799-
first.add_one_maybe(TtHandle::from_token(sep.clone()));
799+
first.add_one_maybe(TtHandle::from_token(*sep));
800800
}
801801

802802
// Reverse scan: Sequence comes before `first`.
@@ -859,7 +859,7 @@ impl<'tt> FirstSets<'tt> {
859859
// If the sequence contents can be empty, then the first
860860
// token could be the separator token itself.
861861
if let (Some(sep), true) = (&seq_rep.separator, subfirst.maybe_empty) {
862-
first.add_one_maybe(TtHandle::from_token(sep.clone()));
862+
first.add_one_maybe(TtHandle::from_token(*sep));
863863
}
864864

865865
assert!(first.maybe_empty);
@@ -935,7 +935,7 @@ impl<'tt> Clone for TtHandle<'tt> {
935935
// This variant *must* contain a `mbe::TokenTree::Token`, and not
936936
// any other variant of `mbe::TokenTree`.
937937
TtHandle::Token(mbe::TokenTree::Token(tok)) => {
938-
TtHandle::Token(mbe::TokenTree::Token(tok.clone()))
938+
TtHandle::Token(mbe::TokenTree::Token(*tok))
939939
}
940940

941941
_ => unreachable!(),
@@ -1111,7 +1111,7 @@ fn check_matcher_core<'tt>(
11111111
let mut new;
11121112
let my_suffix = if let Some(sep) = &seq_rep.separator {
11131113
new = suffix_first.clone();
1114-
new.add_one_maybe(TtHandle::from_token(sep.clone()));
1114+
new.add_one_maybe(TtHandle::from_token(*sep));
11151115
&new
11161116
} else {
11171117
&suffix_first

compiler/rustc_expand/src/mbe/quoted.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ fn parse_tree<'a>(
312312
}
313313

314314
// `tree` is an arbitrary token. Keep it.
315-
tokenstream::TokenTree::Token(token, _) => TokenTree::Token(token.clone()),
315+
tokenstream::TokenTree::Token(token, _) => TokenTree::Token(*token),
316316

317317
// `tree` is the beginning of a delimited set of tokens (e.g., `(` or `{`). We need to
318318
// descend into the delimited set and further parse it.
@@ -350,7 +350,7 @@ fn parse_kleene_op<'a>(
350350
match input.next() {
351351
Some(tokenstream::TokenTree::Token(token, _)) => match kleene_op(token) {
352352
Some(op) => Ok(Ok((op, token.span))),
353-
None => Ok(Err(token.clone())),
353+
None => Ok(Err(*token)),
354354
},
355355
tree => Err(tree.map_or(span, tokenstream::TokenTree::span)),
356356
}

compiler/rustc_expand/src/mbe/transcribe.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ pub(super) fn transcribe<'a>(
163163
if repeat_idx < repeat_len {
164164
frame.idx = 0;
165165
if let Some(sep) = sep {
166-
result.push(TokenTree::Token(sep.clone(), Spacing::Alone));
166+
result.push(TokenTree::Token(*sep, Spacing::Alone));
167167
}
168168
continue;
169169
}
@@ -404,7 +404,7 @@ pub(super) fn transcribe<'a>(
404404
// Nothing much to do here. Just push the token to the result, being careful to
405405
// preserve syntax context.
406406
mbe::TokenTree::Token(token) => {
407-
let mut token = token.clone();
407+
let mut token = *token;
408408
mut_visit::visit_token(&mut marker, &mut token);
409409
let tt = TokenTree::Token(token, Spacing::Alone);
410410
result.push(tt);

compiler/rustc_parse/src/lexer/unicode_chars.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ pub(super) fn check_for_substitution(
377377
ascii_name,
378378
})
379379
};
380-
(token.clone(), sugg)
380+
(*token, sugg)
381381
}
382382

383383
/// Extract string if found at current position with given delimiters

compiler/rustc_parse/src/parser/attr_wrapper.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl ToAttrTokenStream for LazyAttrTokenStreamImpl {
120120
// produce an empty `TokenStream` if no calls were made, and omit the
121121
// final token otherwise.
122122
let mut cursor_snapshot = self.cursor_snapshot.clone();
123-
let tokens = iter::once(FlatToken::Token(self.start_token.clone()))
123+
let tokens = iter::once(FlatToken::Token(self.start_token))
124124
.chain(iter::repeat_with(|| FlatToken::Token(cursor_snapshot.next())))
125125
.take(self.num_calls as usize);
126126

@@ -173,7 +173,7 @@ impl ToAttrTokenStream for LazyAttrTokenStreamImpl {
173173
impl<'a> Parser<'a> {
174174
pub(super) fn collect_pos(&self) -> CollectPos {
175175
CollectPos {
176-
start_token: (self.token.clone(), self.token_spacing),
176+
start_token: (self.token, self.token_spacing),
177177
cursor_snapshot: self.token_cursor.clone(),
178178
start_pos: self.num_bump_calls,
179179
}

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ impl<'a> Parser<'a> {
320320
let mut recovered_ident = None;
321321
// we take this here so that the correct original token is retained in
322322
// the diagnostic, regardless of eager recovery.
323-
let bad_token = self.token.clone();
323+
let bad_token = self.token;
324324

325325
// suggest prepending a keyword in identifier position with `r#`
326326
let suggest_raw = if let Some((ident, IdentIsRaw::No)) = self.token.ident()
@@ -380,7 +380,7 @@ impl<'a> Parser<'a> {
380380
// if the previous token is a valid keyword
381381
// that might use a generic, then suggest a correct
382382
// generic placement (later on)
383-
let maybe_keyword = self.prev_token.clone();
383+
let maybe_keyword = self.prev_token;
384384
if valid_prev_keywords.into_iter().any(|x| maybe_keyword.is_keyword(x)) {
385385
// if we have a valid keyword, attempt to parse generics
386386
// also obtain the keywords symbol
@@ -496,7 +496,7 @@ impl<'a> Parser<'a> {
496496
false
497497
}
498498

499-
if **token != parser::TokenType::Token(self.token.kind.clone()) {
499+
if **token != parser::TokenType::Token(self.token.kind) {
500500
let eq = is_ident_eq_keyword(&self.token.kind, &token);
501501
// If the suggestion is a keyword and the found token is an ident,
502502
// the content of which are equal to the suggestion's content,
@@ -560,7 +560,7 @@ impl<'a> Parser<'a> {
560560
// let y = 42;
561561
let guar = self.dcx().emit_err(ExpectedSemi {
562562
span: self.token.span,
563-
token: self.token.clone(),
563+
token: self.token,
564564
unexpected_token_label: None,
565565
sugg: ExpectedSemiSugg::ChangeToSemi(self.token.span),
566566
});
@@ -585,7 +585,7 @@ impl<'a> Parser<'a> {
585585
let span = self.prev_token.span.shrink_to_hi();
586586
let guar = self.dcx().emit_err(ExpectedSemi {
587587
span,
588-
token: self.token.clone(),
588+
token: self.token,
589589
unexpected_token_label: Some(self.token.span),
590590
sugg: ExpectedSemiSugg::AddSemi(span),
591591
});
@@ -827,7 +827,7 @@ impl<'a> Parser<'a> {
827827
let span = self.prev_token.span.shrink_to_hi();
828828
let mut err = self.dcx().create_err(ExpectedSemi {
829829
span,
830-
token: self.token.clone(),
830+
token: self.token,
831831
unexpected_token_label: Some(self.token.span),
832832
sugg: ExpectedSemiSugg::AddSemi(span),
833833
});

0 commit comments

Comments
 (0)