From b821ce6097812763fd6136a90b42f90a71364e76 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 11 Aug 2022 22:20:35 +0000 Subject: [PATCH 1/2] enum variant ctor inherits stability of variant --- compiler/rustc_passes/src/stability.rs | 2 +- .../ui/stability-attribute/auxiliary/ctor-stability.rs | 8 ++++++++ src/test/ui/stability-attribute/ctor-stability.rs | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/stability-attribute/auxiliary/ctor-stability.rs create mode 100644 src/test/ui/stability-attribute/ctor-stability.rs diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 574e8073d8efd..3ec270a7c97f6 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -460,7 +460,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { AnnotationKind::Required, InheritDeprecation::Yes, InheritConstStability::No, - InheritStability::No, + InheritStability::Yes, |_| {}, ); } diff --git a/src/test/ui/stability-attribute/auxiliary/ctor-stability.rs b/src/test/ui/stability-attribute/auxiliary/ctor-stability.rs new file mode 100644 index 0000000000000..74c6023d7fbbd --- /dev/null +++ b/src/test/ui/stability-attribute/auxiliary/ctor-stability.rs @@ -0,0 +1,8 @@ +#![crate_type = "lib"] +#![feature(staged_api)] +#![stable(feature = "none", since = "1.0")] + +#[stable(feature = "none", since = "1.0")] +pub enum Foo { + A, +} diff --git a/src/test/ui/stability-attribute/ctor-stability.rs b/src/test/ui/stability-attribute/ctor-stability.rs new file mode 100644 index 0000000000000..fcab0cb109940 --- /dev/null +++ b/src/test/ui/stability-attribute/ctor-stability.rs @@ -0,0 +1,8 @@ +// aux-build:ctor-stability.rs +// check-pass + +extern crate ctor_stability; + +fn main() { + let _ = ctor_stability::Foo::A; +} From 6925f4101b426c66abe20e8acdddf8c20fd1e87c Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 11 Aug 2022 22:25:16 +0000 Subject: [PATCH 2/2] Check ctor for missing stability --- compiler/rustc_passes/src/stability.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 3ec270a7c97f6..972999deb18f1 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -600,6 +600,9 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> { fn visit_variant(&mut self, var: &'tcx Variant<'tcx>) { self.check_missing_stability(self.tcx.hir().local_def_id(var.id), var.span); + if let Some(ctor_hir_id) = var.data.ctor_hir_id() { + self.check_missing_stability(self.tcx.hir().local_def_id(ctor_hir_id), var.span); + } intravisit::walk_variant(self, var); }