Rollup merge of #94146 - est31:let_else, r=cjgillot

Adopt let else in more places

Continuation of #89933, #91018, #91481, #93046, #93590, #94011.

I have extended my clippy lint to also recognize tuple passing and match statements. The diff caused by fixing it is way above 1 thousand lines. Thus, I split it up into multiple pull requests to make reviewing easier. This is the biggest of these PRs and handles the changes outside of rustdoc, rustc_typeck, rustc_const_eval, rustc_trait_selection, which were handled in PRs #94139, #94142, #94143, #94144.
This commit is contained in:
Matthias Krüger 2022-02-20 00:37:34 +01:00 committed by GitHub
commit f2d6770f77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
132 changed files with 539 additions and 881 deletions

View file

@ -338,20 +338,16 @@ pub(super) fn check_for_substitution<'a>(
ch: char,
err: &mut DiagnosticBuilder<'a>,
) -> Option<token::TokenKind> {
let (u_name, ascii_char) = match UNICODE_ARRAY.iter().find(|&&(c, _, _)| c == ch) {
Some(&(_u_char, u_name, ascii_char)) => (u_name, ascii_char),
None => return None,
let Some(&(_u_char, u_name, ascii_char)) = UNICODE_ARRAY.iter().find(|&&(c, _, _)| c == ch) else {
return None;
};
let span = Span::with_root_ctxt(pos, pos + Pos::from_usize(ch.len_utf8()));
let (ascii_name, token) = match ASCII_ARRAY.iter().find(|&&(c, _, _)| c == ascii_char) {
Some((_ascii_char, ascii_name, token)) => (ascii_name, token),
None => {
let msg = format!("substitution character not found for '{}'", ch);
reader.sess.span_diagnostic.span_bug_no_panic(span, &msg);
return None;
}
let Some((_ascii_char, ascii_name, token)) = ASCII_ARRAY.iter().find(|&&(c, _, _)| c == ascii_char) else {
let msg = format!("substitution character not found for '{}'", ch);
reader.sess.span_diagnostic.span_bug_no_panic(span, &msg);
return None;
};
// special help suggestion for "directed" double quotes

View file

@ -1667,9 +1667,8 @@ impl<'a> Parser<'a> {
Err(LitError::NotLiteral) => None,
Err(err) => {
let span = token.span;
let lit = match token.kind {
token::Literal(lit) => lit,
_ => unreachable!(),
let token::Literal(lit) = token.kind else {
unreachable!();
};
self.bump();
self.report_lit_error(err, lit, span);

View file

@ -439,9 +439,8 @@ impl<'a> Parser<'a> {
/// Recover if we parsed attributes and expected an item but there was none.
fn recover_attrs_no_item(&mut self, attrs: &[Attribute]) -> PResult<'a, ()> {
let (start, end) = match attrs {
[] => return Ok(()),
[x0 @ xn] | [x0, .., xn] => (x0, xn),
let ([start @ end] | [start, .., end]) = attrs else {
return Ok(());
};
let msg = if end.is_doc_comment() {
"expected item after doc comment"

View file

@ -524,9 +524,8 @@ impl<'a> Parser<'a> {
// Skip looking for a trailing semicolon when we have an interpolated statement.
maybe_whole!(self, NtStmt, |x| Some(x));
let mut stmt = match self.parse_stmt_without_recovery(true, ForceCollect::No)? {
Some(stmt) => stmt,
None => return Ok(None),
let Some(mut stmt) = self.parse_stmt_without_recovery(true, ForceCollect::No)? else {
return Ok(None);
};
let mut eat_semi = true;