Skip to content

Commit b1a0c0b

Browse files
Change RTN to use .. again
1 parent 99f77a2 commit b1a0c0b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+109
-163
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ pub enum GenericArgs {
176176
AngleBracketed(AngleBracketedArgs),
177177
/// The `(A, B)` and `C` in `Foo(A, B) -> C`.
178178
Parenthesized(ParenthesizedArgs),
179+
/// `(..)` in return type notation
180+
ParenthesizedElided(Span),
179181
}
180182

181183
impl GenericArgs {
@@ -187,6 +189,7 @@ impl GenericArgs {
187189
match self {
188190
AngleBracketed(data) => data.span,
189191
Parenthesized(data) => data.span,
192+
ParenthesizedElided(span) => *span,
190193
}
191194
}
192195
}
@@ -2051,7 +2054,7 @@ impl UintTy {
20512054
/// * the `A: Bound` in `Trait<A: Bound>`
20522055
/// * the `RetTy` in `Trait(ArgTy, ArgTy) -> RetTy`
20532056
/// * the `C = { Ct }` in `Trait<C = { Ct }>` (feature `associated_const_equality`)
2054-
/// * the `f(): Bound` in `Trait<f(): Bound>` (feature `return_type_notation`)
2057+
/// * the `f(..): Bound` in `Trait<f(..): Bound>` (feature `return_type_notation`)
20552058
#[derive(Clone, Encodable, Decodable, Debug)]
20562059
pub struct AssocItemConstraint {
20572060
pub id: NodeId,

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ fn noop_visit_generic_args<T: MutVisitor>(generic_args: &mut GenericArgs, vis: &
582582
match generic_args {
583583
GenericArgs::AngleBracketed(data) => vis.visit_angle_bracketed_parameter_data(data),
584584
GenericArgs::Parenthesized(data) => vis.visit_parenthesized_parameter_data(data),
585+
GenericArgs::ParenthesizedElided(span) => vis.visit_span(span),
585586
}
586587
}
587588

compiler/rustc_ast/src/util/classify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,6 @@ fn path_return_type(path: &ast::Path) -> Option<&ast::Ty> {
234234
ast::FnRetTy::Default(_) => None,
235235
ast::FnRetTy::Ty(ret) => Some(ret),
236236
},
237-
ast::GenericArgs::AngleBracketed(_) => None,
237+
ast::GenericArgs::AngleBracketed(_) | ast::GenericArgs::ParenthesizedElided(_) => None,
238238
}
239239
}

compiler/rustc_ast/src/visit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ where
609609
walk_list!(visitor, visit_ty, inputs);
610610
try_visit!(visitor.visit_fn_ret_ty(output));
611611
}
612+
GenericArgs::ParenthesizedElided(_span) => {}
612613
}
613614
V::Result::output()
614615
}

compiler/rustc_ast_lowering/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ ast_lowering_bad_return_type_notation_inputs =
3636
argument types not allowed with return type notation
3737
.suggestion = remove the input types
3838
39+
ast_lowering_bad_return_type_notation_needs_dots = return type notation arguments must be elided with `..`
40+
.suggestion = add `..`
41+
3942
ast_lowering_bad_return_type_notation_output =
4043
return type not allowed with return type notation
4144
.suggestion = remove the return type

compiler/rustc_ast_lowering/src/errors.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,12 @@ pub enum BadReturnTypeNotation {
393393
#[suggestion(code = "", applicability = "maybe-incorrect")]
394394
span: Span,
395395
},
396+
#[diag(ast_lowering_bad_return_type_notation_needs_dots)]
397+
NeedsDots {
398+
#[primary_span]
399+
#[suggestion(code = "(..)", applicability = "maybe-incorrect")]
400+
span: Span,
401+
},
396402
}
397403

