]> git.lizzy.rs Git - rust.git/commitdiff
Add and use stability helper methods
authorJacob Pratt <jacob@jhpratt.dev>
Tue, 8 Feb 2022 09:52:11 +0000 (04:52 -0500)
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>
Thu, 19 May 2022 12:21:45 +0000 (12:21 +0000)
This avoids an ambiguity (when reading) where `.level.is_stable()` is
not immediately clear whether it is general stability or const
stability.

compiler/rustc_attr/src/builtin.rs
compiler/rustc_const_eval/src/const_eval/fn_queries.rs
compiler/rustc_const_eval/src/transform/check_consts/check.rs
compiler/rustc_middle/src/ty/context.rs
compiler/rustc_passes/src/stability.rs
src/librustdoc/clean/inline.rs
src/librustdoc/clean/types.rs
src/librustdoc/html/render/print_item.rs

index 3d4bd222715c3950a54ca4a4f4bdef75ff22279b..2704cb8d78538da8497e3d793e4eb97591077f82 100644 (file)
@@ -101,6 +101,16 @@ pub struct Stability {
     pub feature: Symbol,
 }
 
+impl Stability {
+    pub fn is_unstable(&self) -> bool {
+        self.level.is_unstable()
+    }
+
+    pub fn is_stable(&self) -> bool {
+        self.level.is_stable()
+    }
+}
+
 /// Represents the `#[rustc_const_unstable]` and `#[rustc_const_stable]` attributes.
 #[derive(Encodable, Decodable, Copy, Clone, Debug, PartialEq, Eq, Hash)]
 #[derive(HashStable_Generic)]
@@ -111,6 +121,16 @@ pub struct ConstStability {
     pub promotable: bool,
 }
 
+impl ConstStability {
+    pub fn is_const_unstable(&self) -> bool {
+        self.level.is_unstable()
+    }
+
+    pub fn is_const_stable(&self) -> bool {
+        self.level.is_stable()
+    }
+}
+
 /// The available stability levels.
 #[derive(Encodable, Decodable, PartialEq, Copy, Clone, Debug, Eq, Hash)]
 #[derive(HashStable_Generic)]
index 777f4393458e2b3f4033790c02d1e98366ef5de5..d6f62062d1f8ee39c8348249bcf949a96b37a9f1 100644 (file)
@@ -9,7 +9,7 @@
 pub fn is_unstable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Symbol> {
     if tcx.is_const_fn_raw(def_id) {
         let const_stab = tcx.lookup_const_stability(def_id)?;
-        if const_stab.level.is_unstable() { Some(const_stab.feature) } else { None }
+        if const_stab.is_const_unstable() { Some(const_stab.feature) } else { None }
     } else {
         None
     }
index 1104bbf4716826d24aea7b647423598f90496a8c..7f9f5dc39a1fb6eca2cab43b3f364f1cc75e5c72 100644 (file)
@@ -944,7 +944,7 @@ fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location
                 // have no `rustc_const_stable` attributes to be const-unstable as well. This
                 // should be fixed later.
                 let callee_is_unstable_unmarked = tcx.lookup_const_stability(callee).is_none()
-                    && tcx.lookup_stability(callee).map_or(false, |s| s.level.is_unstable());
+                    && tcx.lookup_stability(callee).map_or(false, |s| s.is_unstable());
                 if callee_is_unstable_unmarked {
                     trace!("callee_is_unstable_unmarked");
                     // We do not use `const` modifiers for intrinsic "functions", as intrinsics are
index 1616b753433a83c0e47415865ca3e67836870677..fa519ede4eaf2b5189bd852432ad247603c93096 100644 (file)
@@ -2791,7 +2791,7 @@ pub fn lifetime_scope(self, id: HirId) -> Option<&'tcx LifetimeScopeForPath> {
     pub fn is_const_fn(self, def_id: DefId) -> bool {
         if self.is_const_fn_raw(def_id) {
             match self.lookup_const_stability(def_id) {
-                Some(stability) if stability.level.is_unstable() => {
+                Some(stability) if stability.is_const_unstable() => {
                     // has a `rustc_const_unstable` attribute, check whether the user enabled the
                     // corresponding feature gate.
                     self.features()
index 58195fce281975b5e0245c204214c6e5cbc955a0..b96322db26efd44cd85550f254bb609eeac34a26 100644 (file)
@@ -147,7 +147,7 @@ fn annotate<F>(
             // Propagate unstability.  This can happen even for non-staged-api crates in case
             // -Zforce-unstable-if-unmarked is set.
             if let Some(stab) = self.parent_stab {
-                if inherit_deprecation.yes() && stab.level.is_unstable() {
+                if inherit_deprecation.yes() && stab.is_unstable() {
                     self.index.stab_map.insert(def_id, stab);
                 }
             }
@@ -190,7 +190,7 @@ fn annotate<F>(
         if const_stab.is_none() {
             debug!("annotate: const_stab not found, parent = {:?}", self.parent_const_stab);
             if let Some(parent) = self.parent_const_stab {
-                if parent.level.is_unstable() {
+                if parent.is_const_unstable() {
                     self.index.const_stab_map.insert(def_id, parent);
                 }
             }
@@ -272,9 +272,7 @@ fn annotate<F>(
         if stab.is_none() {
             debug!("annotate: stab not found, parent = {:?}", self.parent_stab);
             if let Some(stab) = self.parent_stab {
-                if inherit_deprecation.yes() && stab.level.is_unstable()
-                    || inherit_from_parent.yes()
-                {
+                if inherit_deprecation.yes() && stab.is_unstable() || inherit_from_parent.yes() {
                     self.index.stab_map.insert(def_id, stab);
                 }
             }
index 9a579cb5311642487251b5697021af5532b4dba3..6b73634afbc2ec43e1d68e0cf7fcf6727e68391a 100644 (file)
@@ -344,7 +344,7 @@ fn merge_attrs(
             }
 
             if let Some(stab) = tcx.lookup_stability(did) {
-                if stab.level.is_unstable() && stab.feature == sym::rustc_private {
+                if stab.is_unstable() && stab.feature == sym::rustc_private {
                     return;
                 }
             }
@@ -373,7 +373,7 @@ fn merge_attrs(
             }
 
             if let Some(stab) = tcx.lookup_stability(did) {
-                if stab.level.is_unstable() && stab.feature == sym::rustc_private {
+                if stab.is_unstable() && stab.feature == sym::rustc_private {
                     return;
                 }
             }
index 456d860f12559d4832c5df65e9d0121bafa127d1..934de5471fe136fda205660d51c2e080b9cecc29 100644 (file)
@@ -632,7 +632,7 @@ impl Item {
         self.stability(tcx).as_ref().and_then(|s| {
             let mut classes = Vec::with_capacity(2);
 
-            if s.level.is_unstable() {
+            if s.is_unstable() {
                 classes.push("unstable");
             }
 
index 4951cd83af207a3635d1aa4c6c7a10d0bce8663b..e0f4083a9181249f2620705221fa730e0f2b8331 100644 (file)
@@ -445,10 +445,7 @@ fn tag_html(class: &str, title: &str, contents: &str) -> String {
 
     // The "rustc_private" crates are permanently unstable so it makes no sense
     // to render "unstable" everywhere.
-    if item
-        .stability(tcx)
-        .as_ref()
-        .map(|s| s.level.is_unstable() && s.feature != sym::rustc_private)
+    if item.stability(tcx).as_ref().map(|s| s.is_unstable() && s.feature != sym::rustc_private)
         == Some(true)
     {
         tags += &tag_html("unstable", "", "Experimental");