diff options
| author | Léo Lanteri Thauvin <leseulartichaut@gmail.com> | 2021-08-16 17:29:49 +0200 |
|---|---|---|
| committer | Léo Lanteri Thauvin <leseulartichaut@gmail.com> | 2021-08-25 20:24:35 +0200 |
| commit | fde1b76b4b1d0d84f5691f4785906b31bb91f38d (patch) | |
| tree | 966691ff24d8ec26354d737e549bbfccaa658f3d /compiler/rustc_parse/src/parser | |
| parent | a992a11913b39a258158646bb1e03528c5aa5060 (diff) | |
| download | rust-fde1b76b4b1d0d84f5691f4785906b31bb91f38d.tar.gz rust-fde1b76b4b1d0d84f5691f4785906b31bb91f38d.zip | |
Use if-let guards in the codebase
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/nonterminal.rs | 17 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/stmt.rs | 20 |
2 files changed, 18 insertions, 19 deletions
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<bar, baz>;`. Try to recover. - match &mut local.init { - Some(ref mut expr) => { - self.check_mistyped_turbofish_with_multiple_type_params(e, expr)?; - // We found `foo<bar, baz>`, 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<bar, baz>;`. Try to recover. + match &mut local.init { + Some(ref mut expr) => { + self.check_mistyped_turbofish_with_multiple_type_params(e, expr)?; + // We found `foo<bar, baz>`, 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) { |
