Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When an ADT field is missing a stability attribute, look at its parent #68401

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/librustc_passes/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,27 @@ struct MissingStabilityAnnotations<'a, 'tcx> {

impl<'a, 'tcx> MissingStabilityAnnotations<'a, 'tcx> {
fn check_missing_stability(&self, hir_id: HirId, span: Span, name: &str) {
let stab = self.tcx.stability().local_stability(hir_id);
let stability = self.tcx.stability();
// Get the stability attribute of the current node, if it has none and it is part of an
// ADT, climb up until the item's def to get the whole's ADT's stability if present.
let stab = stability.local_stability(hir_id).or_else(|| {
let parent_id = self.tcx.hir().get_parent_node(hir_id);
let node = self.tcx.hir().find(parent_id);
match node {
// For enum/union variants we check first the variant's stability and if none, we
// check the whole ADT.
Some(hir::Node::Variant(_)) => stability.local_stability(parent_id).or_else(|| {
let parent_id = self.tcx.hir().get_parent_node(hir_id);
stability.local_stability(parent_id)
}),
Some(hir::Node::Item(hir::Item { kind: hir::ItemKind::Struct(..), .. }))
| Some(hir::Node::Item(hir::Item { kind: hir::ItemKind::Enum(..), .. }))
| Some(hir::Node::Item(hir::Item { kind: hir::ItemKind::Union(..), .. })) => {
stability.local_stability(parent_id)
}
_ => None,
}
});
let is_error =
!self.tcx.sess.opts.test && stab.is_none() && self.access_levels.is_reachable(hir_id);
if is_error {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// check-pass
#![feature(staged_api)]
#![stable(feature = "test", since = "0")]

#[stable(feature = "test", since = "0")]
pub struct Reverse<T>(pub T); //~ ERROR field has missing stability attribute
pub struct Reverse<T>(pub T); // if the field has no stability, we check its parent

fn main() {
// Make sure the field is used to fill the stability cache
Expand Down

This file was deleted.