From 2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:50 +0200 Subject: Merging upstream version 1.69.0+dfsg1. Signed-off-by: Daniel Baumann --- compiler/rustc_passes/src/stability.rs | 63 +++++++++++++++++----------------- 1 file changed, 32 insertions(+), 31 deletions(-) (limited to 'compiler/rustc_passes/src/stability.rs') diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 34e1abb78..16194a6f1 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -1,12 +1,7 @@ //! A pass that annotates every item and method with its stability level, //! propagating default levels lexically from parent to children ast nodes. -use crate::errors::{ - self, CannotStabilizeDeprecated, DeprecatedAttribute, DuplicateFeatureErr, - FeatureOnlyOnNightly, ImpliedFeatureNotExist, InvalidDeprecationVersion, InvalidStability, - MissingConstErr, MissingConstStabAttr, MissingStabilityAttr, TraitImplConstStable, - UnknownFeature, UselessStability, -}; +use crate::errors; use rustc_attr::{ self as attr, rust_version_symbol, ConstStability, Stability, StabilityLevel, Unstable, UnstableReason, VERSION_PLACEHOLDER, @@ -125,7 +120,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { if let Some((depr, span)) = &depr { is_deprecated = true; - if kind == AnnotationKind::Prohibited || kind == AnnotationKind::DeprecationProhibited { + if matches!(kind, AnnotationKind::Prohibited | AnnotationKind::DeprecationProhibited) { let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id); self.tcx.emit_spanned_lint( USELESS_DEPRECATED, @@ -185,7 +180,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { { self.tcx .sess - .emit_err(MissingConstErr { fn_sig_span: fn_sig.span, const_span }); + .emit_err(errors::MissingConstErr { fn_sig_span: fn_sig.span, const_span }); } } } @@ -203,7 +198,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { if let Some((rustc_attr::Deprecation { is_since_rustc_version: true, .. }, span)) = &depr { if stab.is_none() { - self.tcx.sess.emit_err(DeprecatedAttribute { span: *span }); + self.tcx.sess.emit_err(errors::DeprecatedAttribute { span: *span }); } } @@ -219,7 +214,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { if kind == AnnotationKind::Prohibited || (kind == AnnotationKind::Container && stab.level.is_stable() && is_deprecated) { - self.tcx.sess.emit_err(UselessStability { span, item_sp }); + self.tcx.sess.emit_err(errors::UselessStability { span, item_sp }); } debug!("annotate: found {:?}", stab); @@ -235,15 +230,16 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { { match stab_v.parse::() { Err(_) => { - self.tcx.sess.emit_err(InvalidStability { span, item_sp }); + self.tcx.sess.emit_err(errors::InvalidStability { span, item_sp }); break; } Ok(stab_vp) => match dep_v.parse::() { Ok(dep_vp) => match dep_vp.cmp(&stab_vp) { Ordering::Less => { - self.tcx - .sess - .emit_err(CannotStabilizeDeprecated { span, item_sp }); + self.tcx.sess.emit_err(errors::CannotStabilizeDeprecated { + span, + item_sp, + }); break; } Ordering::Equal => continue, @@ -251,9 +247,10 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { }, Err(_) => { if dep_v != "TBD" { - self.tcx - .sess - .emit_err(InvalidDeprecationVersion { span, item_sp }); + self.tcx.sess.emit_err(errors::InvalidDeprecationVersion { + span, + item_sp, + }); } break; } @@ -284,7 +281,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { self.recurse_with_stability_attrs( depr.map(|(d, _)| DeprecationEntry::local(d, def_id)), stab, - if inherit_const_stability.yes() { const_stab } else { None }, + inherit_const_stability.yes().then_some(const_stab).flatten(), visit_children, ); } @@ -526,8 +523,8 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> { && stab.is_none() && self.effective_visibilities.is_reachable(def_id) { - let descr = self.tcx.def_kind(def_id).descr(def_id.to_def_id()); - self.tcx.sess.emit_err(MissingStabilityAttr { span, descr }); + let descr = self.tcx.def_descr(def_id.to_def_id()); + self.tcx.sess.emit_err(errors::MissingStabilityAttr { span, descr }); } } @@ -540,7 +537,7 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> { // 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()) { + if self.tcx.is_automatically_derived(def_id.to_def_id()) { return; } @@ -554,8 +551,8 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> { let is_reachable = self.effective_visibilities.is_reachable(def_id); if is_const && is_stable && missing_const_stability_attribute && is_reachable { - let descr = self.tcx.def_kind(def_id).descr(def_id.to_def_id()); - self.tcx.sess.emit_err(MissingConstStabAttr { span, descr }); + let descr = self.tcx.def_descr(def_id.to_def_id()); + self.tcx.sess.emit_err(errors::MissingConstStabAttr { span, descr }); } } } @@ -751,7 +748,10 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { let mut c = CheckTraitImplStable { tcx: self.tcx, fully_stable: true }; c.visit_ty(self_ty); c.visit_trait_ref(t); - if c.fully_stable { + + // do not lint when the trait isn't resolved, since resolution error should + // be fixed first + if t.path.res != Res::Err && c.fully_stable { self.tcx.struct_span_lint_hir( INEFFECTIVE_UNSTABLE_TRAIT_IMPL, item.hir_id(), @@ -768,7 +768,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { && *constness == hir::Constness::Const && const_stab.map_or(false, |(stab, _)| stab.is_const_stable()) { - self.tcx.sess.emit_err(TraitImplConstStable { span: item.span }); + self.tcx.sess.emit_err(errors::TraitImplConstStable { span: item.span }); } } @@ -855,7 +855,8 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { /// See issue #94972 for details on why this is a special case fn is_unstable_reexport(tcx: TyCtxt<'_>, id: hir::HirId) -> bool { // Get the LocalDefId so we can lookup the item to check the kind. - let Some(def_id) = tcx.hir().opt_local_def_id(id) else { return false; }; + let Some(owner) = id.as_owner() else { return false; }; + let def_id = owner.def_id; let Some(stab) = tcx.stability().local_stability(def_id) else { return false; @@ -946,7 +947,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { } if !lang_features.insert(feature) { // Warn if the user enables a lang feature multiple times. - tcx.sess.emit_err(DuplicateFeatureErr { span, feature }); + tcx.sess.emit_err(errors::DuplicateFeatureErr { span, feature }); } } @@ -954,14 +955,14 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { let mut remaining_lib_features = FxIndexMap::default(); for (feature, span) in declared_lib_features { if !tcx.sess.opts.unstable_features.is_nightly_build() { - tcx.sess.emit_err(FeatureOnlyOnNightly { + tcx.sess.emit_err(errors::FeatureOnlyOnNightly { span: *span, release_channel: env!("CFG_RELEASE_CHANNEL"), }); } if remaining_lib_features.contains_key(&feature) { // Warn if the user enables a lib feature multiple times. - tcx.sess.emit_err(DuplicateFeatureErr { span: *span, feature: *feature }); + tcx.sess.emit_err(errors::DuplicateFeatureErr { span: *span, feature: *feature }); } remaining_lib_features.insert(feature, *span); } @@ -1062,7 +1063,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { } for (feature, span) in remaining_lib_features { - tcx.sess.emit_err(UnknownFeature { span, feature: *feature }); + tcx.sess.emit_err(errors::UnknownFeature { span, feature: *feature }); } for (implied_by, feature) in remaining_implications { @@ -1073,7 +1074,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { .map(|(_, span)| span) .or_else(|| local_defined_features.unstable.get(&feature)) .expect("feature that implied another does not exist"); - tcx.sess.emit_err(ImpliedFeatureNotExist { span, feature, implied_by }); + tcx.sess.emit_err(errors::ImpliedFeatureNotExist { span, feature, implied_by }); } // FIXME(#44232): the `used_features` table no longer exists, so we -- cgit v1.2.3