Skip to content

Commit a34bcd7

Browse files
authored
Rollup merge of rust-lang#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.
2 parents b4734f0 + 24cbf81 commit a34bcd7

File tree

27 files changed

+126
-109
lines changed

27 files changed

+126
-109
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,6 @@ pub enum GenericArgs {
167167
AngleBracketed(AngleBracketedArgs),
168168
/// The `(A, B)` and `C` in `Foo(A, B) -> C`.
169169
Parenthesized(ParenthesizedArgs),
170-
/// Associated return type bounds, like `T: Trait<method(..): Send>`
171-
/// which applies the `Send` bound to the return-type of `method`.
172-
ReturnTypeNotation(Span),
173170
}
174171

175172
impl GenericArgs {
@@ -181,7 +178,6 @@ impl GenericArgs {
181178
match self {
182179
AngleBracketed(data) => data.span,
183180
Parenthesized(data) => data.span,
184-
ReturnTypeNotation(span) => *span,
185181
}
186182
}
187183
}

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,6 @@ pub fn noop_visit_generic_args<T: MutVisitor>(generic_args: &mut GenericArgs, vi
561561
match generic_args {
562562
GenericArgs::AngleBracketed(data) => vis.visit_angle_bracketed_parameter_data(data),
563563
GenericArgs::Parenthesized(data) => vis.visit_parenthesized_parameter_data(data),
564-
GenericArgs::ReturnTypeNotation(_span) => {}
565564
}
566565
}
567566

compiler/rustc_ast/src/visit.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,6 @@ where
482482
walk_list!(visitor, visit_ty, &data.inputs);
483483
walk_fn_ret_ty(visitor, &data.output);
484484
}
485-
GenericArgs::ReturnTypeNotation(_span) => {}
486485
}
487486
}
488487

compiler/rustc_ast_lowering/src/errors.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -353,13 +353,7 @@ pub enum BadReturnTypeNotation {
353353
#[diag(ast_lowering_bad_return_type_notation_inputs)]
354354
Inputs {
355355
#[primary_span]
356-
#[suggestion(code = "(..)", applicability = "maybe-incorrect")]
357-
span: Span,
358-
},
359-
#[diag(ast_lowering_bad_return_type_notation_needs_dots)]
360-
NeedsDots {
361-
#[primary_span]
362-
#[suggestion(code = "(..)", applicability = "maybe-incorrect")]
356+
#[suggestion(code = "()", applicability = "maybe-incorrect")]
363357
span: Span,
364358
},
365359
#[diag(ast_lowering_bad_return_type_notation_output)]

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -987,15 +987,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
987987
GenericArgs::AngleBracketed(data) => {
988988
self.lower_angle_bracketed_parameter_data(data, ParamMode::Explicit, itctx).0
989989
}
990-
&GenericArgs::ReturnTypeNotation(span) => GenericArgsCtor {
991-
args: Default::default(),
992-
bindings: &[],
993-
parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
994-
span,
995-
},
996990
GenericArgs::Parenthesized(data) => {
997-
if let Some(start_char) = constraint.ident.as_str().chars().next()
998-
&& start_char.is_ascii_lowercase()
991+
if data.inputs.is_empty() && matches!(data.output, FnRetTy::Default(..)) {
992+
let parenthesized = if self.tcx.features().return_type_notation {
993+
hir::GenericArgsParentheses::ReturnTypeNotation
994+
} else {
995+
self.emit_bad_parenthesized_trait_in_assoc_ty(data);
996+
hir::GenericArgsParentheses::No
997+
};
998+
GenericArgsCtor {
999+
args: Default::default(),
1000+
bindings: &[],
1001+
parenthesized,
1002+
span: data.inputs_span,
1003+
}
1004+
} else if let Some(first_char) = constraint.ident.as_str().chars().next()
1005+
&& first_char.is_ascii_lowercase()
9991006
{
10001007
let mut err = if !data.inputs.is_empty() {
10011008
self.tcx.sess.create_err(errors::BadReturnTypeNotation::Inputs {
@@ -1006,9 +1013,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10061013
span: data.inputs_span.shrink_to_hi().to(ty.span),
10071014
})
10081015
} else {
1009-
self.tcx.sess.create_err(errors::BadReturnTypeNotation::NeedsDots {
1010-
span: data.inputs_span,
1011-
})
1016+
unreachable!("inputs are empty and return type is not provided")
10121017
};
10131018
if !self.tcx.features().return_type_notation
10141019
&& self.tcx.sess.is_nightly_build()

compiler/rustc_ast_lowering/src/path.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use rustc_span::symbol::{kw, sym, Ident};
1313
use rustc_span::{BytePos, Span, DUMMY_SP};
1414

1515
use smallvec::{smallvec, SmallVec};
16-
use thin_vec::ThinVec;
1716

1817
impl<'a, 'hir> LoweringContext<'a, 'hir> {
1918
#[instrument(level = "trace", skip(self))]
@@ -219,18 +218,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
219218
)
220219
}
221220
},
222-
&GenericArgs::ReturnTypeNotation(span) => {
223-
self.tcx.sess.emit_err(GenericTypeWithParentheses { span, sub: None });
224-
(
225-
self.lower_angle_bracketed_parameter_data(
226-
&AngleBracketedArgs { span, args: ThinVec::default() },
227-
param_mode,
228-
itctx,
229-
)
230-
.0,
231-
false,
232-
)
233-
}
234221
}
235222
} else {
236223
(

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10801080
self.with_impl_trait(None, |this| this.visit_ty(ty));
10811081
}
10821082
}
1083-
GenericArgs::ReturnTypeNotation(_span) => {}
10841083
}
10851084
}
10861085

