Skip to content

Commit a5c395e

Browse files
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
2 parents 5485a54 + ab0b935 commit a5c395e

File tree

6 files changed

+64
-12
lines changed

6 files changed

+64
-12
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -485,17 +485,10 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
485485
if let Some(args) = constraint.gen_args.as_ref()
486486
&& matches!(
487487
args,
488-
ast::GenericArgs::ReturnTypeNotation(..) | ast::GenericArgs::Parenthesized(..)
488+
ast::GenericArgs::ReturnTypeNotation(..)
489489
)
490490
{
491-
// RTN is gated elsewhere, and parenthesized args will turn into
492-
// another error.
493-
if matches!(args, ast::GenericArgs::Parenthesized(..)) {
494-
self.sess.delay_span_bug(
495-
constraint.span,
496-
"should have emitted a parenthesized generics error",
497-
);
498-
}
491+
// RTN is gated below with a `gate_all`.
499492
} else {
500493
gate_feature_post!(
501494
&self,

tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ trait Trait {
1010

1111
fn foo<T: Trait<method(i32): Send>>() {}
1212
//~^ ERROR argument types not allowed with return type notation
13+
//~| ERROR associated type bounds are unstable
1314

1415
fn bar<T: Trait<method(..) -> (): Send>>() {}
1516
//~^ ERROR return type not allowed with return type notation
1617

1718
fn baz<T: Trait<method(): Send>>() {}
1819
//~^ ERROR return type notation arguments must be elided with `..`
20+
//~| ERROR associated type bounds are unstable
1921

2022
fn main() {}

tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.stderr

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
error: return type not allowed with return type notation
2-
--> $DIR/bad-inputs-and-output.rs:14:28
2+
--> $DIR/bad-inputs-and-output.rs:15:28
33
|
44
LL | fn bar<T: Trait<method(..) -> (): Send>>() {}
55
| ^^^^^ help: remove the return type
66

7+
error[E0658]: associated type bounds are unstable
8+
--> $DIR/bad-inputs-and-output.rs:11:17
9+
|
10+
LL | fn foo<T: Trait<method(i32): Send>>() {}
11+
| ^^^^^^^^^^^^^^^^^
12+
|
13+
= note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information
14+
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
15+
16+
error[E0658]: associated type bounds are unstable
17+
--> $DIR/bad-inputs-and-output.rs:18:17
18+
|
19+
LL | fn baz<T: Trait<method(): Send>>() {}
20+
| ^^^^^^^^^^^^^^
21+
|
22+
= note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information
23+
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
24+
725
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
826
--> $DIR/bad-inputs-and-output.rs:3:12
927
|
@@ -28,10 +46,11 @@ LL | fn foo<T: Trait<method(i32): Send>>() {}
2846
| ^^^^^ help: remove the input types: `(..)`
2947

3048
error: return type notation arguments must be elided with `..`
31-
--> $DIR/bad-inputs-and-output.rs:17:23
49+
--> $DIR/bad-inputs-and-output.rs:18:23
3250
|
3351
LL | fn baz<T: Trait<method(): Send>>() {}
3452
| ^^ help: add `..`: `(..)`
3553

36-
error: aborting due to 3 previous errors; 2 warnings emitted
54+
error: aborting due to 5 previous errors; 2 warnings emitted
3755

56+
For more information about this error, try `rustc --explain E0658`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// edition: 2021
2+
// compile-flags: -Zunpretty=expanded
3+
4+
trait Trait {
5+
async fn method() {}
6+
}
7+
8+
fn foo<T: Trait<method(i32): Send>>() {}
9+
//~^ ERROR associated type bounds are unstable
10+
11+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0658]: associated type bounds are unstable
2+
--> $DIR/unpretty-parenthesized.rs:8:17
3+
|
4+
LL | fn foo<T: Trait<method(i32): Send>>() {}
5+
| ^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information
8+
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0658`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![feature(prelude_import)]
2+
#[prelude_import]
3+
use std::prelude::rust_2021::*;
4+
#[macro_use]
5+
extern crate std;
6+
// edition: 2021
7+
// compile-flags: -Zunpretty=expanded
8+
9+
trait Trait {
10+
async fn method() {}
11+
}
12+
13+
fn foo<T: Trait<method(i32) : Send>>() {}
14+
15+
fn main() {}

0 commit comments

Comments
 (0)