Use if-let guards in the codebase
This commit is contained in:
parent
a992a11913
commit
fde1b76b4b
27 changed files with 242 additions and 254 deletions
|
@ -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))?,
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue