diff options
| author | bors <bors@rust-lang.org> | 2023-12-29 10:41:45 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-12-29 10:41:45 +0000 |
| commit | b74f5c4e8b5320ed24461c9b46a251e477e638b5 (patch) | |
| tree | 24ccc2ae09d517107f93fa53b07f5f06f28743a9 /compiler/rustc_parse/src/parser | |
| parent | 95613d1b23e2fc01a17f25a3221cdf01730305f9 (diff) | |
| parent | 761e0589c27ea0d5c247158ce7e093fb870589db (diff) | |
| download | rust-b74f5c4e8b5320ed24461c9b46a251e477e638b5.tar.gz rust-b74f5c4e8b5320ed24461c9b46a251e477e638b5.zip | |
Auto merge of #119407 - matthiaskrgr:rollup-bsoz7bn, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #119375 (Merge Coroutine lowering functions) - #119393 (Use filter instead of filter_map in Parser::expected_one_of_not_found) - #119401 (coverage: Avoid a possible query stability hazard in `CoverageCounters`) - #119402 (Also walk bindings created by if-let guards) - #119404 (Enable profiler in dist-powerpc-linux) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index b4493df57e2..77bca2f138a 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -450,37 +450,39 @@ impl<'a> Parser<'a> { let mut expected = edible .iter() - .map(|x| TokenType::Token(x.clone())) - .chain(inedible.iter().map(|x| TokenType::Token(x.clone()))) + .chain(inedible) + .cloned() + .map(TokenType::Token) .chain(self.expected_tokens.iter().cloned()) - .filter_map(|token| { - // filter out suggestions which suggest the same token which was found and deemed incorrect + .filter(|token| { + // Filter out suggestions that suggest the same token which was found and deemed incorrect. fn is_ident_eq_keyword(found: &TokenKind, expected: &TokenType) -> bool { - if let TokenKind::Ident(current_sym, _) = found { - if let TokenType::Keyword(suggested_sym) = expected { - return current_sym == suggested_sym; - } + if let TokenKind::Ident(current_sym, _) = found + && let TokenType::Keyword(suggested_sym) = expected + { + return current_sym == suggested_sym; } false } - if token != parser::TokenType::Token(self.token.kind.clone()) { + + if *token != parser::TokenType::Token(self.token.kind.clone()) { let eq = is_ident_eq_keyword(&self.token.kind, &token); - // if the suggestion is a keyword and the found token is an ident, + // If the suggestion is a keyword and the found token is an ident, // the content of which are equal to the suggestion's content, - // we can remove that suggestion (see the return None statement below) + // we can remove that suggestion (see the `return false` below). - // if this isn't the case however, and the suggestion is a token the - // content of which is the same as the found token's, we remove it as well + // If this isn't the case however, and the suggestion is a token the + // content of which is the same as the found token's, we remove it as well. if !eq { if let TokenType::Token(kind) = &token { if kind == &self.token.kind { - return None; + return false; } } - return Some(token); + return true; } } - return None; + false }) .collect::<Vec<_>>(); expected.sort_by_cached_key(|x| x.to_string()); @@ -488,10 +490,10 @@ impl<'a> Parser<'a> { let sm = self.sess.source_map(); - // Special-case "expected `;`" errors + // Special-case "expected `;`" errors. if expected.contains(&TokenType::Token(token::Semi)) { // If the user is trying to write a ternary expression, recover it and - // return an Err to prevent a cascade of irrelevant diagnostics + // return an Err to prevent a cascade of irrelevant diagnostics. if self.prev_token == token::Question && let Err(e) = self.maybe_recover_from_ternary_operator() { |
