Skip to content

Commit 08e37fe

Browse files
authored
Unrolled build for rust-lang#127092
Rollup merge of rust-lang#127092 - compiler-errors:rtn-dots-redux, r=estebank Change return-type-notation to use `(..)` Aligns the syntax with the current wording of [RFC 3654](rust-lang/rfcs#3654). Also implements rustfmt support (along with making a match exhaustive). Tracking: * rust-lang#109417
2 parents aa1d4f6 + 99365a5 commit 08e37fe

Some content is hidden

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

51 files changed

+248
-179
lines changed

compiler/rustc_ast/src/ast.rs

+4-1
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

+1
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,6 @@ fn path_return_type(path: &ast::Path) -> Option<&ast::Ty> {
311311
ast::FnRetTy::Default(_) => None,
312312
ast::FnRetTy::Ty(ret) => Some(ret),
313313
},
314-
ast::GenericArgs::AngleBracketed(_) => None,
314+
ast::GenericArgs::AngleBracketed(_) | ast::GenericArgs::ParenthesizedElided(_) => None,
315315
}
316316
}

compiler/rustc_ast/src/visit.rs

+1
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

+5
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,15 @@ 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
4245
46+
ast_lowering_bad_return_type_notation_position = return type notation not allowed in this position yet
47+
4348
ast_lowering_base_expression_double_dot =
4449
base expression required after `..`
4550
.suggestion = add a base expression here

compiler/rustc_ast_lowering/src/errors.rs

+11
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,17 @@ 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+
},
402+
#[diag(ast_lowering_bad_return_type_notation_position)]
403+
Position {
404+
#[primary_span]
405+
span: Span,
406+
},
396407
}
397408

398409
#[derive(Diagnostic)]

compiler/rustc_ast_lowering/src/lib.rs

+10-15
Original file line numberDiff line numberDiff line change
@@ -985,20 +985,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
985985
self.lower_angle_bracketed_parameter_data(data, ParamMode::Explicit, itctx).0
986986
}
987987
GenericArgs::Parenthesized(data) => {
988-
if data.inputs.is_empty() && matches!(data.output, FnRetTy::Default(..)) {
989-
let parenthesized = if self.tcx.features().return_type_notation {
990-
hir::GenericArgsParentheses::ReturnTypeNotation
991-
} else {
992-
self.emit_bad_parenthesized_trait_in_assoc_ty(data);
993-
hir::GenericArgsParentheses::No
994-
};
995-
GenericArgsCtor {
996-
args: Default::default(),
997-
constraints: &[],
998-
parenthesized,
999-
span: data.inputs_span,
1000-
}
1001-
} else if let Some(first_char) = constraint.ident.as_str().chars().next()
988+
if let Some(first_char) = constraint.ident.as_str().chars().next()
1002989
&& first_char.is_ascii_lowercase()
1003990
{
1004991
let mut err = if !data.inputs.is_empty() {
@@ -1010,7 +997,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1010997
span: data.inputs_span.shrink_to_hi().to(ty.span),
1011998
})
1012999
} else {
1013-
unreachable!("inputs are empty and return type is not provided")
1000+
self.dcx().create_err(errors::BadReturnTypeNotation::NeedsDots {
1001+
span: data.inputs_span,
1002+
})
10141003
};
10151004
if !self.tcx.features().return_type_notation
10161005
&& self.tcx.sess.is_nightly_build()
@@ -1040,6 +1029,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10401029
.0
10411030
}
10421031
}
1032+
GenericArgs::ParenthesizedElided(span) => GenericArgsCtor {
1033+
args: Default::default(),
1034+
constraints: &[],
1035+
parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
1036+
span: *span,
1037+
},
10431038
};
10441039
gen_args_ctor.into_generic_args(self)
10451040
} else {

compiler/rustc_ast_lowering/src/path.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::ImplTraitPosition;
22

33
use super::errors::{
4-
AsyncBoundNotOnTrait, AsyncBoundOnlyForFnTraits, GenericTypeWithParentheses, UseAngleBrackets,
4+
AsyncBoundNotOnTrait, AsyncBoundOnlyForFnTraits, BadReturnTypeNotation,
5+
GenericTypeWithParentheses, UseAngleBrackets,
56
};
67
use super::ResolverAstLoweringExt;
78
use super::{GenericArgsCtor, LifetimeRes, ParenthesizedGenericArgs};
@@ -271,6 +272,18 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
271272
)
272273
}
273274
},
275+
GenericArgs::ParenthesizedElided(span) => {
276+
self.dcx().emit_err(BadReturnTypeNotation::Position { span: *span });
277+
(
278+
GenericArgsCtor {
279+
args: Default::default(),
280+
constraints: &[],
281+
parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
282+
span: *span,
283+
},
284+
false,
285+
)
286+
}
274287
}
275288
} else {
276289
(

compiler/rustc_ast_passes/src/ast_validation.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13121312
self.with_impl_trait(None, |this| this.visit_ty(ty));
13131313
}
13141314
}
1315+
GenericArgs::ParenthesizedElided(_span) => {}
13151316
}
13161317
}
13171318

