Skip to content

Commit

Permalink
Rollup merge of #109914 - compiler-errors:rtn-bad-parens, r=oli-obk
Browse files Browse the repository at this point in the history
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
  • Loading branch information
compiler-errors committed Apr 4, 2023
2 parents 5485a54 + ab0b935 commit a5c395e
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 12 deletions.
11 changes: 2 additions & 9 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Original file line number Diff line number Diff line change
@@ -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
|
Expand All @@ -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`.
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit a5c395e

Please sign in to comment.