From b1a0c0b1231a554d4ae699221a80a6e2f81bac4d Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 28 Jun 2024 11:49:16 -0400 Subject: [PATCH 1/3] Change RTN to use .. again --- compiler/rustc_ast/src/ast.rs | 5 +++- compiler/rustc_ast/src/mut_visit.rs | 1 + compiler/rustc_ast/src/util/classify.rs | 2 +- compiler/rustc_ast/src/visit.rs | 1 + compiler/rustc_ast_lowering/messages.ftl | 3 ++ compiler/rustc_ast_lowering/src/errors.rs | 6 ++++ compiler/rustc_ast_lowering/src/lib.rs | 25 +++++++---------- compiler/rustc_ast_lowering/src/path.rs | 3 ++ .../rustc_ast_passes/src/ast_validation.rs | 7 +++-- compiler/rustc_ast_passes/src/feature_gate.rs | 24 ++-------------- compiler/rustc_ast_pretty/src/pprust/state.rs | 5 ++++ compiler/rustc_hir/src/hir.rs | 2 +- compiler/rustc_parse/messages.ftl | 4 --- compiler/rustc_parse/src/errors.rs | 8 ------ compiler/rustc_parse/src/parser/path.rs | 27 ++++-------------- compiler/rustc_passes/src/hir_stats.rs | 2 +- compiler/rustc_resolve/src/late.rs | 1 + compiler/rustc_resolve/src/lib.rs | 1 + src/librustdoc/clean/types.rs | 2 +- tests/crashes/125249.rs | 2 +- .../bad-inputs-and-output.rs | 4 +-- .../bad-inputs-and-output.stderr | 12 ++++---- .../return-type-notation/basic.rs | 2 +- .../return-type-notation/equality.rs | 2 +- .../return-type-notation/equality.stderr | 4 +-- .../issue-120208-higher-ranked-const.rs | 2 +- .../issue-120208-higher-ranked-const.stderr | 4 +-- .../return-type-notation/missing.rs | 2 +- .../return-type-notation/missing.stderr | 2 +- .../return-type-notation/non-rpitit.rs | 2 +- .../return-type-notation/non-rpitit.stderr | 4 +-- .../issue-110963-early.rs | 2 +- .../return-type-notation/issue-110963-late.rs | 2 +- ...ormalizing-self-auto-trait-issue-109924.rs | 2 +- .../rtn-implied-in-supertrait.rs | 2 +- .../rtn-in-impl-signature.rs | 2 +- .../rtn-in-impl-signature.stderr | 12 ++++---- .../super-method-bound-ambig.rs | 2 +- .../super-method-bound-ambig.stderr | 4 +-- .../super-method-bound.rs | 2 +- .../return-type-notation/supertrait-bound.rs | 2 +- .../return-type-notation/ty-or-ct-params.rs | 2 +- .../ty-or-ct-params.stderr | 10 +++---- .../ui/borrowck/alias-liveness/rtn-static.rs | 4 +-- ...ature-gate-return_type_notation.cfg.stderr | 28 +++---------------- ...eature-gate-return_type_notation.no.stderr | 13 ++++----- .../feature-gate-return_type_notation.rs | 12 ++------ 47 files changed, 109 insertions(+), 163 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index f5e79c04d78..dbbc4980050 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -176,6 +176,8 @@ pub enum GenericArgs { AngleBracketed(AngleBracketedArgs), /// The `(A, B)` and `C` in `Foo(A, B) -> C`. Parenthesized(ParenthesizedArgs), + /// `(..)` in return type notation + ParenthesizedElided(Span), } impl GenericArgs { @@ -187,6 +189,7 @@ pub fn span(&self) -> Span { match self { AngleBracketed(data) => data.span, Parenthesized(data) => data.span, + ParenthesizedElided(span) => *span, } } } @@ -2051,7 +2054,7 @@ pub fn name(&self) -> Symbol { /// * the `A: Bound` in `Trait` /// * the `RetTy` in `Trait(ArgTy, ArgTy) -> RetTy` /// * the `C = { Ct }` in `Trait` (feature `associated_const_equality`) -/// * the `f(): Bound` in `Trait` (feature `return_type_notation`) +/// * the `f(..): Bound` in `Trait` (feature `return_type_notation`) #[derive(Clone, Encodable, Decodable, Debug)] pub struct AssocItemConstraint { pub id: NodeId, diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 27e781a5a63..f816375b912 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -582,6 +582,7 @@ fn noop_visit_generic_args(generic_args: &mut GenericArgs, vis: & match generic_args { GenericArgs::AngleBracketed(data) => vis.visit_angle_bracketed_parameter_data(data), GenericArgs::Parenthesized(data) => vis.visit_parenthesized_parameter_data(data), + GenericArgs::ParenthesizedElided(span) => vis.visit_span(span), } } diff --git a/compiler/rustc_ast/src/util/classify.rs b/compiler/rustc_ast/src/util/classify.rs index 4b2544ac47e..ed64f44f726 100644 --- a/compiler/rustc_ast/src/util/classify.rs +++ b/compiler/rustc_ast/src/util/classify.rs @@ -234,6 +234,6 @@ fn path_return_type(path: &ast::Path) -> Option<&ast::Ty> { ast::FnRetTy::Default(_) => None, ast::FnRetTy::Ty(ret) => Some(ret), }, - ast::GenericArgs::AngleBracketed(_) => None, + ast::GenericArgs::AngleBracketed(_) | ast::GenericArgs::ParenthesizedElided(_) => None, } } diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index 26cb04d4d47..f6929057bed 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -609,6 +609,7 @@ pub fn walk_generic_args<'a, V>(visitor: &mut V, generic_args: &'a GenericArgs) walk_list!(visitor, visit_ty, inputs); try_visit!(visitor.visit_fn_ret_ty(output)); } + GenericArgs::ParenthesizedElided(_span) => {} } V::Result::output() } diff --git a/compiler/rustc_ast_lowering/messages.ftl b/compiler/rustc_ast_lowering/messages.ftl index 58f65f1257f..d6eb344fd1d 100644 --- a/compiler/rustc_ast_lowering/messages.ftl +++ b/compiler/rustc_ast_lowering/messages.ftl @@ -36,6 +36,9 @@ ast_lowering_bad_return_type_notation_inputs = argument types not allowed with return type notation .suggestion = remove the input types +ast_lowering_bad_return_type_notation_needs_dots = return type notation arguments must be elided with `..` + .suggestion = add `..` + ast_lowering_bad_return_type_notation_output = return type not allowed with return type notation .suggestion = remove the return type diff --git a/compiler/rustc_ast_lowering/src/errors.rs b/compiler/rustc_ast_lowering/src/errors.rs index 3d4b6a1f033..6699c6e75f5 100644 --- a/compiler/rustc_ast_lowering/src/errors.rs +++ b/compiler/rustc_ast_lowering/src/errors.rs @@ -393,6 +393,12 @@ pub enum BadReturnTypeNotation { #[suggestion(code = "", applicability = "maybe-incorrect")] span: Span, }, + #[diag(ast_lowering_bad_return_type_notation_needs_dots)] + NeedsDots { + #[primary_span] + #[suggestion(code = "(..)", applicability = "maybe-incorrect")] + span: Span, + }, } #[derive(Diagnostic)] diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 0a06304fcec..92fb5b3c2eb 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -979,20 +979,7 @@ fn lower_assoc_item_constraint( self.lower_angle_bracketed_parameter_data(data, ParamMode::Explicit, itctx).0 } GenericArgs::Parenthesized(data) => { - if data.inputs.is_empty() && matches!(data.output, FnRetTy::Default(..)) { - let parenthesized = if self.tcx.features().return_type_notation { - hir::GenericArgsParentheses::ReturnTypeNotation - } else { - self.emit_bad_parenthesized_trait_in_assoc_ty(data); - hir::GenericArgsParentheses::No - }; - GenericArgsCtor { - args: Default::default(), - constraints: &[], - parenthesized, - span: data.inputs_span, - } - } else if let Some(first_char) = constraint.ident.as_str().chars().next() + if let Some(first_char) = constraint.ident.as_str().chars().next() && first_char.is_ascii_lowercase() { let mut err = if !data.inputs.is_empty() { @@ -1004,7 +991,9 @@ fn lower_assoc_item_constraint( span: data.inputs_span.shrink_to_hi().to(ty.span), }) } else { - unreachable!("inputs are empty and return type is not provided") + self.dcx().create_err(errors::BadReturnTypeNotation::NeedsDots { + span: data.inputs_span, + }) }; if !self.tcx.features().return_type_notation && self.tcx.sess.is_nightly_build() @@ -1034,6 +1023,12 @@ fn lower_assoc_item_constraint( .0 } } + GenericArgs::ParenthesizedElided(span) => GenericArgsCtor { + args: Default::default(), + constraints: &[], + parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation, + span: *span, + }, }; gen_args_ctor.into_generic_args(self) } else { diff --git a/compiler/rustc_ast_lowering/src/path.rs b/compiler/rustc_ast_lowering/src/path.rs index 9d38e1e6784..1efa5bd3c4c 100644 --- a/compiler/rustc_ast_lowering/src/path.rs +++ b/compiler/rustc_ast_lowering/src/path.rs @@ -276,6 +276,9 @@ pub(crate) fn lower_path_segment( ) } }, + GenericArgs::ParenthesizedElided(_span) => { + todo!() + } } } else { ( diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index ba4b6130b60..c0e8c4bf977 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -1289,6 +1289,7 @@ fn visit_generic_args(&mut self, generic_args: &'a GenericArgs) { self.with_impl_trait(None, |this| this.visit_ty(ty)); } } + GenericArgs::ParenthesizedElided(_span) => {} } } @@ -1445,7 +1446,7 @@ fn visit_param_bound(&mut self, bound: &'a GenericBound, ctxt: BoundKind) { span: args.span, }); } - None => {} + Some(ast::GenericArgs::ParenthesizedElided(_)) | None => {} } } } @@ -1693,7 +1694,9 @@ fn deny_equality_constraints( // Add `` to `Foo`. match &mut assoc_path.segments[len].args { Some(args) => match args.deref_mut() { - GenericArgs::Parenthesized(_) => continue, + GenericArgs::Parenthesized(_) | GenericArgs::ParenthesizedElided(..) => { + continue; + } GenericArgs::AngleBracketed(args) => { args.args.push(arg); } diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index e1c1a027a30..9cf3182daea 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -1,6 +1,6 @@ use rustc_ast as ast; use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor}; -use rustc_ast::{attr, AssocItemConstraint, AssocItemConstraintKind, NodeId}; +use rustc_ast::{attr, NodeId}; use rustc_ast::{token, PatKind}; use rustc_feature::{AttributeGate, BuiltinAttribute, Features, GateIssue, BUILTIN_ATTRIBUTE_MAP}; use rustc_session::parse::{feature_err, feature_err_issue, feature_warn}; @@ -445,23 +445,6 @@ fn visit_fn(&mut self, fn_kind: FnKind<'a>, span: Span, _: NodeId) { visit::walk_fn(self, fn_kind) } - fn visit_assoc_item_constraint(&mut self, constraint: &'a AssocItemConstraint) { - if let AssocItemConstraintKind::Bound { .. } = constraint.kind - && let Some(ast::GenericArgs::Parenthesized(args)) = constraint.gen_args.as_ref() - && args.inputs.is_empty() - && let ast::FnRetTy::Default(..) = args.output - { - gate!( - &self, - return_type_notation, - constraint.span, - "return type notation is experimental" - ); - } - - visit::walk_assoc_item_constraint(self, constraint) - } - fn visit_assoc_item(&mut self, i: &'a ast::AssocItem, ctxt: AssocCtxt) { let is_fn = match &i.kind { ast::AssocItemKind::Fn(_) => true, @@ -566,6 +549,7 @@ macro_rules! gate_all { unsafe_extern_blocks, "`unsafe extern {}` blocks and `safe` keyword are experimental" ); + gate_all!(return_type_notation, "return type notation is experimental"); if !visitor.features.never_patterns { if let Some(spans) = spans.get(&sym::never_patterns) { @@ -611,10 +595,6 @@ macro_rules! gate_all_legacy_dont_use { gate_all_legacy_dont_use!(box_patterns, "box pattern syntax is experimental"); gate_all_legacy_dont_use!(trait_alias, "trait aliases are experimental"); - // Despite being a new feature, `where T: Trait`, which is RTN syntax now, - // used to be gated under associated_type_bounds, which are right above, so RTN needs to - // be too. - gate_all_legacy_dont_use!(return_type_notation, "return type notation is experimental"); gate_all_legacy_dont_use!(decl_macro, "`macro` is experimental"); gate_all_legacy_dont_use!(try_blocks, "`try` blocks are unstable"); gate_all_legacy_dont_use!(auto_traits, "`auto` traits are unstable"); diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 0225c95dca8..0568d368d8c 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -1060,6 +1060,11 @@ fn print_generic_args(&mut self, args: &ast::GenericArgs, colons_before_params: self.word(")"); self.print_fn_ret_ty(&data.output); } + ast::GenericArgs::ParenthesizedElided(_) => { + self.word("("); + self.word(".."); + self.word(")"); + } } } } diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 22a6c06bba3..5b126d37ed6 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -2413,7 +2413,7 @@ pub enum ImplItemKind<'hir> { /// * the `A: Bound` in `Trait` /// * the `RetTy` in `Trait(ArgTy, ArgTy) -> RetTy` /// * the `C = { Ct }` in `Trait` (feature `associated_const_equality`) -/// * the `f(): Bound` in `Trait` (feature `return_type_notation`) +/// * the `f(..): Bound` in `Trait` (feature `return_type_notation`) #[derive(Debug, Clone, Copy, HashStable_Generic)] pub struct AssocItemConstraint<'hir> { pub hir_id: HirId, diff --git a/compiler/rustc_parse/messages.ftl b/compiler/rustc_parse/messages.ftl index f08efe60d96..e4c75ac1145 100644 --- a/compiler/rustc_parse/messages.ftl +++ b/compiler/rustc_parse/messages.ftl @@ -45,10 +45,6 @@ parse_bad_assoc_type_bounds = bounds on associated types do not belong here parse_bad_item_kind = {$descr} is not supported in {$ctx} .help = consider moving the {$descr} out to a nearby module scope -parse_bad_return_type_notation_dotdot = - return type notation uses `()` instead of `(..)` for elided arguments - .suggestion = remove the `..` - parse_bad_return_type_notation_output = return type not allowed with return type notation .suggestion = remove the return type diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 8d49887f164..6894f470d88 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -2567,14 +2567,6 @@ pub(crate) struct BadReturnTypeNotationOutput { 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, -} - #[derive(Diagnostic)] #[diag(parse_bad_assoc_type_bounds)] pub(crate) struct BadAssocTypeBounds { diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index da8d1194325..03c647dd527 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -353,18 +353,17 @@ pub(super) fn parse_path_segment( })?; let span = lo.to(self.prev_token.span); AngleBracketedArgs { args, span }.into() - } else if self.may_recover() - && self.token.kind == token::OpenDelim(Delimiter::Parenthesis) + } 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) { - self.bump(); - self.dcx() - .emit_err(errors::BadReturnTypeNotationDotDot { span: self.token.span }); - self.bump(); + self.bump(); // ( + self.bump(); // .. self.expect(&token::CloseDelim(Delimiter::Parenthesis))?; let span = lo.to(self.prev_token.span); + self.psess.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()?; @@ -372,13 +371,7 @@ pub(super) fn parse_path_segment( .emit_err(errors::BadReturnTypeNotationOutput { span: lo.to(ty.span) }); } - ParenthesizedArgs { - span, - inputs: ThinVec::new(), - inputs_span: span, - output: ast::FnRetTy::Default(self.prev_token.span.shrink_to_hi()), - } - .into() + P(ast::GenericArgs::ParenthesizedElided(span)) } else { // `(T, U) -> R` @@ -733,14 +726,6 @@ fn parse_angle_arg( let span = lo.to(self.prev_token.span); - if let AssocItemConstraintKind::Bound { .. } = kind - && let Some(ast::GenericArgs::Parenthesized(args)) = &gen_args - && args.inputs.is_empty() - && let ast::FnRetTy::Default(..) = args.output - { - self.psess.gated_spans.gate(sym::return_type_notation, span); - } - let constraint = AssocItemConstraint { id: ast::DUMMY_NODE_ID, ident, gen_args, kind, span }; Ok(Some(AngleBracketedArg::Constraint(constraint))) diff --git a/compiler/rustc_passes/src/hir_stats.rs b/compiler/rustc_passes/src/hir_stats.rs index 0ba61f8e8b4..0720efebf97 100644 --- a/compiler/rustc_passes/src/hir_stats.rs +++ b/compiler/rustc_passes/src/hir_stats.rs @@ -695,7 +695,7 @@ fn visit_path_segment(&mut self, path_segment: &'v ast::PathSegment) { fn visit_generic_args(&mut self, g: &'v ast::GenericArgs) { record_variants!( (self, g, g, Id::None, ast, GenericArgs, GenericArgs), - [AngleBracketed, Parenthesized] + [AngleBracketed, Parenthesized, ParenthesizedElided] ); ast_visit::walk_generic_args(self, g) } diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 66a1c05289b..ad4e222f4de 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -1221,6 +1221,7 @@ fn visit_path_segment(&mut self, path_segment: &'ast PathSegment) { } } } + GenericArgs::ParenthesizedElided(_) => {} } } } diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 94cdce1025f..38963ef4ef0 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -350,6 +350,7 @@ fn from(seg: &'a ast::PathSegment) -> Segment { (args.span, found_lifetimes) } GenericArgs::Parenthesized(args) => (args.span, true), + GenericArgs::ParenthesizedElided(span) => (*span, true), } } else { (DUMMY_SP, false) diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index c4020f2a450..ddc3dd4270f 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -2557,7 +2557,7 @@ pub(crate) struct ProcMacro { /// * the `A: Bound` in `Trait` /// * the `RetTy` in `Trait(ArgTy, ArgTy) -> RetTy` /// * the `C = { Ct }` in `Trait` (feature `associated_const_equality`) -/// * the `f(): Bound` in `Trait` (feature `return_type_notation`) +/// * the `f(..): Bound` in `Trait` (feature `return_type_notation`) #[derive(Clone, PartialEq, Eq, Debug, Hash)] pub(crate) struct AssocItemConstraint { pub(crate) assoc: PathSegment, diff --git a/tests/crashes/125249.rs b/tests/crashes/125249.rs index 18196d7b34f..1cf6338a0d6 100644 --- a/tests/crashes/125249.rs +++ b/tests/crashes/125249.rs @@ -2,7 +2,7 @@ #![feature(return_position_impl_trait_in_trait, return_type_notation)] trait IntFactory { - fn stream(&self) -> impl IntFactory + Send>; + fn stream(&self) -> impl IntFactory + Send>; } pub fn main() {} diff --git a/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.rs b/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.rs index c23eff79ce2..a8c8a85c5aa 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.rs +++ b/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.rs @@ -13,7 +13,7 @@ fn foo>() {} fn bar (): Send>>() {} //~^ ERROR return type not allowed with return type notation -fn baz>() {} -//~^ ERROR return type notation uses `()` instead of `(..)` for elided arguments +fn baz>() {} +//~^ ERROR return type notation arguments must be elided with `..` fn main() {} diff --git a/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.stderr b/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.stderr index d95249efe40..7e1695984f1 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.stderr +++ b/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.stderr @@ -1,9 +1,3 @@ -error: return type notation uses `()` instead of `(..)` for elided arguments - --> $DIR/bad-inputs-and-output.rs:16:24 - | -LL | fn baz>() {} - | ^^ help: remove the `..` - warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes --> $DIR/bad-inputs-and-output.rs:3:12 | @@ -25,5 +19,11 @@ error: return type not allowed with return type notation LL | fn bar (): Send>>() {} | ^^^^^^ help: remove the return type +error: return type notation arguments must be elided with `..` + --> $DIR/bad-inputs-and-output.rs:16:23 + | +LL | fn baz>() {} + | ^^ help: add `..`: `(..)` + error: aborting due to 3 previous errors; 1 warning emitted diff --git a/tests/ui/associated-type-bounds/return-type-notation/basic.rs b/tests/ui/associated-type-bounds/return-type-notation/basic.rs index 9755fd01c97..be489a19a7a 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/basic.rs +++ b/tests/ui/associated-type-bounds/return-type-notation/basic.rs @@ -17,7 +17,7 @@ async fn foo() -> Result<(), ()> { fn is_send(_: impl Send) {} fn test< - #[cfg(with)] T: Foo, + #[cfg(with)] T: Foo, #[cfg(without)] T: Foo, >() { is_send(foo::()); diff --git a/tests/ui/associated-type-bounds/return-type-notation/equality.rs b/tests/ui/associated-type-bounds/return-type-notation/equality.rs index ae38dce1818..95c16fa1e3f 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/equality.rs +++ b/tests/ui/associated-type-bounds/return-type-notation/equality.rs @@ -9,7 +9,7 @@ trait Trait { async fn method() {} } -fn test>>>() {} +fn test>>>() {} //~^ ERROR return type notation is not allowed to use type equality fn main() {} diff --git a/tests/ui/associated-type-bounds/return-type-notation/equality.stderr b/tests/ui/associated-type-bounds/return-type-notation/equality.stderr index d432e957735..d76b1bd1c05 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/equality.stderr +++ b/tests/ui/associated-type-bounds/return-type-notation/equality.stderr @@ -10,8 +10,8 @@ LL | #![feature(return_type_notation)] error: return type notation is not allowed to use type equality --> $DIR/equality.rs:12:18 | -LL | fn test>>>() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | fn test>>>() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error; 1 warning emitted diff --git a/tests/ui/associated-type-bounds/return-type-notation/issue-120208-higher-ranked-const.rs b/tests/ui/associated-type-bounds/return-type-notation/issue-120208-higher-ranked-const.rs index 11728b87990..4d026b7d1d8 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/issue-120208-higher-ranked-const.rs +++ b/tests/ui/associated-type-bounds/return-type-notation/issue-120208-higher-ranked-const.rs @@ -9,7 +9,7 @@ trait HealthCheck { async fn do_health_check_par(hc: HC) where - HC: HealthCheck + Send + 'static, + HC: HealthCheck + Send + 'static, //~^ ERROR return type notation is not allowed for functions that have const parameters { } diff --git a/tests/ui/associated-type-bounds/return-type-notation/issue-120208-higher-ranked-const.stderr b/tests/ui/associated-type-bounds/return-type-notation/issue-120208-higher-ranked-const.stderr index 8a3f037d003..12f32a75eda 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/issue-120208-higher-ranked-const.stderr +++ b/tests/ui/associated-type-bounds/return-type-notation/issue-120208-higher-ranked-const.stderr @@ -13,8 +13,8 @@ error: return type notation is not allowed for functions that have const paramet LL | async fn check() -> bool; | -------------- const parameter declared here ... -LL | HC: HealthCheck + Send + 'static, - | ^^^^^^^^^^^^^ +LL | HC: HealthCheck + Send + 'static, + | ^^^^^^^^^^^^^^^ error: aborting due to 1 previous error; 1 warning emitted diff --git a/tests/ui/associated-type-bounds/return-type-notation/missing.rs b/tests/ui/associated-type-bounds/return-type-notation/missing.rs index 9a8b77d00b7..3a04a56339b 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/missing.rs +++ b/tests/ui/associated-type-bounds/return-type-notation/missing.rs @@ -7,7 +7,7 @@ trait Trait { async fn method() {} } -fn bar>() {} +fn bar>() {} //~^ ERROR associated function `methid` not found for `Trait` fn main() {} diff --git a/tests/ui/associated-type-bounds/return-type-notation/missing.stderr b/tests/ui/associated-type-bounds/return-type-notation/missing.stderr index db9cb9f49a3..5cb8e2642f5 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/missing.stderr +++ b/tests/ui/associated-type-bounds/return-type-notation/missing.stderr @@ -10,7 +10,7 @@ LL | #![feature(return_type_notation)] error[E0220]: associated function `methid` not found for `Trait` --> $DIR/missing.rs:10:17 | -LL | fn bar>() {} +LL | fn bar>() {} | ^^^^^^ help: there is an associated function with a similar name: `method` error: aborting due to 1 previous error; 1 warning emitted diff --git a/tests/ui/associated-type-bounds/return-type-notation/non-rpitit.rs b/tests/ui/associated-type-bounds/return-type-notation/non-rpitit.rs index db5f6fe389e..d283c6eab37 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/non-rpitit.rs +++ b/tests/ui/associated-type-bounds/return-type-notation/non-rpitit.rs @@ -5,7 +5,7 @@ trait Trait { fn method() {} } -fn test>() {} +fn test>() {} //~^ ERROR return type notation used on function that is not `async` and does not return `impl Trait` fn main() {} diff --git a/tests/ui/associated-type-bounds/return-type-notation/non-rpitit.stderr b/tests/ui/associated-type-bounds/return-type-notation/non-rpitit.stderr index 3e307c5f42c..79ced3c96ed 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/non-rpitit.stderr +++ b/tests/ui/associated-type-bounds/return-type-notation/non-rpitit.stderr @@ -13,8 +13,8 @@ error: return type notation used on function that is not `async` and does not re LL | fn method() {} | ----------- this function must be `async` or return `impl Trait` ... -LL | fn test>() {} - | ^^^^^^^^^^^^^^ +LL | fn test>() {} + | ^^^^^^^^^^^^^^^^ | = note: function returns `()`, which is not compatible with associated type return bounds diff --git a/tests/ui/async-await/return-type-notation/issue-110963-early.rs b/tests/ui/async-await/return-type-notation/issue-110963-early.rs index 4090912f528..46b8fbf6f86 100644 --- a/tests/ui/async-await/return-type-notation/issue-110963-early.rs +++ b/tests/ui/async-await/return-type-notation/issue-110963-early.rs @@ -9,7 +9,7 @@ trait HealthCheck { async fn do_health_check_par(hc: HC) where - HC: HealthCheck + Send + 'static, + HC: HealthCheck + Send + 'static, { spawn(async move { let mut hc = hc; diff --git a/tests/ui/async-await/return-type-notation/issue-110963-late.rs b/tests/ui/async-await/return-type-notation/issue-110963-late.rs index e0e59b6c6ad..cb9c0b97f1e 100644 --- a/tests/ui/async-await/return-type-notation/issue-110963-late.rs +++ b/tests/ui/async-await/return-type-notation/issue-110963-late.rs @@ -10,7 +10,7 @@ trait HealthCheck { async fn do_health_check_par(hc: HC) where - HC: HealthCheck + Send + 'static, + HC: HealthCheck + Send + 'static, { spawn(async move { let mut hc = hc; diff --git a/tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.rs b/tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.rs index bee9ad2516e..24041ed0807 100644 --- a/tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.rs +++ b/tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.rs @@ -16,7 +16,7 @@ impl Foo for Bar { async fn bar(&self) {} } -fn build(_: T) where T: Foo {} +fn build(_: T) where T: Foo {} fn main() { build(Bar); diff --git a/tests/ui/async-await/return-type-notation/rtn-implied-in-supertrait.rs b/tests/ui/async-await/return-type-notation/rtn-implied-in-supertrait.rs index 365ca574006..2f6e04c3853 100644 --- a/tests/ui/async-await/return-type-notation/rtn-implied-in-supertrait.rs +++ b/tests/ui/async-await/return-type-notation/rtn-implied-in-supertrait.rs @@ -16,7 +16,7 @@ trait Foo { async fn bar(&self) -> i32; } -trait SendFoo: Foo + Send {} +trait SendFoo: Foo + Send {} fn foobar(foo: impl SendFoo) -> JoinHandle { spawn(async move { diff --git a/tests/ui/async-await/return-type-notation/rtn-in-impl-signature.rs b/tests/ui/async-await/return-type-notation/rtn-in-impl-signature.rs index 637678692bd..1e971d0aea7 100644 --- a/tests/ui/async-await/return-type-notation/rtn-in-impl-signature.rs +++ b/tests/ui/async-await/return-type-notation/rtn-in-impl-signature.rs @@ -7,7 +7,7 @@ trait Super1<'a> { fn bar<'b>() -> bool; } -impl Super1<'_, bar(): Send> for () {} +impl Super1<'_, bar(..): Send> for () {} //~^ ERROR associated item constraints are not allowed here //~| ERROR not all trait items implemented diff --git a/tests/ui/async-await/return-type-notation/rtn-in-impl-signature.stderr b/tests/ui/async-await/return-type-notation/rtn-in-impl-signature.stderr index 54960ae60bc..b23dbc37a55 100644 --- a/tests/ui/async-await/return-type-notation/rtn-in-impl-signature.stderr +++ b/tests/ui/async-await/return-type-notation/rtn-in-impl-signature.stderr @@ -10,13 +10,13 @@ LL | #![feature(return_type_notation)] error[E0229]: associated item constraints are not allowed here --> $DIR/rtn-in-impl-signature.rs:10:17 | -LL | impl Super1<'_, bar(): Send> for () {} - | ^^^^^^^^^^^ associated item constraint not allowed here +LL | impl Super1<'_, bar(..): Send> for () {} + | ^^^^^^^^^^^^^ associated item constraint not allowed here | help: consider removing this associated item constraint | -LL | impl Super1<'_, bar(): Send> for () {} - | ~~~~~~~~~~~~~ +LL | impl Super1<'_, bar(..): Send> for () {} + | ~~~~~~~~~~~~~~~ error[E0046]: not all trait items implemented, missing: `bar` --> $DIR/rtn-in-impl-signature.rs:10:1 @@ -24,8 +24,8 @@ error[E0046]: not all trait items implemented, missing: `bar` LL | fn bar<'b>() -> bool; | --------------------- `bar` from trait ... -LL | impl Super1<'_, bar(): Send> for () {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `bar` in implementation +LL | impl Super1<'_, bar(..): Send> for () {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `bar` in implementation error: aborting due to 2 previous errors; 1 warning emitted diff --git a/tests/ui/async-await/return-type-notation/super-method-bound-ambig.rs b/tests/ui/async-await/return-type-notation/super-method-bound-ambig.rs index fa647ea0bc7..452568f3e46 100644 --- a/tests/ui/async-await/return-type-notation/super-method-bound-ambig.rs +++ b/tests/ui/async-await/return-type-notation/super-method-bound-ambig.rs @@ -22,7 +22,7 @@ impl Foo for () {} fn test() where - T: Foo, + T: Foo, //~^ ERROR ambiguous associated function `test` in bounds of `Foo` { } diff --git a/tests/ui/async-await/return-type-notation/super-method-bound-ambig.stderr b/tests/ui/async-await/return-type-notation/super-method-bound-ambig.stderr index 4003aad6d03..9a6fdd7f2ac 100644 --- a/tests/ui/async-await/return-type-notation/super-method-bound-ambig.stderr +++ b/tests/ui/async-await/return-type-notation/super-method-bound-ambig.stderr @@ -16,8 +16,8 @@ LL | async fn test(); LL | async fn test(); | ---------------- ambiguous `test` from `Super2` ... -LL | T: Foo, - | ^^^^^^^^^^^^ ambiguous associated function `test` +LL | T: Foo, + | ^^^^^^^^^^^^^^ ambiguous associated function `test` error: aborting due to 1 previous error; 1 warning emitted diff --git a/tests/ui/async-await/return-type-notation/super-method-bound.rs b/tests/ui/async-await/return-type-notation/super-method-bound.rs index ad7ed5b283c..1aa8258a09b 100644 --- a/tests/ui/async-await/return-type-notation/super-method-bound.rs +++ b/tests/ui/async-await/return-type-notation/super-method-bound.rs @@ -16,7 +16,7 @@ impl Foo for () {} fn test() where - T: Foo, + T: Foo, { } diff --git a/tests/ui/async-await/return-type-notation/supertrait-bound.rs b/tests/ui/async-await/return-type-notation/supertrait-bound.rs index adb286a21d2..9c74c10b333 100644 --- a/tests/ui/async-await/return-type-notation/supertrait-bound.rs +++ b/tests/ui/async-await/return-type-notation/supertrait-bound.rs @@ -6,6 +6,6 @@ trait IntFactory { fn stream(&self) -> impl Iterator; } -trait SendIntFactory: IntFactory + Send {} +trait SendIntFactory: IntFactory + Send {} fn main() {} diff --git a/tests/ui/async-await/return-type-notation/ty-or-ct-params.rs b/tests/ui/async-await/return-type-notation/ty-or-ct-params.rs index 328cd8d2ad0..06a966df445 100644 --- a/tests/ui/async-await/return-type-notation/ty-or-ct-params.rs +++ b/tests/ui/async-await/return-type-notation/ty-or-ct-params.rs @@ -11,7 +11,7 @@ async fn baz() {} fn test() where - T: Foo, + T: Foo, //~^ ERROR return type notation is not allowed for functions that have const parameters //~| ERROR return type notation is not allowed for functions that have type parameters { diff --git a/tests/ui/async-await/return-type-notation/ty-or-ct-params.stderr b/tests/ui/async-await/return-type-notation/ty-or-ct-params.stderr index da94d9d1e6d..1c000bc6c33 100644 --- a/tests/ui/async-await/return-type-notation/ty-or-ct-params.stderr +++ b/tests/ui/async-await/return-type-notation/ty-or-ct-params.stderr @@ -13,17 +13,17 @@ error: return type notation is not allowed for functions that have type paramete LL | async fn bar() {} | - type parameter declared here ... -LL | T: Foo, - | ^^^^^^^^^^^ +LL | T: Foo, + | ^^^^^^^^^^^^^ error: return type notation is not allowed for functions that have const parameters - --> $DIR/ty-or-ct-params.rs:14:25 + --> $DIR/ty-or-ct-params.rs:14:27 | LL | async fn baz() {} | -------------- const parameter declared here ... -LL | T: Foo, - | ^^^^^^^^^^^ +LL | T: Foo, + | ^^^^^^^^^^^^^ error: aborting due to 2 previous errors; 1 warning emitted diff --git a/tests/ui/borrowck/alias-liveness/rtn-static.rs b/tests/ui/borrowck/alias-liveness/rtn-static.rs index 37f634a8e23..6aa5d8fc7a1 100644 --- a/tests/ui/borrowck/alias-liveness/rtn-static.rs +++ b/tests/ui/borrowck/alias-liveness/rtn-static.rs @@ -7,7 +7,7 @@ trait Foo { fn borrow(&mut self) -> impl Sized + '_; } -fn live_past_borrow>(mut t: T) { +fn live_past_borrow>(mut t: T) { let x = t.borrow(); drop(t); drop(x); @@ -15,7 +15,7 @@ fn live_past_borrow>(mut t: T) { // Test that the `'_` item bound in `borrow` does not cause us to // overlook the `'static` RTN bound. -fn overlapping_mut>(mut t: T) { +fn overlapping_mut>(mut t: T) { let x = t.borrow(); let x = t.borrow(); } diff --git a/tests/ui/feature-gates/feature-gate-return_type_notation.cfg.stderr b/tests/ui/feature-gates/feature-gate-return_type_notation.cfg.stderr index 41bd66b13e7..18f46928fab 100644 --- a/tests/ui/feature-gates/feature-gate-return_type_notation.cfg.stderr +++ b/tests/ui/feature-gates/feature-gate-return_type_notation.cfg.stderr @@ -1,33 +1,13 @@ error[E0658]: return type notation is experimental - --> $DIR/feature-gate-return_type_notation.rs:14:17 + --> $DIR/feature-gate-return_type_notation.rs:10:18 | -LL | fn foo>() {} - | ^^^^^^^^^ +LL | fn foo>() {} + | ^^^^ | = note: see issue #109417 for more information = help: add `#![feature(return_type_notation)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error: parenthesized generic arguments cannot be used in associated type constraints - --> $DIR/feature-gate-return_type_notation.rs:14:17 - | -LL | fn foo>() {} - | ^-- - | | - | help: remove these parentheses - -error: expected type, found function - --> $DIR/feature-gate-return_type_notation.rs:14:17 - | -LL | fn foo>() {} - | ^ unexpected function - | -note: the associated function is defined here - --> $DIR/feature-gate-return_type_notation.rs:10:5 - | -LL | async fn m(); - | ^^^^^^^^^^^^^ - -error: aborting due to 3 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/feature-gates/feature-gate-return_type_notation.no.stderr b/tests/ui/feature-gates/feature-gate-return_type_notation.no.stderr index 79c626cef35..18f46928fab 100644 --- a/tests/ui/feature-gates/feature-gate-return_type_notation.no.stderr +++ b/tests/ui/feature-gates/feature-gate-return_type_notation.no.stderr @@ -1,14 +1,13 @@ -warning: return type notation is experimental - --> $DIR/feature-gate-return_type_notation.rs:14:17 +error[E0658]: return type notation is experimental + --> $DIR/feature-gate-return_type_notation.rs:10:18 | -LL | fn foo>() {} - | ^^^^^^^^^ +LL | fn foo>() {} + | ^^^^ | = note: see issue #109417 for more information = help: add `#![feature(return_type_notation)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = warning: unstable syntax can change at any point in the future, causing a hard error! - = note: for more information, see issue #65860 -warning: 1 warning emitted +error: aborting due to 1 previous error +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/feature-gates/feature-gate-return_type_notation.rs b/tests/ui/feature-gates/feature-gate-return_type_notation.rs index 7ae6cd0234b..254b794e431 100644 --- a/tests/ui/feature-gates/feature-gate-return_type_notation.rs +++ b/tests/ui/feature-gates/feature-gate-return_type_notation.rs @@ -1,21 +1,13 @@ //@ edition: 2021 //@ revisions: cfg no -//@ [no] check-pass -// Since we're not adding new syntax, `cfg`'d out RTN must pass. - - trait Trait { #[allow(async_fn_in_trait)] async fn m(); } #[cfg(cfg)] -fn foo>() {} -//[cfg]~^ ERROR return type notation is experimental -//[cfg]~| ERROR parenthesized generic arguments cannot be used in associated type constraints -//[cfg]~| ERROR expected type, found function -//[no]~^^^^ WARN return type notation is experimental -//[no]~| WARN unstable syntax can change at any point in the future, causing a hard error! +fn foo>() {} +//~^ ERROR return type notation is experimental fn main() {} From 82b4af7511a430e53d2ed554771754552e5ecca8 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 28 Jun 2024 14:10:32 -0400 Subject: [PATCH 2/3] Make sure we deny unimplemented RTN on qpath segments --- compiler/rustc_ast_lowering/messages.ftl | 2 + compiler/rustc_ast_lowering/src/errors.rs | 5 ++ compiler/rustc_ast_lowering/src/path.rs | 16 ++++- .../return-type-notation/bare-path.rs | 26 ++++++++ .../return-type-notation/bare-path.stderr | 66 +++++++++++++++++++ 5 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 tests/ui/associated-type-bounds/return-type-notation/bare-path.rs create mode 100644 tests/ui/associated-type-bounds/return-type-notation/bare-path.stderr diff --git a/compiler/rustc_ast_lowering/messages.ftl b/compiler/rustc_ast_lowering/messages.ftl index d6eb344fd1d..9ed93d481e7 100644 --- a/compiler/rustc_ast_lowering/messages.ftl +++ b/compiler/rustc_ast_lowering/messages.ftl @@ -43,6 +43,8 @@ ast_lowering_bad_return_type_notation_output = return type not allowed with return type notation .suggestion = remove the return type +ast_lowering_bad_return_type_notation_position = return type notation not allowed in this position yet + ast_lowering_base_expression_double_dot = base expression required after `..` .suggestion = add a base expression here diff --git a/compiler/rustc_ast_lowering/src/errors.rs b/compiler/rustc_ast_lowering/src/errors.rs index 6699c6e75f5..4c77892a6b7 100644 --- a/compiler/rustc_ast_lowering/src/errors.rs +++ b/compiler/rustc_ast_lowering/src/errors.rs @@ -399,6 +399,11 @@ pub enum BadReturnTypeNotation { #[suggestion(code = "(..)", applicability = "maybe-incorrect")] span: Span, }, + #[diag(ast_lowering_bad_return_type_notation_position)] + Position { + #[primary_span] + span: Span, + }, } #[derive(Diagnostic)] diff --git a/compiler/rustc_ast_lowering/src/path.rs b/compiler/rustc_ast_lowering/src/path.rs index 1efa5bd3c4c..c6c08649374 100644 --- a/compiler/rustc_ast_lowering/src/path.rs +++ b/compiler/rustc_ast_lowering/src/path.rs @@ -1,7 +1,8 @@ use crate::ImplTraitPosition; use super::errors::{ - AsyncBoundNotOnTrait, AsyncBoundOnlyForFnTraits, GenericTypeWithParentheses, UseAngleBrackets, + AsyncBoundNotOnTrait, AsyncBoundOnlyForFnTraits, BadReturnTypeNotation, + GenericTypeWithParentheses, UseAngleBrackets, }; use super::ResolverAstLoweringExt; use super::{GenericArgsCtor, LifetimeRes, ParenthesizedGenericArgs}; @@ -276,8 +277,17 @@ pub(crate) fn lower_path_segment( ) } }, - GenericArgs::ParenthesizedElided(_span) => { - todo!() + GenericArgs::ParenthesizedElided(span) => { + self.dcx().emit_err(BadReturnTypeNotation::Position { span: *span }); + ( + GenericArgsCtor { + args: Default::default(), + constraints: &[], + parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation, + span: *span, + }, + false, + ) } } } else { diff --git a/tests/ui/associated-type-bounds/return-type-notation/bare-path.rs b/tests/ui/associated-type-bounds/return-type-notation/bare-path.rs new file mode 100644 index 00000000000..f507d82afec --- /dev/null +++ b/tests/ui/associated-type-bounds/return-type-notation/bare-path.rs @@ -0,0 +1,26 @@ +#![feature(return_type_notation)] +//~^ WARN the feature `return_type_notation` is incomplete + +trait Tr { + const CONST: usize; + + fn method() -> impl Sized; +} + +fn foo() +where + T::method(..): Send, + //~^ ERROR return type notation not allowed in this position yet + //~| ERROR expected type, found function + ::method(..): Send, + //~^ ERROR return type notation not allowed in this position yet + //~| ERROR expected associated type, found associated function `Tr::method` +{ + let _ = T::CONST::(..); + //~^ ERROR return type notation not allowed in this position yet + let _: T::method(..); + //~^ ERROR return type notation not allowed in this position yet + //~| ERROR expected type, found function +} + +fn main() {} diff --git a/tests/ui/associated-type-bounds/return-type-notation/bare-path.stderr b/tests/ui/associated-type-bounds/return-type-notation/bare-path.stderr new file mode 100644 index 00000000000..cb45de59c7e --- /dev/null +++ b/tests/ui/associated-type-bounds/return-type-notation/bare-path.stderr @@ -0,0 +1,66 @@ +error[E0575]: expected associated type, found associated function `Tr::method` + --> $DIR/bare-path.rs:15:5 + | +LL | ::method(..): Send, + | ^^^^^^^^^^^^^^^^^^^^^ not a associated type + +warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/bare-path.rs:1:12 + | +LL | #![feature(return_type_notation)] + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #109417 for more information + = note: `#[warn(incomplete_features)]` on by default + +error: return type notation not allowed in this position yet + --> $DIR/bare-path.rs:19:23 + | +LL | let _ = T::CONST::(..); + | ^^^^ + +error: return type notation not allowed in this position yet + --> $DIR/bare-path.rs:21:21 + | +LL | let _: T::method(..); + | ^^^^ + +error: return type notation not allowed in this position yet + --> $DIR/bare-path.rs:12:14 + | +LL | T::method(..): Send, + | ^^^^ + +error: return type notation not allowed in this position yet + --> $DIR/bare-path.rs:15:22 + | +LL | ::method(..): Send, + | ^^^^ + +error: expected type, found function + --> $DIR/bare-path.rs:12:8 + | +LL | T::method(..): Send, + | ^^^^^^ unexpected function + | +note: the associated function is defined here + --> $DIR/bare-path.rs:7:5 + | +LL | fn method() -> impl Sized; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected type, found function + --> $DIR/bare-path.rs:21:15 + | +LL | let _: T::method(..); + | ^^^^^^ unexpected function + | +note: the associated function is defined here + --> $DIR/bare-path.rs:7:5 + | +LL | fn method() -> impl Sized; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 7 previous errors; 1 warning emitted + +For more information about this error, try `rustc --explain E0575`. From 99365a5a7ace1092852784c2fa71b7fd5ef25e5d Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 28 Jun 2024 14:18:36 -0400 Subject: [PATCH 3/3] Implement RTN support in rustfmt --- src/tools/rustfmt/src/types.rs | 34 +++++++++++-------- .../tests/target/return-type-notation.rs | 10 ++++++ 2 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 src/tools/rustfmt/tests/target/return-type-notation.rs diff --git a/src/tools/rustfmt/src/types.rs b/src/tools/rustfmt/src/types.rs index c0bf9482b11..c826547e9d0 100644 --- a/src/tools/rustfmt/src/types.rs +++ b/src/tools/rustfmt/src/types.rs @@ -484,21 +484,25 @@ fn rewrite_generic_args( span: Span, ) -> Option { match gen_args { - ast::GenericArgs::AngleBracketed(ref data) if !data.args.is_empty() => { - let args = data - .args - .iter() - .map(|x| match x { - ast::AngleBracketedArg::Arg(generic_arg) => { - SegmentParam::from_generic_arg(generic_arg) - } - ast::AngleBracketedArg::Constraint(constraint) => { - SegmentParam::Binding(constraint) - } - }) - .collect::>(); + ast::GenericArgs::AngleBracketed(ref data) => { + if data.args.is_empty() { + Some("".to_owned()) + } else { + let args = data + .args + .iter() + .map(|x| match x { + ast::AngleBracketedArg::Arg(generic_arg) => { + SegmentParam::from_generic_arg(generic_arg) + } + ast::AngleBracketedArg::Constraint(constraint) => { + SegmentParam::Binding(constraint) + } + }) + .collect::>(); - overflow::rewrite_with_angle_brackets(context, "", args.iter(), shape, span) + overflow::rewrite_with_angle_brackets(context, "", args.iter(), shape, span) + } } ast::GenericArgs::Parenthesized(ref data) => format_function_type( data.inputs.iter().map(|x| &**x), @@ -508,7 +512,7 @@ fn rewrite_generic_args( context, shape, ), - _ => Some("".to_owned()), + ast::GenericArgs::ParenthesizedElided(..) => Some("(..)".to_owned()), } } diff --git a/src/tools/rustfmt/tests/target/return-type-notation.rs b/src/tools/rustfmt/tests/target/return-type-notation.rs new file mode 100644 index 00000000000..0f26e7e272b --- /dev/null +++ b/src/tools/rustfmt/tests/target/return-type-notation.rs @@ -0,0 +1,10 @@ +fn rtn() +where + T: Trait, + T::method(..): Send + 'static, +{ +} + +fn test() { + let x: T::method(..); +}