@@ -1468,7 +1469,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
14681469
span: args.span,
14691470
});
14701471
}
1471-
None => {}
1472+
Some(ast::GenericArgs::ParenthesizedElided(_)) | None => {}
14721473
}
14731474
}
14741475
}
@@ -1716,7 +1717,9 @@ fn deny_equality_constraints(
17161717
// Add `<Bar = RhsTy>` to `Foo`.
17171718
match &mut assoc_path.segments[len].args {
17181719
Some(args) => match args.deref_mut() {
1719-
GenericArgs::Parenthesized(_) => continue,
1720+
GenericArgs::Parenthesized(_) | GenericArgs::ParenthesizedElided(..) => {
1721+
continue;
1722+
}
17201723
GenericArgs::AngleBracketed(args) => {
17211724
args.args.push(arg);
17221725
}

compiler/rustc_ast_passes/src/feature_gate.rs

+2-22
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");

compiler/rustc_ast_pretty/src/pprust/state.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,11 @@ impl<'a> PrintState<'a> for State<'a> {
10601060
self.word(")");
10611061
self.print_fn_ret_ty(&data.output);
10621062
}
1063+
ast::GenericArgs::ParenthesizedElided(_) => {
1064+
self.word("(");
1065+
self.word("..");
1066+
self.word(")");
1067+
}
10631068
}
10641069
}
10651070
}

compiler/rustc_hir/src/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2414,7 +2414,7 @@ pub enum ImplItemKind<'hir> {
24142414
/// * the `A: Bound` in `Trait<A: Bound>`
24152415
/// * the `RetTy` in `Trait(ArgTy, ArgTy) -> RetTy`
24162416
/// * the `C = { Ct }` in `Trait<C = { Ct }>` (feature `associated_const_equality`)
2417-
/// * the `f(): Bound` in `Trait<f(): Bound>` (feature `return_type_notation`)
2417+
/// * the `f(..): Bound` in `Trait<f(..): Bound>` (feature `return_type_notation`)
24182418
#[derive(Debug, Clone, Copy, HashStable_Generic)]
24192419
pub struct AssocItemConstraint<'hir> {
24202420
pub hir_id: HirId,

compiler/rustc_parse/messages.ftl

-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ parse_bad_assoc_type_bounds = bounds on associated types do not belong here
4545
parse_bad_item_kind = {$descr} is not supported in {$ctx}
4646
.help = consider moving the {$descr} out to a nearby module scope
4747
48-
parse_bad_return_type_notation_dotdot =
49-
return type notation uses `()` instead of `(..)` for elided arguments
50-
.suggestion = remove the `..`
51-
5248
parse_bad_return_type_notation_output =
5349
return type not allowed with return type notation
5450
.suggestion = remove the return type

compiler/rustc_parse/src/errors.rs

-8
Original file line numberDiff line numberDiff line change
@@ -2567,14 +2567,6 @@ pub(crate) struct BadReturnTypeNotationOutput {
25672567
pub span: Span,
25682568
}
25692569

