1
Fork 0

Rely on regular "expected"/"found" parser error for fn

This commit is contained in:
Esteban Küber 2020-10-25 12:13:27 -07:00
parent 07a63e6d1f
commit 040f568815
15 changed files with 36 additions and 31 deletions

View file

@ -1550,14 +1550,6 @@ impl<'a> Parser<'a> {
}
}
pub(super) fn expected_semi_or_open_brace<T>(&mut self) -> PResult<'a, T> {
let token_str = super::token_descr(&self.token);
let msg = &format!("expected `;` or `{{`, found {}", token_str);
let mut err = self.struct_span_err(self.token.span, msg);
err.span_label(self.token.span, "expected `;` or `{`");
Err(err)
}
pub(super) fn eat_incorrect_doc_comment_for_param_type(&mut self) {
if let token::DocComment(..) = self.token.kind {
self.struct_span_err(

View file

@ -1551,10 +1551,9 @@ impl<'a> Parser<'a> {
attrs: &mut Vec<Attribute>,
sig_hi: &mut Span,
) -> PResult<'a, Option<P<Block>>> {
let (inner_attrs, body) = if self.check(&token::Semi) {
let (inner_attrs, body) = if self.eat(&token::Semi) {
// Include the trailing semicolon in the span of the signature
*sig_hi = self.token.span;
self.bump(); // `;`
*sig_hi = self.prev_token.span;
(Vec::new(), None)
} else if self.check(&token::OpenDelim(token::Brace)) || self.token.is_whole_block() {
self.parse_inner_attrs_and_block().map(|(attrs, body)| (attrs, Some(body)))?
@ -1574,7 +1573,9 @@ impl<'a> Parser<'a> {
.emit();
(Vec::new(), Some(self.mk_block_err(span)))
} else {
return self.expected_semi_or_open_brace();
return self
.expected_one_of_not_found(&[], &[token::Semi, token::OpenDelim(token::Brace)])
.map(|_| None);
};
attrs.extend(inner_attrs);
Ok(body)