Skip to content

Commit 203cba7

Browse files
committed
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.
1 parent db7b07a commit 203cba7

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/librustdoc/clean/render_macro_matchers.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,13 @@ fn snippet_equal_to_token(tcx: TyCtxt<'_>, matcher: &TokenTree) -> Option<String
7676
};
7777

7878
// Reparse a single token tree.
79-
let mut reparsed_trees = Vec::new();
80-
while parser.token != token::Eof {
81-
reparsed_trees.push(parser.parse_token_tree());
79+
if parser.token == token::Eof {
80+
return None;
8281
}
83-
if reparsed_trees.len() != 1 {
82+
let reparsed_tree = parser.parse_token_tree();
83+
if parser.token != token::Eof {
8484
return None;
8585
}
86-
let reparsed_tree = reparsed_trees.pop().unwrap();
8786

8887
// Compare against the original tree.
8988
if reparsed_tree.eq_unspanned(matcher) { Some(snippet) } else { None }

0 commit comments

Comments
 (0)