From af3d75ad2e760dc885f54e6179543718ef8f141f Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Tue, 5 Jan 2021 00:22:42 +0800 Subject: Refactor TokenBuffer for reduc cloning --- crates/hir_expand/src/proc_macro.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/hir_expand/src/proc_macro.rs') diff --git a/crates/hir_expand/src/proc_macro.rs b/crates/hir_expand/src/proc_macro.rs index 7c77f6ce0..1923daca5 100644 --- a/crates/hir_expand/src/proc_macro.rs +++ b/crates/hir_expand/src/proc_macro.rs @@ -58,7 +58,7 @@ impl ProcMacroExpander { } fn eat_punct(cursor: &mut Cursor, c: char) -> bool { - if let Some(tt::TokenTree::Leaf(tt::Leaf::Punct(punct))) = cursor.token_tree() { + if let Some(tt::buffer::TokenTreeRef::Leaf(tt::Leaf::Punct(punct), _)) = cursor.token_tree() { if punct.char == c { *cursor = cursor.bump(); return true; @@ -68,7 +68,7 @@ fn eat_punct(cursor: &mut Cursor, c: char) -> bool { } fn eat_subtree(cursor: &mut Cursor, kind: tt::DelimiterKind) -> bool { - if let Some(tt::TokenTree::Subtree(subtree)) = cursor.token_tree() { + if let Some(tt::buffer::TokenTreeRef::Subtree(subtree, _)) = cursor.token_tree() { if Some(kind) == subtree.delimiter_kind() { *cursor = cursor.bump_subtree(); return true; @@ -78,7 +78,7 @@ fn eat_subtree(cursor: &mut Cursor, kind: tt::DelimiterKind) -> bool { } fn eat_ident(cursor: &mut Cursor, t: &str) -> bool { - if let Some(tt::TokenTree::Leaf(tt::Leaf::Ident(ident))) = cursor.token_tree() { + if let Some(tt::buffer::TokenTreeRef::Leaf(tt::Leaf::Ident(ident), _)) = cursor.token_tree() { if t == ident.text.as_str() { *cursor = cursor.bump(); return true; @@ -88,7 +88,7 @@ fn eat_ident(cursor: &mut Cursor, t: &str) -> bool { } fn remove_derive_attrs(tt: &tt::Subtree) -> Option { - let buffer = TokenBuffer::new(&tt.token_trees); + let buffer = TokenBuffer::from_tokens(&tt.token_trees); let mut p = buffer.begin(); let mut result = tt::Subtree::default(); @@ -106,7 +106,7 @@ fn remove_derive_attrs(tt: &tt::Subtree) -> Option { } } - result.token_trees.push(curr.token_tree()?.clone()); + result.token_trees.push(curr.token_tree()?.cloned()); p = curr.bump(); } -- cgit v1.2.3