]> git.lizzy.rs Git - rust.git/commitdiff
Allow #[unstable] impl for fn() -> UnstableType.
authorMara Bos <m-ou.se@m-ou.se>
Wed, 19 Oct 2022 11:33:45 +0000 (13:33 +0200)
committerMara Bos <m-ou.se@m-ou.se>
Wed, 19 Oct 2022 11:34:18 +0000 (13:34 +0200)
(But not fn() -> !, which is stable.)

compiler/rustc_passes/src/stability.rs
src/test/ui/stability-attribute/stability-attribute-trait-impl.rs

index 78591e640e38f960ffd090b09440bd4db5441ba8..9591aeb881f3d58c8e4790e0120ff7e7f5381b9d 100644 (file)
@@ -888,14 +888,26 @@ fn visit_trait_ref(&mut self, t: &'tcx TraitRef<'tcx>) {
     }
 
     fn visit_ty(&mut self, t: &'tcx Ty<'tcx>) {
-        match t.kind {
-            TyKind::Never => self.fully_stable = false,
-            TyKind::BareFn(f) => {
-                if rustc_target::spec::abi::is_stable(f.abi.name()).is_err() {
-                    self.fully_stable = false;
-                }
+        if let TyKind::Never = t.kind {
+            self.fully_stable = false;
+        }
+        if let TyKind::BareFn(f) = t.kind {
+            if rustc_target::spec::abi::is_stable(f.abi.name()).is_err() {
+                self.fully_stable = false;
+            }
+        }
+        intravisit::walk_ty(self, t)
+    }
+
+    fn visit_fn_decl(&mut self, fd: &'tcx hir::FnDecl<'tcx>) {
+        for ty in fd.inputs {
+            self.visit_ty(ty)
+        }
+        if let hir::FnRetTy::Return(output_ty) = fd.output {
+            match output_ty.kind {
+                TyKind::Never => {} // `-> !` is stable
+                _ => self.visit_ty(output_ty),
             }
-            _ => intravisit::walk_ty(self, t),
         }
     }
 }
index cc5bc3b6d9128d20d5a1849bcfea3220df3b0fd1..0c771ae87953c4ef24f9135430681def9f7937ac 100644 (file)
@@ -37,4 +37,7 @@ impl StableTrait for StableType {}
 //~^ ERROR an `#[unstable]` annotation here has no effect [ineffective_unstable_trait_impl]
 impl StableTrait for fn() -> ! {}
 
+#[unstable(feature = "l", issue = "none")]
+impl StableTrait for fn() -> UnstableType {}
+
 fn main() {}