parse_all_token_trees cannot fail.

This commit is contained in:
Nicholas Nethercote 2023-07-31 15:47:19 +10:00
parent d12c6e947c
commit d9f2fdfaed
2 changed files with 3 additions and 9 deletions

View File

@ -1288,12 +1288,12 @@ pub(crate) fn parse_token_tree(&mut self) -> TokenTree {
} }
/// Parses a stream of tokens into a list of `TokenTree`s, up to EOF. /// Parses a stream of tokens into a list of `TokenTree`s, up to EOF.
pub fn parse_all_token_trees(&mut self) -> PResult<'a, Vec<TokenTree>> { pub fn parse_all_token_trees(&mut self) -> Vec<TokenTree> {
let mut tts = Vec::new(); let mut tts = Vec::new();
while self.token != token::Eof { while self.token != token::Eof {
tts.push(self.parse_token_tree()); tts.push(self.parse_token_tree());
} }
Ok(tts) tts
} }
pub fn parse_tokens(&mut self) -> TokenStream { pub fn parse_tokens(&mut self) -> TokenStream {

View File

@ -76,13 +76,7 @@ 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 = match parser.parse_all_token_trees() { let mut reparsed_trees = parser.parse_all_token_trees();
Ok(reparsed_trees) => reparsed_trees,
Err(diagnostic) => {
diagnostic.cancel();
return None;
}
};
if reparsed_trees.len() != 1 { if reparsed_trees.len() != 1 {
return None; return None;
} }