Add (..)
syntax for RTN
This commit is contained in:
parent
104aacb49f
commit
8b592db27a
44 changed files with 355 additions and 201 deletions
|
@ -1,6 +1,6 @@
|
|||
use super::ty::{AllowPlus, RecoverQPath, RecoverReturnSign};
|
||||
use super::{Parser, Restrictions, TokenType};
|
||||
use crate::maybe_whole;
|
||||
use crate::{errors, maybe_whole};
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token::{self, Delimiter, Token, TokenKind};
|
||||
use rustc_ast::{
|
||||
|
@ -290,6 +290,25 @@ impl<'a> Parser<'a> {
|
|||
})?;
|
||||
let span = lo.to(self.prev_token.span);
|
||||
AngleBracketedArgs { args, span }.into()
|
||||
} else if self.token.kind == token::OpenDelim(Delimiter::Parenthesis)
|
||||
// FIXME(return_type_notation): Could also recover `...` here.
|
||||
&& self.look_ahead(1, |tok| tok.kind == token::DotDot)
|
||||
{
|
||||
let lo = self.token.span;
|
||||
self.bump();
|
||||
self.bump();
|
||||
self.expect(&token::CloseDelim(Delimiter::Parenthesis))?;
|
||||
let span = lo.to(self.prev_token.span);
|
||||
self.sess.gated_spans.gate(sym::return_type_notation, span);
|
||||
|
||||
if self.eat_noexpect(&token::RArrow) {
|
||||
let lo = self.prev_token.span;
|
||||
let ty = self.parse_ty()?;
|
||||
self.sess
|
||||
.emit_err(errors::BadReturnTypeNotationOutput { span: lo.to(ty.span) });
|
||||
}
|
||||
|
||||
P(GenericArgs::ReturnTypeNotation(span))
|
||||
} else {
|
||||
// `(T, U) -> R`
|
||||
let (inputs, _) = self.parse_paren_comma_seq(|p| p.parse_ty())?;
|
||||
|
@ -300,7 +319,7 @@ impl<'a> Parser<'a> {
|
|||
ParenthesizedArgs { span, inputs, inputs_span, output }.into()
|
||||
};
|
||||
|
||||
PathSegment { ident, args, id: ast::DUMMY_NODE_ID }
|
||||
PathSegment { ident, args: Some(args), id: ast::DUMMY_NODE_ID }
|
||||
} else {
|
||||
// Generic arguments are not found.
|
||||
PathSegment::from_ident(ident)
|
||||
|
@ -550,8 +569,10 @@ impl<'a> Parser<'a> {
|
|||
|
||||
// Gate associated type bounds, e.g., `Iterator<Item: Ord>`.
|
||||
if let AssocConstraintKind::Bound { .. } = kind {
|
||||
if gen_args.as_ref().map_or(false, |args| args.is_parenthesized()) {
|
||||
self.sess.gated_spans.gate(sym::return_type_notation, span);
|
||||
if gen_args.as_ref().map_or(false, |args| {
|
||||
matches!(args, GenericArgs::ReturnTypeNotation(..))
|
||||
}) {
|
||||
// This is already gated in `parse_path_segment`
|
||||
} else {
|
||||
self.sess.gated_spans.gate(sym::associated_type_bounds, span);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue