+ fn parse_tuple_parens_expr(&mut self) -> PResult<'a, P<Expr>> {
+ let lo = self.token.span;
+ let mut first = true;
+ let mut attrs = ThinVec::new();
+ let parse_leading_attr_expr = |p: &mut Self| {
+ if first {
+ // `(#![foo] a, b, ...)` is OK...
+ attrs = p.parse_inner_attributes()?.into();
+ // ...but not `(a, #![foo] b, ...)`.
+ first = false;
+ }
+ p.parse_expr_catch_underscore()
+ };
+ let (es, trailing_comma) = match self.parse_paren_comma_seq(parse_leading_attr_expr) {
+ Ok(x) => x,
+ Err(err) => return Ok(self.recover_seq_parse_error(token::Paren, lo, Err(err))),
+ };
+ let kind = if es.len() == 1 && !trailing_comma {
+ // `(e)` is parenthesized `e`.
+ ExprKind::Paren(es.into_iter().nth(0).unwrap())
+ } else {
+ // `(e,)` is a tuple with only one field, `e`.
+ ExprKind::Tup(es)
+ };
+ let expr = self.mk_expr(lo.to(self.prev_span), kind, attrs);
+ self.maybe_recover_from_bad_qpath(expr, true)
+ }
+