From 379f3181def3021818b7d8c3d69a512c290d9dc9 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Thu, 5 Mar 2020 08:08:07 +0100 Subject: [PATCH] parse: simplify parse_fn_body --- src/librustc_parse/parser/item.rs | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs index 126686c8def..428c01a8344 100644 --- a/src/librustc_parse/parser/item.rs +++ b/src/librustc_parse/parser/item.rs @@ -1411,23 +1411,13 @@ impl<'a> Parser<'a> { /// This can either be `;` when there's no body, /// or e.g. a block when the function is a provided one. fn parse_fn_body(&mut self, attrs: &mut Vec) -> PResult<'a, Option>> { - let (inner_attrs, body) = match self.token.kind { - token::Semi => { - self.bump(); - (Vec::new(), None) - } - token::OpenDelim(token::Brace) => { - let (attrs, body) = self.parse_inner_attrs_and_block()?; - (attrs, Some(body)) - } - token::Interpolated(ref nt) => match **nt { - token::NtBlock(..) => { - let (attrs, body) = self.parse_inner_attrs_and_block()?; - (attrs, Some(body)) - } - _ => return self.expected_semi_or_open_brace(), - }, - _ => return self.expected_semi_or_open_brace(), + let (inner_attrs, body) = if self.check(&token::Semi) { + self.bump(); + (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)))? + } else { + return self.expected_semi_or_open_brace(); }; attrs.extend(inner_attrs); Ok(body)