about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume.gomez@huawei.com>2024-02-01 14:56:41 +0100
committerGuillaume Gomez <guillaume.gomez@huawei.com>2024-02-01 20:01:04 +0100
commit2c0030ff2cb373a31d4dfa7f7cb3596739090ff3 (patch)
tree08dee7980226be9461992b2fd674fcdaea4b8aae
parent11f32b73e0dc9287e305b5b9980d24aecdc8c17f (diff)
downloadrust-2c0030ff2cb373a31d4dfa7f7cb3596739090ff3.tar.gz
rust-2c0030ff2cb373a31d4dfa7f7cb3596739090ff3.zip
Correctly check `never_type` feature gating
-rw-r--r--compiler/rustc_ast_passes/src/feature_gate.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs
index 82236d2e306..409aef9185d 100644
--- a/compiler/rustc_ast_passes/src/feature_gate.rs
+++ b/compiler/rustc_ast_passes/src/feature_gate.rs
@@ -362,6 +362,19 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
         }
     }
 
+    fn visit_generic_args(&mut self, args: &'a ast::GenericArgs) {
+        // This check needs to happen here because the never type can be returned from a function,
+        // but cannot be used in any other context. If this check was in `visit_fn_ret_ty`, it
+        // include both functions and generics like `impl Fn() -> !`.
+        if let ast::GenericArgs::Parenthesized(generic_args) = args
+            && let ast::FnRetTy::Ty(ref ty) = generic_args.output
+            && matches!(ty.kind, ast::TyKind::Never)
+        {
+            gate!(&self, never_type, ty.span, "the `!` type is experimental");
+        }
+        visit::walk_generic_args(self, args);
+    }
+
     fn visit_expr(&mut self, e: &'a ast::Expr) {
         match e.kind {
             ast::ExprKind::TryBlock(_) => {