Skip to content

Commit c4f829b

Browse files
committed
Allow #[unstable] impl for fn() -> UnstableType.
(But not fn() -> !, which is stable.)
1 parent 5420fa3 commit c4f829b

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

Diff for: compiler/rustc_passes/src/stability.rs

+19-7
Original file line numberDiff line numberDiff line change
@@ -888,14 +888,26 @@ impl<'tcx> Visitor<'tcx> for CheckTraitImplStable<'tcx> {
888888
}
889889

890890
fn visit_ty(&mut self, t: &'tcx Ty<'tcx>) {
891-
match t.kind {
892-
TyKind::Never => self.fully_stable = false,
893-
TyKind::BareFn(f) => {
894-
if rustc_target::spec::abi::is_stable(f.abi.name()).is_err() {
895-
self.fully_stable = false;
896-
}
891+
if let TyKind::Never = t.kind {
892+
self.fully_stable = false;
893+
}
894+
if let TyKind::BareFn(f) = t.kind {
895+
if rustc_target::spec::abi::is_stable(f.abi.name()).is_err() {
896+
self.fully_stable = false;
897+
}
898+
}
899+
intravisit::walk_ty(self, t)
900+
}
901+
902+
fn visit_fn_decl(&mut self, fd: &'tcx hir::FnDecl<'tcx>) {
903+
for ty in fd.inputs {
904+
self.visit_ty(ty)
905+
}
906+
if let hir::FnRetTy::Return(output_ty) = fd.output {
907+
match output_ty.kind {
908+
TyKind::Never => {} // `-> !` is stable
909+
_ => self.visit_ty(output_ty),
897910
}
898-
_ => intravisit::walk_ty(self, t),
899911
}
900912
}
901913
}

Diff for: src/test/ui/stability-attribute/stability-attribute-trait-impl.rs

+3
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@ impl StableTrait for StableType {}
3737
//~^ ERROR an `#[unstable]` annotation here has no effect [ineffective_unstable_trait_impl]
3838
impl StableTrait for fn() -> ! {}
3939

40+
#[unstable(feature = "l", issue = "none")]
41+
impl StableTrait for fn() -> UnstableType {}
42+
4043
fn main() {}

0 commit comments

Comments
 (0)