diff options
Diffstat (limited to 'compiler/rustc_passes/src/stability.rs')
-rw-r--r-- | compiler/rustc_passes/src/stability.rs | 68 |
1 files changed, 26 insertions, 42 deletions
diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 4a35c6794..b81b7ad60 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -7,7 +7,6 @@ use rustc_attr::{ UnstableReason, VERSION_PLACEHOLDER, }; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; -use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID}; @@ -17,7 +16,8 @@ use rustc_hir::{FieldDef, Item, ItemKind, TraitRef, Ty, TyKind, Variant}; use rustc_middle::hir::nested_filter; use rustc_middle::middle::privacy::EffectiveVisibilities; use rustc_middle::middle::stability::{AllowUnstable, DeprecationEntry, Index}; -use rustc_middle::ty::{query::Providers, TyCtxt}; +use rustc_middle::query::Providers; +use rustc_middle::ty::TyCtxt; use rustc_session::lint; use rustc_session::lint::builtin::{INEFFECTIVE_UNSTABLE_TRAIT_IMPL, USELESS_DEPRECATED}; use rustc_span::symbol::{sym, Symbol}; @@ -554,10 +554,8 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> { 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 - .tcx - .lookup_stability(def_id) - .map_or(false, |stability| stability.level.is_stable()); + let is_stable = + self.tcx.lookup_stability(def_id).is_some_and(|stability| stability.level.is_stable()); let missing_const_stability_attribute = self.tcx.lookup_const_stability(def_id).is_none(); let is_reachable = self.effective_visibilities.is_reachable(def_id); @@ -759,12 +757,11 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { // 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( + self.tcx.emit_spanned_lint( INEFFECTIVE_UNSTABLE_TRAIT_IMPL, item.hir_id(), span, - "an `#[unstable]` annotation here has no effect", - |lint| lint.note("see issue #55436 <https://github.com/rust-lang/rust/issues/55436> for more information") + errors::IneffectiveUnstableImpl, ); } } @@ -773,7 +770,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { // needs to have an error emitted. if features.const_trait_impl && *constness == hir::Constness::Const - && const_stab.map_or(false, |(stab, _)| stab.is_const_stable()) + && const_stab.is_some_and(|(stab, _)| stab.is_const_stable()) { self.tcx.sess.emit_err(errors::TraitImplConstStable { span: item.span }); } @@ -810,15 +807,12 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { ); let is_allowed_through_unstable_modules = |def_id| { - self.tcx - .lookup_stability(def_id) - .map(|stab| match stab.level { - StabilityLevel::Stable { allowed_through_unstable_modules, .. } => { - allowed_through_unstable_modules - } - _ => false, - }) - .unwrap_or(false) + self.tcx.lookup_stability(def_id).is_some_and(|stab| match stab.level { + StabilityLevel::Stable { allowed_through_unstable_modules, .. } => { + allowed_through_unstable_modules + } + _ => false, + }) }; if item_is_allowed && !is_allowed_through_unstable_modules(def_id) { @@ -1095,29 +1089,16 @@ fn unnecessary_partially_stable_feature_lint( implies: Symbol, since: Symbol, ) { - tcx.struct_span_lint_hir( + tcx.emit_spanned_lint( lint::builtin::STABLE_FEATURES, hir::CRATE_HIR_ID, span, - format!( - "the feature `{feature}` has been partially stabilized since {since} and is succeeded \ - by the feature `{implies}`" - ), - |lint| { - lint.span_suggestion( - span, - &format!( - "if you are using features which are still unstable, change to using `{implies}`" - ), - implies, - Applicability::MaybeIncorrect, - ) - .span_suggestion( - tcx.sess.source_map().span_extend_to_line(span), - "if you are using features which are now stable, remove this line", - "", - Applicability::MaybeIncorrect, - ) + errors::UnnecessaryPartialStableFeature { + span, + line: tcx.sess.source_map().span_extend_to_line(span), + feature, + since, + implies, }, ); } @@ -1131,7 +1112,10 @@ fn unnecessary_stable_feature_lint( if since.as_str() == VERSION_PLACEHOLDER { since = rust_version_symbol(); } - tcx.struct_span_lint_hir(lint::builtin::STABLE_FEATURES, hir::CRATE_HIR_ID, span, format!("the feature `{feature}` has been stable since {since} and no longer requires an attribute to enable"), |lint| { - lint - }); + tcx.emit_spanned_lint( + lint::builtin::STABLE_FEATURES, + hir::CRATE_HIR_ID, + span, + errors::UnnecessaryStableFeature { feature, since }, + ); } |