Skip to content

Commit fb9ca92

Browse files
Feature gate
1 parent f50c1e1 commit fb9ca92

File tree

6 files changed

+73
-6
lines changed

6 files changed

+73
-6
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ impl GenericArgs {
174174
matches!(self, AngleBracketed(..))
175175
}
176176

177+
pub fn is_parenthesized(&self) -> bool {
178+
matches!(self, Parenthesized(..))
179+
}
180+
177181
pub fn span(&self) -> Span {
178182
match self {
179183
AngleBracketed(data) => data.span,

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -482,12 +482,21 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
482482

483483
fn visit_assoc_constraint(&mut self, constraint: &'a AssocConstraint) {
484484
if let AssocConstraintKind::Bound { .. } = constraint.kind {
485-
gate_feature_post!(
486-
&self,
487-
associated_type_bounds,
488-
constraint.span,
489-
"associated type bounds are unstable"
490-
)
485+
if constraint.gen_args.as_ref().map_or(false, |args| args.is_parenthesized()) {
486+
gate_feature_post!(
487+
&self,
488+
return_type_notation,
489+
constraint.span,
490+
"return type notation is unstable"
491+
)
492+
} else {
493+
gate_feature_post!(
494+
&self,
495+
associated_type_bounds,
496+
constraint.span,
497+
"associated type bounds are unstable"
498+
)
499+
}
491500
}
492501
visit::walk_assoc_constraint(self, constraint)
493502
}

compiler/rustc_feature/src/active.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,8 @@ declare_features! (
495495
(active, repr_simd, "1.4.0", Some(27731), None),
496496
/// Allows return-position `impl Trait` in traits.
497497
(incomplete, return_position_impl_trait_in_trait, "1.65.0", Some(91611), None),
498+
/// Allows bounding the return type of AFIT/RPITIT.
499+
(incomplete, return_type_notation, "CURRENT_RUSTC_VERSION", Some(109417), None),
498500
/// Allows `extern "rust-cold"`.
499501
(active, rust_cold_cc, "1.63.0", Some(97544), None),
500502
/// Allows the use of SIMD types in functions declared in `extern` blocks.

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,7 @@ symbols! {
11931193
residual,
11941194
result,
11951195
return_position_impl_trait_in_trait,
1196+
return_type_notation,
11961197
rhs,
11971198
rintf32,
11981199
rintf64,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// edition: 2021
2+
3+
#![feature(async_fn_in_trait)]
4+
//~^ WARN the feature `async_fn_in_trait` is incomplete
5+
6+
trait Trait {
7+
async fn m();
8+
}
9+
10+
fn foo<T: Trait<m(): Send>>() {}
11+
//~^ ERROR parenthesized generic arguments cannot be used in associated type constraints
12+
//~| ERROR associated type `m` not found for `Trait`
13+
//~| ERROR return type notation is unstable
14+
15+
fn main() {}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
error[E0658]: return type notation is unstable
2+
--> $DIR/feature-gate-return_type_notation.rs:10:17
3+
|
4+
LL | fn foo<T: Trait<m(): Send>>() {}
5+
| ^^^^^^^^^
6+
|
7+
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
8+
= help: add `#![feature(return_type_notation)]` to the crate attributes to enable
9+
10+
warning: the feature `async_fn_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes
11+
--> $DIR/feature-gate-return_type_notation.rs:3:12
12+
|
13+
LL | #![feature(async_fn_in_trait)]
14+
| ^^^^^^^^^^^^^^^^^
15+
|
16+
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
17+
= note: `#[warn(incomplete_features)]` on by default
18+
19+
error: parenthesized generic arguments cannot be used in associated type constraints
20+
--> $DIR/feature-gate-return_type_notation.rs:10:17
21+
|
22+
LL | fn foo<T: Trait<m(): Send>>() {}
23+
| ^--
24+
| |
25+
| help: remove these parentheses
26+
27+
error[E0220]: associated type `m` not found for `Trait`
28+
--> $DIR/feature-gate-return_type_notation.rs:10:17
29+
|
30+
LL | fn foo<T: Trait<m(): Send>>() {}
31+
| ^ associated type `m` not found
32+
33+
error: aborting due to 3 previous errors; 1 warning emitted
34+
35+
Some errors have detailed explanations: E0220, E0658.
36+
For more information about an error, try `rustc --explain E0220`.

0 commit comments

Comments
 (0)