avoid embedding StabilityLevel::Unstable reason string into metadata multiple times
This commit is contained in:
parent
1673f1450e
commit
b38c94857d
5 changed files with 46 additions and 9 deletions
|
@ -138,7 +138,7 @@ pub enum StabilityLevel {
|
||||||
/// `#[unstable]`
|
/// `#[unstable]`
|
||||||
Unstable {
|
Unstable {
|
||||||
/// Reason for the current stability level.
|
/// Reason for the current stability level.
|
||||||
reason: Option<Symbol>,
|
reason: UnstableReason,
|
||||||
/// Relevant `rust-lang/rust` issue.
|
/// Relevant `rust-lang/rust` issue.
|
||||||
issue: Option<NonZeroU32>,
|
issue: Option<NonZeroU32>,
|
||||||
is_soft: bool,
|
is_soft: bool,
|
||||||
|
@ -182,6 +182,32 @@ impl StabilityLevel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Encodable, Decodable, PartialEq, Copy, Clone, Debug, Eq, Hash)]
|
||||||
|
#[derive(HashStable_Generic)]
|
||||||
|
pub enum UnstableReason {
|
||||||
|
None,
|
||||||
|
Default,
|
||||||
|
Some(Symbol),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UnstableReason {
|
||||||
|
fn from_opt_reason(reason: Option<Symbol>) -> Self {
|
||||||
|
// UnstableReason::Default constructed manually
|
||||||
|
match reason {
|
||||||
|
Some(r) => Self::Some(r),
|
||||||
|
None => Self::None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_opt_reason(&self) -> Option<Symbol> {
|
||||||
|
match self {
|
||||||
|
Self::None => None,
|
||||||
|
Self::Default => Some(sym::unstable_location_reason_default),
|
||||||
|
Self::Some(r) => Some(*r),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Collects stability info from all stability attributes in `attrs`.
|
/// Collects stability info from all stability attributes in `attrs`.
|
||||||
/// Returns `None` if no stability attributes are found.
|
/// Returns `None` if no stability attributes are found.
|
||||||
pub fn find_stability(
|
pub fn find_stability(
|
||||||
|
@ -371,7 +397,12 @@ where
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let level = Unstable { reason, issue: issue_num, is_soft, implied_by };
|
let level = Unstable {
|
||||||
|
reason: UnstableReason::from_opt_reason(reason),
|
||||||
|
issue: issue_num,
|
||||||
|
is_soft,
|
||||||
|
implied_by,
|
||||||
|
};
|
||||||
if sym::unstable == meta_name {
|
if sym::unstable == meta_name {
|
||||||
stab = Some((Stability { level, feature }, attr.span));
|
stab = Some((Stability { level, feature }, attr.span));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -475,7 +475,13 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let suggestion = suggestion_for_allocator_api(self, def_id, span, feature);
|
let suggestion = suggestion_for_allocator_api(self, def_id, span, feature);
|
||||||
EvalResult::Deny { feature, reason, issue, suggestion, is_soft }
|
EvalResult::Deny {
|
||||||
|
feature,
|
||||||
|
reason: reason.to_opt_reason(),
|
||||||
|
issue,
|
||||||
|
suggestion,
|
||||||
|
is_soft,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
// Stable APIs are always ok to call and deprecated APIs are
|
// Stable APIs are always ok to call and deprecated APIs are
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
//! propagating default levels lexically from parent to children ast nodes.
|
//! propagating default levels lexically from parent to children ast nodes.
|
||||||
|
|
||||||
use attr::StabilityLevel;
|
use attr::StabilityLevel;
|
||||||
use rustc_attr::{self as attr, ConstStability, Stability, Unstable};
|
use rustc_attr::{self as attr, ConstStability, Stability, Unstable, UnstableReason};
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
|
||||||
use rustc_errors::{struct_span_err, Applicability};
|
use rustc_errors::{struct_span_err, Applicability};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
|
@ -634,12 +634,9 @@ fn stability_index(tcx: TyCtxt<'_>, (): ()) -> Index {
|
||||||
// while maintaining the invariant that all sysroot crates are unstable
|
// while maintaining the invariant that all sysroot crates are unstable
|
||||||
// by default and are unable to be used.
|
// by default and are unable to be used.
|
||||||
if tcx.sess.opts.unstable_opts.force_unstable_if_unmarked {
|
if tcx.sess.opts.unstable_opts.force_unstable_if_unmarked {
|
||||||
let reason = "this crate is being loaded from the sysroot, an \
|
|
||||||
unstable location; did you mean to load this crate \
|
|
||||||
from crates.io via `Cargo.toml` instead?";
|
|
||||||
let stability = Stability {
|
let stability = Stability {
|
||||||
level: attr::StabilityLevel::Unstable {
|
level: attr::StabilityLevel::Unstable {
|
||||||
reason: Some(Symbol::intern(reason)),
|
reason: UnstableReason::Default,
|
||||||
issue: NonZeroU32::new(27812),
|
issue: NonZeroU32::new(27812),
|
||||||
is_soft: false,
|
is_soft: false,
|
||||||
implied_by: None,
|
implied_by: None,
|
||||||
|
|
|
@ -812,7 +812,7 @@ impl<'a> Resolver<'a> {
|
||||||
stability::report_unstable(
|
stability::report_unstable(
|
||||||
self.session,
|
self.session,
|
||||||
feature,
|
feature,
|
||||||
reason,
|
reason.to_opt_reason(),
|
||||||
issue,
|
issue,
|
||||||
None,
|
None,
|
||||||
is_soft,
|
is_soft,
|
||||||
|
|
|
@ -1527,6 +1527,9 @@ symbols! {
|
||||||
unsized_locals,
|
unsized_locals,
|
||||||
unsized_tuple_coercion,
|
unsized_tuple_coercion,
|
||||||
unstable,
|
unstable,
|
||||||
|
unstable_location_reason_default: "this crate is being loaded from the sysroot, an \
|
||||||
|
unstable location; did you mean to load this crate \
|
||||||
|
from crates.io via `Cargo.toml` instead?",
|
||||||
untagged_unions,
|
untagged_unions,
|
||||||
unused_imports,
|
unused_imports,
|
||||||
unused_qualifications,
|
unused_qualifications,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue