diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2023-07-31 15:53:46 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2023-08-02 10:04:00 +1000 |
| commit | 203cba76e07c87c4e665b2e78ca0358b5a72e86a (patch) | |
| tree | e19b3afd4ef8a53d8c12e37298e814b021525470 /src | |
| parent | db7b07aa028b65b4d85610e81fecb0d2382b8c76 (diff) | |
| download | rust-203cba76e07c87c4e665b2e78ca0358b5a72e86a.tar.gz rust-203cba76e07c87c4e665b2e78ca0358b5a72e86a.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustdoc/clean/render_macro_matchers.rs | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/librustdoc/clean/render_macro_matchers.rs b/src/librustdoc/clean/render_macro_matchers.rs index b3dc0f63e45..66d10f2368b 100644 --- a/src/librustdoc/clean/render_macro_matchers.rs +++ b/src/librustdoc/clean/render_macro_matchers.rs @@ -76,14 +76,13 @@ fn snippet_equal_to_token(tcx: TyCtxt<'_>, matcher: &TokenTree) -> Option<String }; // Reparse a single token tree. - let mut reparsed_trees = Vec::new(); - while parser.token != token::Eof { - reparsed_trees.push(parser.parse_token_tree()); + if parser.token == token::Eof { + return None; } - if reparsed_trees.len() != 1 { + let reparsed_tree = parser.parse_token_tree(); + if parser.token != token::Eof { return None; } - let reparsed_tree = reparsed_trees.pop().unwrap(); // Compare against the original tree. if reparsed_tree.eq_unspanned(matcher) { Some(snippet) } else { None } |
