From d9f2fdfaed8d18ede6d113426279c86d84d92445 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 31 Jul 2023 15:47:19 +1000 Subject: `parse_all_token_trees` cannot fail. --- src/librustdoc/clean/render_macro_matchers.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'src/librustdoc') diff --git a/src/librustdoc/clean/render_macro_matchers.rs b/src/librustdoc/clean/render_macro_matchers.rs index ef38ca3c16c..b6120e814df 100644 --- a/src/librustdoc/clean/render_macro_matchers.rs +++ b/src/librustdoc/clean/render_macro_matchers.rs @@ -76,13 +76,7 @@ fn snippet_equal_to_token(tcx: TyCtxt<'_>, matcher: &TokenTree) -> Option reparsed_trees, - Err(diagnostic) => { - diagnostic.cancel(); - return None; - } - }; + let mut reparsed_trees = parser.parse_all_token_trees(); if reparsed_trees.len() != 1 { return None; } -- cgit 1.4.1-3-g733a5 From db7b07aa028b65b4d85610e81fecb0d2382b8c76 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 31 Jul 2023 15:51:08 +1000 Subject: Inline and remove `parse_all_token_trees`. It has a single call site. --- compiler/rustc_parse/src/parser/mod.rs | 11 +---------- src/librustdoc/clean/render_macro_matchers.rs | 5 ++++- 2 files changed, 5 insertions(+), 11 deletions(-) (limited to 'src/librustdoc') diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index b452eb6a401..4b23f5a6de1 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -1251,7 +1251,7 @@ impl<'a> Parser<'a> { } /// Parses a single token tree from the input. - pub(crate) fn parse_token_tree(&mut self) -> TokenTree { + pub fn parse_token_tree(&mut self) -> TokenTree { match self.token.kind { token::OpenDelim(..) => { // Grab the tokens within the delimiters. @@ -1287,15 +1287,6 @@ impl<'a> Parser<'a> { } } - /// Parses a stream of tokens into a list of `TokenTree`s, up to EOF. - pub fn parse_all_token_trees(&mut self) -> Vec { - let mut tts = Vec::new(); - while self.token != token::Eof { - tts.push(self.parse_token_tree()); - } - tts - } - pub fn parse_tokens(&mut self) -> TokenStream { let mut result = Vec::new(); loop { diff --git a/src/librustdoc/clean/render_macro_matchers.rs b/src/librustdoc/clean/render_macro_matchers.rs index b6120e814df..b3dc0f63e45 100644 --- a/src/librustdoc/clean/render_macro_matchers.rs +++ b/src/librustdoc/clean/render_macro_matchers.rs @@ -76,7 +76,10 @@ fn snippet_equal_to_token(tcx: TyCtxt<'_>, matcher: &TokenTree) -> Option Date: Mon, 31 Jul 2023 15:53:46 +1000 Subject: 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. --- src/librustdoc/clean/render_macro_matchers.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/librustdoc') 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