Skip to content

Emit feature error for parenthesized generics in associated type bounds #109914

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {}