From ab0b9356e6e018b2d2f76a26402a7c337c03bad3 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 3 Apr 2023 21:20:48 +0000 Subject: [PATCH] Emit feature error for parenthesized generics in associated type bounds --- compiler/rustc_ast_passes/src/feature_gate.rs | 11 ++------ .../bad-inputs-and-output.rs | 2 ++ .../bad-inputs-and-output.stderr | 25 ++++++++++++++++--- .../unpretty-parenthesized.rs | 11 ++++++++ .../unpretty-parenthesized.stderr | 12 +++++++++ .../unpretty-parenthesized.stdout | 15 +++++++++++ 6 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.rs create mode 100644 tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.stderr create mode 100644 tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.stdout diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index de94c1bc47794..b3923b651eb3b 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -485,17 +485,10 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { if let Some(args) = constraint.gen_args.as_ref() && matches!( args, - ast::GenericArgs::ReturnTypeNotation(..) | ast::GenericArgs::Parenthesized(..) + ast::GenericArgs::ReturnTypeNotation(..) ) { - // RTN is gated elsewhere, and parenthesized args will turn into - // another error. - if matches!(args, ast::GenericArgs::Parenthesized(..)) { - self.sess.delay_span_bug( - constraint.span, - "should have emitted a parenthesized generics error", - ); - } + // RTN is gated below with a `gate_all`. } else { gate_feature_post!( &self, 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 75aa25906aa0f..2f9a1d1c76e06 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 @@ -10,11 +10,13 @@ trait Trait { fn foo>() {} //~^ ERROR argument types not allowed with return type notation +//~| ERROR associated type bounds are unstable fn bar (): Send>>() {} //~^ ERROR return type not allowed with return type notation fn baz>() {} //~^ ERROR return type notation arguments must be elided with `..` +//~| ERROR associated type bounds are unstable 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 5b075a0fa2921..b354a6805d6e5 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,27 @@ error: return type not allowed with return type notation - --> $DIR/bad-inputs-and-output.rs:14:28 + --> $DIR/bad-inputs-and-output.rs:15:28 | LL | fn bar (): Send>>() {} | ^^^^^ help: remove the return type +error[E0658]: associated type bounds are unstable + --> $DIR/bad-inputs-and-output.rs:11:17 + | +LL | fn foo>() {} + | ^^^^^^^^^^^^^^^^^ + | + = note: see issue #52662 for more information + = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable + +error[E0658]: associated type bounds are unstable + --> $DIR/bad-inputs-and-output.rs:18:17 + | +LL | fn baz>() {} + | ^^^^^^^^^^^^^^ + | + = note: see issue #52662 for more information + = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable + 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 | @@ -28,10 +46,11 @@ LL | fn foo>() {} | ^^^^^ help: remove the input types: `(..)` error: return type notation arguments must be elided with `..` - --> $DIR/bad-inputs-and-output.rs:17:23 + --> $DIR/bad-inputs-and-output.rs:18:23 | LL | fn baz>() {} | ^^ help: add `..`: `(..)` -error: aborting due to 3 previous errors; 2 warnings emitted +error: aborting due to 5 previous errors; 2 warnings emitted +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.rs b/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.rs new file mode 100644 index 0000000000000..9129f37e0c6b6 --- /dev/null +++ b/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.rs @@ -0,0 +1,11 @@ +// edition: 2021 +// compile-flags: -Zunpretty=expanded + +trait Trait { + async fn method() {} +} + +fn foo>() {} +//~^ ERROR associated type bounds are unstable + +fn main() {} diff --git a/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.stderr b/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.stderr new file mode 100644 index 0000000000000..77e015b4160bb --- /dev/null +++ b/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.stderr @@ -0,0 +1,12 @@ +error[E0658]: associated type bounds are unstable + --> $DIR/unpretty-parenthesized.rs:8:17 + | +LL | fn foo>() {} + | ^^^^^^^^^^^^^^^^^ + | + = note: see issue #52662 for more information + = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.stdout b/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.stdout new file mode 100644 index 0000000000000..b3dea8f6eca71 --- /dev/null +++ b/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.stdout @@ -0,0 +1,15 @@ +#![feature(prelude_import)] +#[prelude_import] +use std::prelude::rust_2021::*; +#[macro_use] +extern crate std; +// edition: 2021 +// compile-flags: -Zunpretty=expanded + +trait Trait { + async fn method() {} +} + +fn foo>() {} + +fn main() {}