diff options
Diffstat (limited to 'compiler/rustc_passes/src/stability.rs')
-rw-r--r-- | compiler/rustc_passes/src/stability.rs | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 78afa2f25..da7155234 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -358,9 +358,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { const_stab_inherit = InheritConstStability::Yes; } hir::ItemKind::Struct(ref sd, _) => { - if let Some(ctor_hir_id) = sd.ctor_hir_id() { + if let Some(ctor_def_id) = sd.ctor_def_id() { self.annotate( - self.tcx.hir().local_def_id(ctor_hir_id), + ctor_def_id, i.span, None, AnnotationKind::Required, @@ -435,7 +435,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { fn visit_variant(&mut self, var: &'tcx Variant<'tcx>) { self.annotate( - self.tcx.hir().local_def_id(var.id), + var.def_id, var.span, None, AnnotationKind::Required, @@ -443,9 +443,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { InheritConstStability::No, InheritStability::Yes, |v| { - if let Some(ctor_hir_id) = var.data.ctor_hir_id() { + if let Some(ctor_def_id) = var.data.ctor_def_id() { v.annotate( - v.tcx.hir().local_def_id(ctor_hir_id), + ctor_def_id, var.span, None, AnnotationKind::Required, @@ -463,7 +463,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { fn visit_field_def(&mut self, s: &'tcx FieldDef<'tcx>) { self.annotate( - self.tcx.hir().local_def_id(s.hir_id), + s.def_id, s.span, None, AnnotationKind::Required, @@ -500,7 +500,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { }; self.annotate( - self.tcx.hir().local_def_id(p.hir_id), + p.def_id, p.span, None, kind, @@ -536,6 +536,14 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> { return; } + // if the const impl is derived using the `derive_const` attribute, + // then it would be "stable" at least for the impl. + // We gate usages of it using `feature(const_trait_impl)` anyways + // so there is no unstable leakage + if self.tcx.is_builtin_derive(def_id.to_def_id()) { + return; + } + let is_const = self.tcx.is_const_fn(def_id.to_def_id()) || self.tcx.is_const_trait_impl_raw(def_id.to_def_id()); let is_stable = self @@ -593,15 +601,15 @@ 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); + self.check_missing_stability(var.def_id, var.span); + if let Some(ctor_def_id) = var.data.ctor_def_id() { + self.check_missing_stability(ctor_def_id, var.span); } intravisit::walk_variant(self, var); } fn visit_field_def(&mut self, s: &'tcx FieldDef<'tcx>) { - self.check_missing_stability(self.tcx.hir().local_def_id(s.hir_id), s.span); + self.check_missing_stability(s.def_id, s.span); intravisit::walk_field_def(self, s); } @@ -779,7 +787,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { intravisit::walk_item(self, item); } - fn visit_path(&mut self, path: &'tcx hir::Path<'tcx>, id: hir::HirId) { + fn visit_path(&mut self, path: &hir::Path<'tcx>, id: hir::HirId) { if let Some(def_id) = path.res.opt_def_id() { let method_span = path.segments.last().map(|s| s.ident.span); let item_is_allowed = self.tcx.check_stability_allow_unstable( @@ -872,7 +880,7 @@ struct CheckTraitImplStable<'tcx> { } impl<'tcx> Visitor<'tcx> for CheckTraitImplStable<'tcx> { - fn visit_path(&mut self, path: &'tcx hir::Path<'tcx>, _id: hir::HirId) { + fn visit_path(&mut self, path: &hir::Path<'tcx>, _id: hir::HirId) { if let Some(def_id) = path.res.opt_def_id() { if let Some(stab) = self.tcx.lookup_stability(def_id) { self.fully_stable &= stab.level.is_stable(); |