summaryrefslogtreecommitdiff
path: root/compiler/rustc_parse
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-04-12 20:56:22 +0200
committerGitHub <noreply@github.com>2023-04-12 20:56:22 +0200
commita34bcd70b2ca1ba7fb60fe0cbd1cbfd5fa57a089 (patch)
tree80ecf040f8c30f8ee3dc617d64712c6d1596104c /compiler/rustc_parse
parentb4734f01fee9fd34f80e0516798e70e8e5666533 (diff)
parent24cbf81b8546beb8193217316acf4ded4117b4af (diff)
downloadrust-a34bcd70b2ca1ba7fb60fe0cbd1cbfd5fa57a089.tar.gz
Rollup merge of #110203 - compiler-errors:rtn-dots, r=eholk
Remove `..` from return type notation `@nikomatsakis` and I decided that using `..` in the return-type notation syntax is probably overkill. r? `@eholk` since you reviewed the last one Since this is piggybacking now totally off of a pre-existing syntax (parenthesized generics), let me know if you need any explanation of the logic here, since it's a bit more complicated now.
Diffstat (limited to 'compiler/rustc_parse')
-rw-r--r--compiler/rustc_parse/messages.ftl4
-rw-r--r--compiler/rustc_parse/src/errors.rs8
-rw-r--r--compiler/rustc_parse/src/parser/path.rs25
3 files changed, 28 insertions, 9 deletions
diff --git a/compiler/rustc_parse/messages.ftl b/compiler/rustc_parse/messages.ftl
index e21bbd0217b..f11d0ed0f01 100644
--- a/compiler/rustc_parse/messages.ftl
+++ b/compiler/rustc_parse/messages.ftl
@@ -738,3 +738,7 @@ parse_box_syntax_removed = `box_syntax` has been removed
parse_bad_return_type_notation_output =
return type not allowed with return type notation
.suggestion = remove the return type
+
+parse_bad_return_type_notation_dotdot =
+ return type notation uses `()` instead of `(..)` for elided arguments
+ .suggestion = remove the `..`
diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs
index aead216b61c..069217165fa 100644
--- a/compiler/rustc_parse/src/errors.rs
+++ b/compiler/rustc_parse/src/errors.rs
@@ -2324,3 +2324,11 @@ pub(crate) struct BadReturnTypeNotationOutput {
#[suggestion(code = "", applicability = "maybe-incorrect")]
pub span: Span,
}
+
+#[derive(Diagnostic)]
+#[diag(parse_bad_return_type_notation_dotdot)]
+pub(crate) struct BadReturnTypeNotationDotDot {
+ #[primary_span]
+ #[suggestion(code = "", applicability = "maybe-incorrect")]
+ pub span: Span,
+}
diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs
index f1c9f0109f8..c25c23d849f 100644
--- a/compiler/rustc_parse/src/parser/path.rs
+++ b/compiler/rustc_parse/src/parser/path.rs
@@ -290,16 +290,17 @@ 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)
+ } else if self.may_recover()
+ && 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.sess
+ .emit_err(errors::BadReturnTypeNotationDotDot { span: self.token.span });
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;
@@ -308,7 +309,13 @@ impl<'a> Parser<'a> {
.emit_err(errors::BadReturnTypeNotationOutput { span: lo.to(ty.span) });
}
- P(GenericArgs::ReturnTypeNotation(span))
+ ParenthesizedArgs {
+ span,
+ inputs: ThinVec::new(),
+ inputs_span: span,
+ output: ast::FnRetTy::Default(self.prev_token.span.shrink_to_hi()),
+ }
+ .into()
} else {
// `(T, U) -> R`
let (inputs, _) = self.parse_paren_comma_seq(|p| p.parse_ty())?;
@@ -566,13 +573,13 @@ impl<'a> Parser<'a> {
};
let span = lo.to(self.prev_token.span);
-
// Gate associated type bounds, e.g., `Iterator<Item: Ord>`.
if let AssocConstraintKind::Bound { .. } = kind {
- if gen_args.as_ref().map_or(false, |args| {
- matches!(args, GenericArgs::ReturnTypeNotation(..))
- }) {
- // This is already gated in `parse_path_segment`
+ if let Some(ast::GenericArgs::Parenthesized(args)) = &gen_args
+ && args.inputs.is_empty()
+ && matches!(args.output, ast::FnRetTy::Default(..))
+ {
+ self.sess.gated_spans.gate(sym::return_type_notation, span);
} else {
self.sess.gated_spans.gate(sym::associated_type_bounds, span);
}