Move diagnostic logic out of parser
This commit is contained in:
parent
a2f853a691
commit
da57ac38a6
@ -614,4 +614,23 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
crate fn expected_expression_found(&self) -> DiagnosticBuilder<'a> {
|
||||
let (span, msg) = match (&self.token, self.subparser_name) {
|
||||
(&token::Token::Eof, Some(origin)) => {
|
||||
let sp = self.sess.source_map().next_point(self.span);
|
||||
(sp, format!( "expected expression, found end of {}", origin))
|
||||
}
|
||||
_ => (self.span, format!(
|
||||
"expected expression, found {}",
|
||||
self.this_token_descr(),
|
||||
)),
|
||||
};
|
||||
let mut err = self.struct_span_err(span, &msg);
|
||||
let sp = self.sess.source_map().start_point(self.span);
|
||||
if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&sp) {
|
||||
self.sess.expr_parentheses_needed(&mut err, *sp, None);
|
||||
}
|
||||
err.span_label(span, "expected expression");
|
||||
err
|
||||
}
|
||||
}
|
||||
|
@ -2601,25 +2601,7 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
Err(mut err) => {
|
||||
self.cancel(&mut err);
|
||||
let (span, msg) = match (&self.token, self.subparser_name) {
|
||||
(&token::Token::Eof, Some(origin)) => {
|
||||
let sp = self.sess.source_map().next_point(self.span);
|
||||
(sp, format!( "expected expression, found end of {}", origin))
|
||||
}
|
||||
_ => (self.span, format!(
|
||||
"expected expression, found {}",
|
||||
self.this_token_descr(),
|
||||
)),
|
||||
};
|
||||
let mut err = self.struct_span_err(span, &msg);
|
||||
let sp = self.sess.source_map().start_point(self.span);
|
||||
if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow()
|
||||
.get(&sp)
|
||||
{
|
||||
self.sess.expr_parentheses_needed(&mut err, *sp, None);
|
||||
}
|
||||
err.span_label(span, "expected expression");
|
||||
return Err(err);
|
||||
return Err(self.expected_expression_found());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user