Only call parse_token_tree
once.
This code currently uses a `while` loop and gathers token trees into a vector, but it only succeeds in the case where there is a single token tree. We can instead just call `parse_token_tree` once and then look for `Eof` to detect the success case.
This commit is contained in:
parent
db7b07aa02
commit
203cba76e0
@ -76,14 +76,13 @@ fn snippet_equal_to_token(tcx: TyCtxt<'_>, matcher: &TokenTree) -> Option<String
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Reparse a single token tree.
|
// Reparse a single token tree.
|
||||||
let mut reparsed_trees = Vec::new();
|
if parser.token == token::Eof {
|
||||||
while parser.token != token::Eof {
|
return None;
|
||||||
reparsed_trees.push(parser.parse_token_tree());
|
}
|
||||||
}
|
let reparsed_tree = parser.parse_token_tree();
|
||||||
if reparsed_trees.len() != 1 {
|
if parser.token != token::Eof {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let reparsed_tree = reparsed_trees.pop().unwrap();
|
|
||||||
|
|
||||||
// Compare against the original tree.
|
// Compare against the original tree.
|
||||||
if reparsed_tree.eq_unspanned(matcher) { Some(snippet) } else { None }
|
if reparsed_tree.eq_unspanned(matcher) { Some(snippet) } else { None }
|
||||||
|
Loading…
Reference in New Issue
Block a user