From fde1b76b4b1d0d84f5691f4785906b31bb91f38d Mon Sep 17 00:00:00 2001 From: Léo Lanteri Thauvin Date: Mon, 16 Aug 2021 17:29:49 +0200 Subject: Use if-let guards in the codebase --- compiler/rustc_parse/src/parser/nonterminal.rs | 17 +++++++++-------- compiler/rustc_parse/src/parser/stmt.rs | 20 +++++++++----------- 2 files changed, 18 insertions(+), 19 deletions(-) (limited to 'compiler/rustc_parse/src/parser') diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs index 313d9db58fc..72e6f8a1bc8 100644 --- a/compiler/rustc_parse/src/parser/nonterminal.rs +++ b/compiler/rustc_parse/src/parser/nonterminal.rs @@ -143,15 +143,16 @@ impl<'a> Parser<'a> { token::NtTy(self.collect_tokens_no_attrs(|this| this.parse_ty())?) } // this could be handled like a token, since it is one + NonterminalKind::Ident + if let Some((ident, is_raw)) = get_macro_ident(&self.token) => + { + self.bump(); + token::NtIdent(ident, is_raw) + } NonterminalKind::Ident => { - if let Some((ident, is_raw)) = get_macro_ident(&self.token) { - self.bump(); - token::NtIdent(ident, is_raw) - } else { - let token_str = pprust::token_to_string(&self.token); - let msg = &format!("expected ident, found {}", &token_str); - return Err(self.struct_span_err(self.token.span, msg)); - } + let token_str = pprust::token_to_string(&self.token); + let msg = &format!("expected ident, found {}", &token_str); + return Err(self.struct_span_err(self.token.span, msg)); } NonterminalKind::Path => token::NtPath( self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?, diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 9ef3f61ec34..85515bd2a63 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -493,21 +493,19 @@ impl<'a> Parser<'a> { } } StmtKind::Expr(_) | StmtKind::MacCall(_) => {} - StmtKind::Local(ref mut local) => { - if let Err(e) = self.expect_semi() { - // We might be at the `,` in `let x = foo;`. Try to recover. - match &mut local.init { - Some(ref mut expr) => { - self.check_mistyped_turbofish_with_multiple_type_params(e, expr)?; - // We found `foo`, have we fully recovered? - self.expect_semi()?; - } - None => return Err(e), + StmtKind::Local(ref mut local) if let Err(e) = self.expect_semi() => { + // We might be at the `,` in `let x = foo;`. Try to recover. + match &mut local.init { + Some(ref mut expr) => { + self.check_mistyped_turbofish_with_multiple_type_params(e, expr)?; + // We found `foo`, have we fully recovered? + self.expect_semi()?; } + None => return Err(e), } eat_semi = false; } - StmtKind::Empty | StmtKind::Item(_) | StmtKind::Semi(_) => eat_semi = false, + StmtKind::Empty | StmtKind::Item(_) | StmtKind::Local(_) | StmtKind::Semi(_) => eat_semi = false, } if eat_semi && self.eat(&token::Semi) { -- cgit 1.4.1-3-g733a5