Rollup merge of #109914 - compiler-errors:rtn-bad-parens, r=oli-obk

Emit feature error for parenthesized generics in associated type bounds

We don't actually do AST->HIR lowering with some `-Zunpretty` flags, so it's not correct to just delay a bug instead of emitting a feature error.

Some diagnostics regressed because of the new errors, but oh well. 🤷

Fixes #109898
This commit is contained in:
Michael Goulet 2023-04-04 09:27:46 -07:00 committed by GitHub
commit a5c395ed94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 64 additions and 12 deletions

View File

@ -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,

View File

@ -10,11 +10,13 @@ trait Trait {
fn foo<T: Trait<method(i32): Send>>() {}
//~^ ERROR argument types not allowed with return type notation
//~| ERROR associated type bounds are unstable
fn bar<T: Trait<method(..) -> (): Send>>() {}
//~^ ERROR return type not allowed with return type notation
fn baz<T: Trait<method(): Send>>() {}
//~^ ERROR return type notation arguments must be elided with `..`
//~| ERROR associated type bounds are unstable
fn main() {}

View File

@ -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<T: Trait<method(..) -> (): Send>>() {}
| ^^^^^ help: remove the return type
error[E0658]: associated type bounds are unstable
--> $DIR/bad-inputs-and-output.rs:11:17
|
LL | fn foo<T: Trait<method(i32): Send>>() {}
| ^^^^^^^^^^^^^^^^^
|
= note: see issue #52662 <https://github.com/rust-lang/rust/issues/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<T: Trait<method(): Send>>() {}
| ^^^^^^^^^^^^^^
|
= note: see issue #52662 <https://github.com/rust-lang/rust/issues/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<T: Trait<method(i32): Send>>() {}
| ^^^^^ 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<T: Trait<method(): Send>>() {}
| ^^ 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`.

View File

@ -0,0 +1,11 @@
// edition: 2021
// compile-flags: -Zunpretty=expanded
trait Trait {
async fn method() {}
}
fn foo<T: Trait<method(i32): Send>>() {}
//~^ ERROR associated type bounds are unstable
fn main() {}

View File

@ -0,0 +1,12 @@
error[E0658]: associated type bounds are unstable
--> $DIR/unpretty-parenthesized.rs:8:17
|
LL | fn foo<T: Trait<method(i32): Send>>() {}
| ^^^^^^^^^^^^^^^^^
|
= note: see issue #52662 <https://github.com/rust-lang/rust/issues/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`.

View File

@ -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<T: Trait<method(i32) : Send>>() {}
fn main() {}