extract: error_block_no_opening_brace
This commit is contained in:
parent
cdca5cfbfd
commit
be463cbc2b
@ -291,6 +291,13 @@ pub fn parse_block(&mut self) -> PResult<'a, P<Block>> {
|
||||
let lo = self.token.span;
|
||||
|
||||
if !self.eat(&token::OpenDelim(token::Brace)) {
|
||||
return self.error_block_no_opening_brace();
|
||||
}
|
||||
|
||||
self.parse_block_tail(lo, BlockCheckMode::Default)
|
||||
}
|
||||
|
||||
fn error_block_no_opening_brace<T>(&mut self) -> PResult<'a, T> {
|
||||
let sp = self.token.span;
|
||||
let tok = self.this_token_descr();
|
||||
let mut e = self.span_fatal(sp, &format!("expected `{{`, found {}", tok));
|
||||
@ -323,17 +330,19 @@ pub fn parse_block(&mut self) -> PResult<'a, P<Block>> {
|
||||
match self.parse_stmt_without_recovery(false) {
|
||||
Ok(Some(stmt)) => {
|
||||
if self.look_ahead(1, |t| t == &token::OpenDelim(token::Brace))
|
||||
|| do_not_suggest_help {
|
||||
|| do_not_suggest_help
|
||||
{
|
||||
// If the next token is an open brace (e.g., `if a b {`), the place-
|
||||
// inside-a-block suggestion would be more likely wrong than right.
|
||||
e.span_label(sp, "expected `{`");
|
||||
return Err(e);
|
||||
}
|
||||
let mut stmt_span = stmt.span;
|
||||
// Expand the span to include the semicolon, if it exists.
|
||||
if self.eat(&token::Semi) {
|
||||
stmt_span = stmt_span.with_hi(self.prev_span.hi());
|
||||
}
|
||||
let stmt_span = if self.eat(&token::Semi) {
|
||||
// Expand the span to include the semicolon.
|
||||
stmt.span.with_hi(self.prev_span.hi())
|
||||
} else {
|
||||
stmt.span
|
||||
};
|
||||
if let Ok(snippet) = self.span_to_snippet(stmt_span) {
|
||||
e.span_suggestion(
|
||||
stmt_span,
|
||||
@ -348,15 +357,12 @@ pub fn parse_block(&mut self) -> PResult<'a, P<Block>> {
|
||||
self.recover_stmt_(SemiColonMode::Break, BlockMode::Ignore);
|
||||
e.cancel();
|
||||
}
|
||||
_ => ()
|
||||
_ => {}
|
||||
}
|
||||
e.span_label(sp, "expected `{`");
|
||||
return Err(e);
|
||||
}
|
||||
|
||||
self.parse_block_tail(lo, BlockCheckMode::Default)
|
||||
}
|
||||
|
||||
/// Parses a block. Inner attributes are allowed.
|
||||
pub(super) fn parse_inner_attrs_and_block(
|
||||
&mut self
|
||||
|
Loading…
Reference in New Issue
Block a user