2570-
#[derive(Diagnostic)]
2571-
#[diag(parse_bad_return_type_notation_dotdot)]
2572-
pub(crate) struct BadReturnTypeNotationDotDot {
2573-
#[primary_span]
2574-
#[suggestion(code = "", applicability = "maybe-incorrect")]
2575-
pub span: Span,
2576-
}
2577-
25782570
#[derive(Diagnostic)]
25792571
#[diag(parse_bad_assoc_type_bounds)]
25802572
pub(crate) struct BadAssocTypeBounds {

compiler/rustc_parse/src/parser/path.rs

+6-21
Original file line numberDiff line numberDiff line change
@@ -353,32 +353,25 @@ impl<'a> Parser<'a> {
353353
})?;
354354
let span = lo.to(self.prev_token.span);
355355
AngleBracketedArgs { args, span }.into()
356-
} else if self.may_recover()
357-
&& self.token.kind == token::OpenDelim(Delimiter::Parenthesis)
356+
} else if self.token.kind == token::OpenDelim(Delimiter::Parenthesis)
358357
// FIXME(return_type_notation): Could also recover `...` here.
359358
&& self.look_ahead(1, |tok| tok.kind == token::DotDot)
360359
{
361-
self.bump();
362-
self.dcx()
363-
.emit_err(errors::BadReturnTypeNotationDotDot { span: self.token.span });
364-
self.bump();
360+
self.bump(); // (
361+
self.bump(); // ..
365362
self.expect(&token::CloseDelim(Delimiter::Parenthesis))?;
366363
let span = lo.to(self.prev_token.span);
367364

365+
self.psess.gated_spans.gate(sym::return_type_notation, span);
366+
368367
if self.eat_noexpect(&token::RArrow) {
369368
let lo = self.prev_token.span;
370369
let ty = self.parse_ty()?;
371370
self.dcx()
372371
.emit_err(errors::BadReturnTypeNotationOutput { span: lo.to(ty.span) });
373372
}
374373

375-
ParenthesizedArgs {
376-
span,
377-
inputs: ThinVec::new(),
378-
inputs_span: span,
379-
output: ast::FnRetTy::Default(self.prev_token.span.shrink_to_hi()),
380-
}
381-
.into()
374+
P(ast::GenericArgs::ParenthesizedElided(span))
382375
} else {
383376
// `(T, U) -> R`
384377

@@ -733,14 +726,6 @@ impl<'a> Parser<'a> {
733726

734727
let span = lo.to(self.prev_token.span);
735728

736-
if let AssocItemConstraintKind::Bound { .. } = kind
737-
&& let Some(ast::GenericArgs::Parenthesized(args)) = &gen_args
738-
&& args.inputs.is_empty()
739-
&& let ast::FnRetTy::Default(..) = args.output
740-
{
741-
self.psess.gated_spans.gate(sym::return_type_notation, span);
742-
}
743-
744729
let constraint =
745730
AssocItemConstraint { id: ast::DUMMY_NODE_ID, ident, gen_args, kind, span };
746731
Ok(Some(AngleBracketedArg::Constraint(constraint)))

compiler/rustc_passes/src/hir_stats.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
695695
fn visit_generic_args(&mut self, g: &'v ast::GenericArgs) {
696696
record_variants!(
697697
(self, g, g, Id::None, ast, GenericArgs, GenericArgs),
698-
[AngleBracketed, Parenthesized]
698+
[AngleBracketed, Parenthesized, ParenthesizedElided]
699699
);
700700
ast_visit::walk_generic_args(self, g)
701701
}

compiler/rustc_resolve/src/late.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
12211221
}
12221222
}
12231223
}
1224+
GenericArgs::ParenthesizedElided(_) => {}
12241225
}
12251226
}
12261227
}

compiler/rustc_resolve/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ impl<'a> From<&'a ast::PathSegment> for Segment {
350350
(args.span, found_lifetimes)
351351
}
352352
GenericArgs::Parenthesized(args) => (args.span, true),
353+
GenericArgs::ParenthesizedElided(span) => (*span, true),
353354
}
354355
} else {
355356
(DUMMY_SP, false)

src/librustdoc/clean/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2557,7 +2557,7 @@ pub(crate) struct ProcMacro {
25572557
/// * the `A: Bound` in `Trait<A: Bound>`
25582558
/// * the `RetTy` in `Trait(ArgTy, ArgTy) -> RetTy`
25592559
/// * the `C = { Ct }` in `Trait<C = { Ct }>` (feature `associated_const_equality`)
2560-
/// * the `f(): Bound` in `Trait<f(): Bound>` (feature `return_type_notation`)
2560+
/// * the `f(..): Bound` in `Trait<f(..): Bound>` (feature `return_type_notation`)
25612561
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
25622562
pub(crate) struct AssocItemConstraint {
25632563
pub(crate) assoc: PathSegment,

0 commit comments

Comments
 (0)