@@ -1391,7 +1390,6 @@ fn deny_equality_constraints(
13911390
match &mut assoc_path.segments[len].args {
13921391
Some(args) => match args.deref_mut() {
13931392
GenericArgs::Parenthesized(_) => continue,
1394-
GenericArgs::ReturnTypeNotation(_span) => continue,
13951393
GenericArgs::AngleBracketed(args) => {
13961394
args.args.push(arg);
13971395
}

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -485,20 +485,23 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
485485

486486
fn visit_assoc_constraint(&mut self, constraint: &'a AssocConstraint) {
487487
if let AssocConstraintKind::Bound { .. } = constraint.kind {
488-
if let Some(args) = constraint.gen_args.as_ref()
489-
&& matches!(
490-
args,
491-
ast::GenericArgs::ReturnTypeNotation(..)
492-
)
488+
if let Some(ast::GenericArgs::Parenthesized(args)) = constraint.gen_args.as_ref()
489+
&& args.inputs.is_empty()
490+
&& matches!(args.output, ast::FnRetTy::Default(..))
493491
{
494-
// RTN is gated below with a `gate_all`.
492+
gate_feature_post!(
493+
&self,
494+
return_type_notation,
495+
constraint.span,
496+
"return type notation is experimental"
497+
);
495498
} else {
496499
gate_feature_post!(
497500
&self,
498501
associated_type_bounds,
499502
constraint.span,
500503
"associated type bounds are unstable"
501-
)
504+
);
502505
}
503506
}
504507
visit::walk_assoc_constraint(self, constraint)
@@ -589,7 +592,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
589592
gate_all!(yeet_expr, "`do yeet` expression is experimental");
590593
gate_all!(dyn_star, "`dyn*` trait objects are experimental");
591594
gate_all!(const_closures, "const closures are experimental");
592-
gate_all!(return_type_notation, "return type notation is experimental");
593595

594596
// All uses of `gate_all!` below this point were added in #65742,
595597
// and subsequently disabled (with the non-early gating readded).
@@ -605,6 +607,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
605607

606608
gate_all!(trait_alias, "trait aliases are experimental");
607609
gate_all!(associated_type_bounds, "associated type bounds are unstable");
610+
gate_all!(return_type_notation, "return type notation is experimental");
608611
gate_all!(decl_macro, "`macro` is experimental");
609612
gate_all!(box_patterns, "box pattern syntax is experimental");
610613
gate_all!(exclusive_range_pattern, "exclusive range pattern syntax is experimental");

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -936,10 +936,6 @@ impl<'a> PrintState<'a> for State<'a> {
936936
self.word(")");
937937
self.print_fn_ret_ty(&data.output);
938938
}
939-
940-
ast::GenericArgs::ReturnTypeNotation(_span) => {
941-
self.word("(..)");
942-
}
943939
}
944940
}
945941
}

compiler/rustc_parse/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,3 +738,7 @@ parse_box_syntax_removed = `box_syntax` has been removed
738738
parse_bad_return_type_notation_output =
739739
return type not allowed with return type notation
740740
.suggestion = remove the return type
741+
742+
parse_bad_return_type_notation_dotdot =
743+
return type notation uses `()` instead of `(..)` for elided arguments
744+
.suggestion = remove the `..`

0 commit comments

Comments
 (0)