Skip to content

Commit a9dd4cf

Browse files
jhprattoli-obk
authored andcommitted
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 f53fc41 commit a9dd4cf

File tree

8 files changed

+30
-15
lines changed

8 files changed

+30
-15
lines changed

compiler/rustc_attr/src/builtin.rs

Lines changed: 20 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_span::symbol::Symbol;
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
944944
// have no `rustc_const_stable` attributes to be const-unstable as well. This
945945
// should be fixed later.
946946
let callee_is_unstable_unmarked = tcx.lookup_const_stability(callee).is_none()
947-
&& tcx.lookup_stability(callee).map_or(false, |s| s.level.is_unstable());
947+
&& tcx.lookup_stability(callee).map_or(false, |s| s.is_unstable());
948948
if callee_is_unstable_unmarked {
949949
trace!("callee_is_unstable_unmarked");
950950
// We do not use `const` modifiers for intrinsic "functions", as intrinsics are

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2791,7 +2791,7 @@ impl<'tcx> TyCtxt<'tcx> {
27912791
pub fn is_const_fn(self, def_id: DefId) -> bool {
27922792
if self.is_const_fn_raw(def_id) {
27932793
match self.lookup_const_stability(def_id) {
2794-
Some(stability) if stability.level.is_unstable() => {
2794+
Some(stability) if stability.is_const_unstable() => {
27952795
// has a `rustc_const_unstable` attribute, check whether the user enabled the
27962796
// corresponding feature gate.
27972797
self.features()

compiler/rustc_passes/src/stability.rs

Lines changed: 3 additions & 5 deletions
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ crate fn build_impl(
344344
}
345345

346346
if let Some(stab) = tcx.lookup_stability(did) {
347-
if stab.level.is_unstable() && stab.feature == sym::rustc_private {
347+
if stab.is_unstable() && stab.feature == sym::rustc_private {
348348
return;
349349
}
350350
}
@@ -373,7 +373,7 @@ crate fn build_impl(
373373
}
374374

375375
if let Some(stab) = tcx.lookup_stability(did) {
376-
if stab.level.is_unstable() && stab.feature == sym::rustc_private {
376+
if stab.is_unstable() && stab.feature == sym::rustc_private {
377377
return;
378378
}
379379
}

src/librustdoc/clean/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ impl Item {
632632
self.stability(tcx).as_ref().and_then(|s| {
633633
let mut classes = Vec::with_capacity(2);
634634

635-
if s.level.is_unstable() {
635+
if s.is_unstable() {
636636
classes.push("unstable");
637637
}
638638

src/librustdoc/html/render/print_item.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,7 @@ fn extra_info_tags(item: &clean::Item, parent: &clean::Item, tcx: TyCtxt<'_>) ->
445445

446446
// The "rustc_private" crates are permanently unstable so it makes no sense
447447
// to render "unstable" everywhere.
448-
if item
449-
.stability(tcx)
450-
.as_ref()
451-
.map(|s| s.level.is_unstable() && s.feature != sym::rustc_private)
448+
if item.stability(tcx).as_ref().map(|s| s.is_unstable() && s.feature != sym::rustc_private)
452449
== Some(true)
453450
{
454451
tags += &tag_html("unstable", "", "Experimental");

0 commit comments

Comments
 (0)