Feature gate

This commit is contained in:
Michael Goulet 2023-03-04 02:23:36 +00:00
parent f50c1e1f05
commit fb9ca9223d
6 changed files with 73 additions and 6 deletions

View File

@ -174,6 +174,10 @@ impl GenericArgs {
matches!(self, AngleBracketed(..))
}
pub fn is_parenthesized(&self) -> bool {
matches!(self, Parenthesized(..))
}
pub fn span(&self) -> Span {
match self {
AngleBracketed(data) => data.span,

View File

@ -482,12 +482,21 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
fn visit_assoc_constraint(&mut self, constraint: &'a AssocConstraint) {
if let AssocConstraintKind::Bound { .. } = constraint.kind {
gate_feature_post!(
&self,
associated_type_bounds,
constraint.span,
"associated type bounds are unstable"
)
if constraint.gen_args.as_ref().map_or(false, |args| args.is_parenthesized()) {
gate_feature_post!(
&self,
return_type_notation,
constraint.span,
"return type notation is unstable"
)
} else {
gate_feature_post!(
&self,
associated_type_bounds,
constraint.span,
"associated type bounds are unstable"
)
}
}
visit::walk_assoc_constraint(self, constraint)
}

View File

@ -495,6 +495,8 @@ declare_features! (
(active, repr_simd, "1.4.0", Some(27731), None),
/// Allows return-position `impl Trait` in traits.
(incomplete, return_position_impl_trait_in_trait, "1.65.0", Some(91611), None),
/// Allows bounding the return type of AFIT/RPITIT.
(incomplete, return_type_notation, "CURRENT_RUSTC_VERSION", Some(109417), None),
/// Allows `extern "rust-cold"`.
(active, rust_cold_cc, "1.63.0", Some(97544), None),
/// Allows the use of SIMD types in functions declared in `extern` blocks.

View File

@ -1193,6 +1193,7 @@ symbols! {
residual,
result,
return_position_impl_trait_in_trait,
return_type_notation,
rhs,
rintf32,
rintf64,

View File

@ -0,0 +1,15 @@
// edition: 2021
#![feature(async_fn_in_trait)]
//~^ WARN the feature `async_fn_in_trait` is incomplete
trait Trait {
async fn m();
}
fn foo<T: Trait<m(): Send>>() {}
//~^ ERROR parenthesized generic arguments cannot be used in associated type constraints
//~| ERROR associated type `m` not found for `Trait`
//~| ERROR return type notation is unstable
fn main() {}

View File

@ -0,0 +1,36 @@
error[E0658]: return type notation is unstable
--> $DIR/feature-gate-return_type_notation.rs:10:17
|
LL | fn foo<T: Trait<m(): Send>>() {}
| ^^^^^^^^^
|
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
= help: add `#![feature(return_type_notation)]` to the crate attributes to enable
warning: the feature `async_fn_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/feature-gate-return_type_notation.rs:3:12
|
LL | #![feature(async_fn_in_trait)]
| ^^^^^^^^^^^^^^^^^
|
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
= note: `#[warn(incomplete_features)]` on by default
error: parenthesized generic arguments cannot be used in associated type constraints
--> $DIR/feature-gate-return_type_notation.rs:10:17
|
LL | fn foo<T: Trait<m(): Send>>() {}
| ^--
| |
| help: remove these parentheses
error[E0220]: associated type `m` not found for `Trait`
--> $DIR/feature-gate-return_type_notation.rs:10:17
|
LL | fn foo<T: Trait<m(): Send>>() {}
| ^ associated type `m` not found
error: aborting due to 3 previous errors; 1 warning emitted
Some errors have detailed explanations: E0220, E0658.
For more information about an error, try `rustc --explain E0220`.