mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Auto merge of #98770 - klensy:no-string-dupes-ugly, r=cjgillot
rmeta: avoid embedding `StabilityLevel::Unstable` reason multiple times into .rmeta\.rlib files Avoids bloating size of some rmeta\rlib files by not placing default string for `StabilityLevel::Unstable` reason multiple times, affects only stdlib\rustc artifacts. For stdlib cuts about 3% (diff of total size for patched\unpatched *.rmeta files of stage1-std) of file size, depending on crates. fixes #88180
This commit is contained in:
commit
7f93d4aa0d
@ -138,7 +138,7 @@ pub enum StabilityLevel {
|
||||
/// `#[unstable]`
|
||||
Unstable {
|
||||
/// Reason for the current stability level.
|
||||
reason: Option<Symbol>,
|
||||
reason: UnstableReason,
|
||||
/// Relevant `rust-lang/rust` issue.
|
||||
issue: Option<NonZeroU32>,
|
||||
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`.
|
||||
/// Returns `None` if no stability attributes are found.
|
||||
pub fn find_stability(
|
||||
@ -371,7 +397,12 @@ where
|
||||
);
|
||||
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 {
|
||||
stab = Some((Stability { level, feature }, attr.span));
|
||||
} else {
|
||||
|
@ -475,7 +475,13 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
}
|
||||
|
||||
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(_) => {
|
||||
// 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.
|
||||
|
||||
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_errors::{struct_span_err, Applicability};
|
||||
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
|
||||
// by default and are unable to be used.
|
||||
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 {
|
||||
level: attr::StabilityLevel::Unstable {
|
||||
reason: Some(Symbol::intern(reason)),
|
||||
reason: UnstableReason::Default,
|
||||
issue: NonZeroU32::new(27812),
|
||||
is_soft: false,
|
||||
implied_by: None,
|
||||
|
@ -812,7 +812,7 @@ impl<'a> Resolver<'a> {
|
||||
stability::report_unstable(
|
||||
self.session,
|
||||
feature,
|
||||
reason,
|
||||
reason.to_opt_reason(),
|
||||
issue,
|
||||
None,
|
||||
is_soft,
|
||||
|
@ -1528,6 +1528,9 @@ symbols! {
|
||||
unsized_locals,
|
||||
unsized_tuple_coercion,
|
||||
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,
|
||||
unused_imports,
|
||||
unused_qualifications,
|
||||
|
Loading…
Reference in New Issue
Block a user