Skip to content

Commit 7f93d4a

Browse files
committed
Auto merge of rust-lang#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 rust-lang#88180
2 parents 530c0a8 + b38c948 commit 7f93d4a

File tree

5 files changed

+46
-9
lines changed

5 files changed

+46
-9
lines changed

compiler/rustc_attr/src/builtin.rs

+33-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub enum StabilityLevel {
138138
/// `#[unstable]`
139139
Unstable {
140140
/// Reason for the current stability level.
141-
reason: Option<Symbol>,
141+
reason: UnstableReason,
142142
/// Relevant `rust-lang/rust` issue.
143143
issue: Option<NonZeroU32>,
144144
is_soft: bool,
@@ -182,6 +182,32 @@ impl StabilityLevel {
182182
}
183183
}
184184

185+
#[derive(Encodable, Decodable, PartialEq, Copy, Clone, Debug, Eq, Hash)]
186+
#[derive(HashStable_Generic)]
187+
pub enum UnstableReason {
188+
None,
189+
Default,
190+
Some(Symbol),
191+
}
192+
193+
impl UnstableReason {
194+
fn from_opt_reason(reason: Option<Symbol>) -> Self {
195+
// UnstableReason::Default constructed manually
196+
match reason {
197+
Some(r) => Self::Some(r),
198+
None => Self::None,
199+
}
200+
}
201+
202+
pub fn to_opt_reason(&self) -> Option<Symbol> {
203+
match self {
204+
Self::None => None,
205+
Self::Default => Some(sym::unstable_location_reason_default),
206+
Self::Some(r) => Some(*r),
207+
}
208+
}
209+
}
210+
185211
/// Collects stability info from all stability attributes in `attrs`.
186212
/// Returns `None` if no stability attributes are found.
187213
pub fn find_stability(
@@ -371,7 +397,12 @@ where
371397
);
372398
continue;
373399
}
374-
let level = Unstable { reason, issue: issue_num, is_soft, implied_by };
400+
let level = Unstable {
401+
reason: UnstableReason::from_opt_reason(reason),
402+
issue: issue_num,
403+
is_soft,
404+
implied_by,
405+
};
375406
if sym::unstable == meta_name {
376407
stab = Some((Stability { level, feature }, attr.span));
377408
} else {

compiler/rustc_middle/src/middle/stability.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,13 @@ impl<'tcx> TyCtxt<'tcx> {
475475
}
476476

477477
let suggestion = suggestion_for_allocator_api(self, def_id, span, feature);
478-
EvalResult::Deny { feature, reason, issue, suggestion, is_soft }
478+
EvalResult::Deny {
479+
feature,
480+
reason: reason.to_opt_reason(),
481+
issue,
482+
suggestion,
483+
is_soft,
484+
}
479485
}
480486
Some(_) => {
481487
// Stable APIs are always ok to call and deprecated APIs are

compiler/rustc_passes/src/stability.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! propagating default levels lexically from parent to children ast nodes.
33
44
use attr::StabilityLevel;
5-
use rustc_attr::{self as attr, ConstStability, Stability, Unstable};
5+
use rustc_attr::{self as attr, ConstStability, Stability, Unstable, UnstableReason};
66
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
77
use rustc_errors::{struct_span_err, Applicability};
88
use rustc_hir as hir;
@@ -634,12 +634,9 @@ fn stability_index(tcx: TyCtxt<'_>, (): ()) -> Index {
634634
// while maintaining the invariant that all sysroot crates are unstable
635635
// by default and are unable to be used.
636636
if tcx.sess.opts.unstable_opts.force_unstable_if_unmarked {
637-
let reason = "this crate is being loaded from the sysroot, an \
638-
unstable location; did you mean to load this crate \
639-
from crates.io via `Cargo.toml` instead?";
640637
let stability = Stability {
641638
level: attr::StabilityLevel::Unstable {
642-
reason: Some(Symbol::intern(reason)),
639+
reason: UnstableReason::Default,
643640
issue: NonZeroU32::new(27812),
644641
is_soft: false,
645642
implied_by: None,

compiler/rustc_resolve/src/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ impl<'a> Resolver<'a> {
812812
stability::report_unstable(
813813
self.session,
814814
feature,
815-
reason,
815+
reason.to_opt_reason(),
816816
issue,
817817
None,
818818
is_soft,

compiler/rustc_span/src/symbol.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1528,6 +1528,9 @@ symbols! {
15281528
unsized_locals,
15291529
unsized_tuple_coercion,
15301530
unstable,
1531+
unstable_location_reason_default: "this crate is being loaded from the sysroot, an \
1532+
unstable location; did you mean to load this crate \
1533+
from crates.io via `Cargo.toml` instead?",
15311534
untagged_unions,
15321535
unused_imports,
15331536
unused_qualifications,

0 commit comments

Comments
 (0)