mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
Refactor TokenBuffer for reduc cloning
This commit is contained in:
parent
f1ffd14922
commit
af3d75ad2e
5 changed files with 99 additions and 53 deletions
|
@ -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<tt::Subtree> {
|
||||
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<tt::Subtree> {
|
|||
}
|
||||
}
|
||||
|
||||
result.token_trees.push(curr.token_tree()?.clone());
|
||||
result.token_trees.push(curr.token_tree()?.cloned());
|
||||
p = curr.bump();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue