Skip to content

Commit 05c5df5

Browse files
refactor: use by-ref TokenTree iterator to avoid a few clones
1 parent 5b24e12 commit 05c5df5

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

compiler/rustc_builtin_macros/src/concat_idents.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub fn expand_concat_idents<'cx>(
1919
}
2020

2121
let mut res_str = String::new();
22-
for (i, e) in tts.into_trees().enumerate() {
22+
for (i, e) in tts.trees().enumerate() {
2323
if i & 1 == 1 {
2424
match e {
2525
TokenTree::Token(Token { kind: token::Comma, .. }, _) => {}

compiler/rustc_builtin_macros/src/trace_macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub fn expand_trace_macros(
88
sp: Span,
99
tt: TokenStream,
1010
) -> Box<dyn base::MacResult + 'static> {
11-
let mut cursor = tt.into_trees();
11+
let mut cursor = tt.trees();
1212
let mut err = false;
1313
let value = match &cursor.next() {
1414
Some(TokenTree::Token(token, _)) if token.is_keyword(kw::True) => true,

compiler/rustc_lint/src/builtin.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1882,8 +1882,8 @@ declare_lint_pass!(
18821882
struct UnderMacro(bool);
18831883

18841884
impl KeywordIdents {
1885-
fn check_tokens(&mut self, cx: &EarlyContext<'_>, tokens: TokenStream) {
1886-
for tt in tokens.into_trees() {
1885+
fn check_tokens(&mut self, cx: &EarlyContext<'_>, tokens: &TokenStream) {
1886+
for tt in tokens.trees() {
18871887
match tt {
18881888
// Only report non-raw idents.
18891889
TokenTree::Token(token, _) => {
@@ -1944,10 +1944,10 @@ impl KeywordIdents {
19441944

19451945
impl EarlyLintPass for KeywordIdents {
19461946
fn check_mac_def(&mut self, cx: &EarlyContext<'_>, mac_def: &ast::MacroDef) {
1947-
self.check_tokens(cx, mac_def.body.tokens.clone());
1947+
self.check_tokens(cx, &mac_def.body.tokens);
19481948
}
19491949
fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::MacCall) {
1950-
self.check_tokens(cx, mac.args.tokens.clone());
1950+
self.check_tokens(cx, &mac.args.tokens);
19511951
}
19521952
fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: Ident) {
19531953
self.check_ident_token(cx, UnderMacro(false), ident);

0 commit comments

Comments
 (0)