398404
#[derive(Diagnostic)]

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -979,20 +979,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
979979
self.lower_angle_bracketed_parameter_data(data, ParamMode::Explicit, itctx).0
980980
}
981981
GenericArgs::Parenthesized(data) => {
982-
if data.inputs.is_empty() && matches!(data.output, FnRetTy::Default(..)) {
983-
let parenthesized = if self.tcx.features().return_type_notation {
984-
hir::GenericArgsParentheses::ReturnTypeNotation
985-
} else {
986-
self.emit_bad_parenthesized_trait_in_assoc_ty(data);
987-
hir::GenericArgsParentheses::No
988-
};
989-
GenericArgsCtor {
990-
args: Default::default(),
991-
constraints: &[],
992-
parenthesized,
993-
span: data.inputs_span,
994-
}
995-
} else if let Some(first_char) = constraint.ident.as_str().chars().next()
982+
if let Some(first_char) = constraint.ident.as_str().chars().next()
996983
&& first_char.is_ascii_lowercase()
997984
{
998985
let mut err = if !data.inputs.is_empty() {
@@ -1004,7 +991,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1004991
span: data.inputs_span.shrink_to_hi().to(ty.span),
1005992
})
1006993
} else {
1007-
unreachable!("inputs are empty and return type is not provided")
994+
self.dcx().create_err(errors::BadReturnTypeNotation::NeedsDots {
995+
span: data.inputs_span,
996+
})
1008997
};
1009998
if !self.tcx.features().return_type_notation
1010999
&& self.tcx.sess.is_nightly_build()
@@ -1034,6 +1023,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10341023
.0
10351024
}
10361025
}
1026+
GenericArgs::ParenthesizedElided(span) => GenericArgsCtor {
1027+
args: Default::default(),
1028+
constraints: &[],
1029+
parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
1030+
span: *span,
1031+
},
10371032
};
10381033
gen_args_ctor.into_generic_args(self)
10391034
} else {

compiler/rustc_ast_lowering/src/path.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
276276
)
277277
}
278278
},
279+
GenericArgs::ParenthesizedElided(_span) => {
280+
todo!()
281+
}
279282
}
280283
} else {
281284
(

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12891289
self.with_impl_trait(None, |this| this.visit_ty(ty));
12901290
}
12911291
}
1292+
GenericArgs::ParenthesizedElided(_span) => {}
12921293
}
12931294
}
12941295

@@ -1445,7 +1446,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
14451446
span: args.span,
14461447
});
14471448
}
1448-
None => {}
1449+
Some(ast::GenericArgs::ParenthesizedElided(_)) | None => {}
14491450
}
14501451
}
14511452
}
@@ -1693,7 +1694,9 @@ fn deny_equality_constraints(
16931694
// Add `<Bar = RhsTy>` to `Foo`.
16941695
match &mut assoc_path.segments[len].args {
16951696
Some(args) => match args.deref_mut() {
1696-
GenericArgs::Parenthesized(_) => continue,
1697+
GenericArgs::Parenthesized(_) | GenericArgs::ParenthesizedElided(..) => {
1698+
continue;
1699+
}
16971700
GenericArgs::AngleBracketed(args) => {
16981701
args.args.push(arg);
16991702
}

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_ast as ast;
22
use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor};
3-
use rustc_ast::{attr, AssocItemConstraint, AssocItemConstraintKind, NodeId};
3+
use rustc_ast::{attr, NodeId};
44
use rustc_ast::{token, PatKind};
55
use rustc_feature::{AttributeGate, BuiltinAttribute, Features, GateIssue, BUILTIN_ATTRIBUTE_MAP};
66
use rustc_session::parse::{feature_err, feature_err_issue, feature_warn};
@@ -445,23 +445,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
445445
visit::walk_fn(self, fn_kind)
446446
}
447447

448-
fn visit_assoc_item_constraint(&mut self, constraint: &'a AssocItemConstraint) {
449-
if let AssocItemConstraintKind::Bound { .. } = constraint.kind
450-
&& let Some(ast::GenericArgs::Parenthesized(args)) = constraint.gen_args.as_ref()
451-
&& args.inputs.is_empty()
452-
&& let ast::FnRetTy::Default(..) = args.output
453-
{
454-
gate!(
455-
&self,
456-
return_type_notation,
457-
constraint.span,
458-
"return type notation is experimental"
459-
);
460-
}
461-
462-
visit::walk_assoc_item_constraint(self, constraint)
463-
}
464-
465448
fn visit_assoc_item(&mut self, i: &'a ast::AssocItem, ctxt: AssocCtxt) {
466449
let is_fn = match &i.kind {
467450
ast::AssocItemKind::Fn(_) => true,
@@ -566,6 +549,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
566549
unsafe_extern_blocks,
567550
"`unsafe extern {}` blocks and `safe` keyword are experimental"
568551
);
552+
gate_all!(return_type_notation, "return type notation is experimental");
569553

570554
if !visitor.features.never_patterns {
571555
if let Some(spans) = spans.get(&sym::never_patterns) {
@@ -611,10 +595,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
611595

612596
gate_all_legacy_dont_use!(box_patterns, "box pattern syntax is experimental");
613597
gate_all_legacy_dont_use!(trait_alias, "trait aliases are experimental");
614-
// Despite being a new feature, `where T: Trait<Assoc(): Sized>`, which is RTN syntax now,
615-
// used to be gated under associated_type_bounds, which are right above, so RTN needs to
616-
// be too.
617-
gate_all_legacy_dont_use!(return_type_notation, "return type notation is experimental");
618598
gate_all_legacy_dont_use!(decl_macro, "`macro` is experimental");
619599
gate_all_legacy_dont_use!(try_blocks, "`try` blocks are unstable");
620600
gate_all_legacy_dont_use!(auto_traits, "`auto` traits are unstable");

0 commit comments

Comments
 (0)