Skip to content

Commit 9a52401

Browse files
committed
Add and use stability helper methods
This avoids an ambiguity (when reading) where `.level.is_stable()` is not immediately clear whether it is general stability or const stability.
1 parent 0b94fa4 commit 9a52401

File tree

8 files changed

+30
-15
lines changed

8 files changed

+30
-15
lines changed

compiler/rustc_attr/src/builtin.rs

+20
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ pub struct Stability {
101101
pub feature: Symbol,
102102
}
103103

104+
impl Stability {
105+
pub fn is_unstable(&self) -> bool {
106+
self.level.is_unstable()
107+
}
108+
109+
pub fn is_stable(&self) -> bool {
110+
self.level.is_stable()
111+
}
112+
}
113+
104114
/// Represents the `#[rustc_const_unstable]` and `#[rustc_const_stable]` attributes.
105115
#[derive(Encodable, Decodable, Copy, Clone, Debug, PartialEq, Eq, Hash)]
106116
#[derive(HashStable_Generic)]
@@ -111,6 +121,16 @@ pub struct ConstStability {
111121
pub promotable: bool,
112122
}
113123

124+
impl ConstStability {
125+
pub fn is_const_unstable(&self) -> bool {
126+
self.level.is_unstable()
127+
}
128+
129+
pub fn is_const_stable(&self) -> bool {
130+
self.level.is_stable()
131+
}
132+
}
133+
114134
/// The available stability levels.
115135
#[derive(Encodable, Decodable, PartialEq, Copy, Clone, Debug, Eq, Hash)]
116136
#[derive(HashStable_Generic)]

compiler/rustc_const_eval/src/const_eval/fn_queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_target::spec::abi::Abi;
99
pub fn is_unstable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Symbol> {
1010
if tcx.is_const_fn_raw(def_id) {
1111
let const_stab = tcx.lookup_const_stability(def_id)?;
12-
if const_stab.level.is_unstable() { Some(const_stab.feature) } else { None }
12+
if const_stab.is_const_unstable() { Some(const_stab.feature) } else { None }
1313
} else {
1414
None
1515
}

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
938938
// have no `rustc_const_stable` attributes to be const-unstable as well. This
939939
// should be fixed later.
940940
let callee_is_unstable_unmarked = tcx.lookup_const_stability(callee).is_none()
941-
&& tcx.lookup_stability(callee).map_or(false, |s| s.level.is_unstable());
941+
&& tcx.lookup_stability(callee).map_or(false, |s| s.is_unstable());
942942
if callee_is_unstable_unmarked {
943943
trace!("callee_is_unstable_unmarked");
944944
// We do not use `const` modifiers for intrinsic "functions", as intrinsics are

compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2785,7 +2785,7 @@ impl<'tcx> TyCtxt<'tcx> {
27852785
pub fn is_const_fn(self, def_id: DefId) -> bool {
27862786
if self.is_const_fn_raw(def_id) {
27872787
match self.lookup_const_stability(def_id) {
2788-
Some(stability) if stability.level.is_unstable() => {
2788+
Some(stability) if stability.is_const_unstable() => {
27892789
// has a `rustc_const_unstable` attribute, check whether the user enabled the
27902790
// corresponding feature gate.
27912791
self.features()

compiler/rustc_passes/src/stability.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
147147
// Propagate unstability. This can happen even for non-staged-api crates in case
148148
// -Zforce-unstable-if-unmarked is set.
149149
if let Some(stab) = self.parent_stab {
150-
if inherit_deprecation.yes() && stab.level.is_unstable() {
150+
if inherit_deprecation.yes() && stab.is_unstable() {
151151
self.index.stab_map.insert(def_id, stab);
152152
}
153153
}
@@ -190,7 +190,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
190190
if const_stab.is_none() {
191191
debug!("annotate: const_stab not found, parent = {:?}", self.parent_const_stab);
192192
if let Some(parent) = self.parent_const_stab {
193-
if parent.level.is_unstable() {
193+
if parent.is_const_unstable() {
194194
self.index.const_stab_map.insert(def_id, parent);
195195
}
196196
}
@@ -272,9 +272,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
272272
if stab.is_none() {
273273
debug!("annotate: stab not found, parent = {:?}", self.parent_stab);
274274
if let Some(stab) = self.parent_stab {
275-
if inherit_deprecation.yes() && stab.level.is_unstable()
276-
|| inherit_from_parent.yes()
277-
{
275+
if inherit_deprecation.yes() && stab.is_unstable() || inherit_from_parent.yes() {
278276
self.index.stab_map.insert(def_id, stab);
279277
}
280278
}

src/librustdoc/clean/inline.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ crate fn build_impl(
351351
}
352352

353353
if let Some(stab) = tcx.lookup_stability(did) {
354-
if stab.level.is_unstable() && stab.feature == sym::rustc_private {
354+
if stab.is_unstable() && stab.feature == sym::rustc_private {
355355
return;
356356
}
357357
}
@@ -380,7 +380,7 @@ crate fn build_impl(
380380
}
381381

382382
if let Some(stab) = tcx.lookup_stability(did) {
383-
if stab.level.is_unstable() && stab.feature == sym::rustc_private {
383+
if stab.is_unstable() && stab.feature == sym::rustc_private {
384384
return;
385385
}
386386
}

src/librustdoc/clean/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ impl Item {
597597
self.stability(tcx).as_ref().and_then(|s| {
598598
let mut classes = Vec::with_capacity(2);
599599

600-
if s.level.is_unstable() {
600+
if s.is_unstable() {
601601
classes.push("unstable");
602602
}
603603

src/librustdoc/html/render/print_item.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,7 @@ fn extra_info_tags(item: &clean::Item, parent: &clean::Item, tcx: TyCtxt<'_>) ->
430430

431431
// The "rustc_private" crates are permanently unstable so it makes no sense
432432
// to render "unstable" everywhere.
433-
if item
434-
.stability(tcx)
435-
.as_ref()
436-
.map(|s| s.level.is_unstable() && s.feature != sym::rustc_private)
433+
if item.stability(tcx).as_ref().map(|s| s.is_unstable() && s.feature != sym::rustc_private)
437434
== Some(true)
438435
{
439436
tags += &tag_html("unstable", "", "Experimental");

0 commit comments

Comments
 (0)