Skip to content

Commit

Permalink
Allow #[unstable] impl for fn() -> UnstableType.
Browse files Browse the repository at this point in the history
(But not fn() -> !, which is stable.)
  • Loading branch information
m-ou-se committed Oct 19, 2022
1 parent 5420fa3 commit c4f829b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
26 changes: 19 additions & 7 deletions compiler/rustc_passes/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -888,14 +888,26 @@ impl<'tcx> Visitor<'tcx> for CheckTraitImplStable<'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),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}

0 comments on commit c4f829b

Please sign in to comment.