about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-03-04 02:23:36 +0000
committerMichael Goulet <michael@errs.io>2023-03-28 01:02:15 +0000
commitfb9ca9223d42a13bc15bddd1c2dce506db2fcb21 (patch)
tree7be29004c8a9b2c8c91b9cf84470b011bdf7f0c1
parentf50c1e1f0587d4a7e44946a909484f75a0a4c929 (diff)
downloadrust-fb9ca9223d42a13bc15bddd1c2dce506db2fcb21.tar.gz
rust-fb9ca9223d42a13bc15bddd1c2dce506db2fcb21.zip
Feature gate
-rw-r--r--compiler/rustc_ast/src/ast.rs4
-rw-r--r--compiler/rustc_ast_passes/src/feature_gate.rs21
-rw-r--r--compiler/rustc_feature/src/active.rs2
-rw-r--r--compiler/rustc_span/src/symbol.rs1
-rw-r--r--tests/ui/feature-gates/feature-gate-return_type_notation.rs15
-rw-r--r--tests/ui/feature-gates/feature-gate-return_type_notation.stderr36
6 files changed, 73 insertions, 6 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs
index ab8b7f632e8..710c7ad3b2e 100644
--- a/compiler/rustc_ast/src/ast.rs
+++ b/compiler/rustc_ast/src/ast.rs
@@ -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,
diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs
index 344a1e7f5e7..1413db64a48 100644
--- a/compiler/rustc_ast_passes/src/feature_gate.rs
+++ b/compiler/rustc_ast_passes/src/feature_gate.rs
@@ -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)
     }
diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs
index b7d280b8751..9c0dc938635 100644
--- a/compiler/rustc_feature/src/active.rs
+++ b/compiler/rustc_feature/src/active.rs
@@ -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.
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index 4a1abdf6318..153988d9e12 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -1193,6 +1193,7 @@ symbols! {
         residual,
         result,
         return_position_impl_trait_in_trait,
+        return_type_notation,
         rhs,
         rintf32,
         rintf64,
diff --git a/tests/ui/feature-gates/feature-gate-return_type_notation.rs b/tests/ui/feature-gates/feature-gate-return_type_notation.rs
new file mode 100644
index 00000000000..fea953dcdd0
--- /dev/null
+++ b/tests/ui/feature-gates/feature-gate-return_type_notation.rs
@@ -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() {}
diff --git a/tests/ui/feature-gates/feature-gate-return_type_notation.stderr b/tests/ui/feature-gates/feature-gate-return_type_notation.stderr
new file mode 100644
index 00000000000..a9373482e5a
--- /dev/null
+++ b/tests/ui/feature-gates/feature-gate-return_type_notation.stderr
@@ -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`.