]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_attr/src/builtin.rs
Rollup merge of #99651 - compiler-errors:fn-and-raw-ptr-in-const-generics, r=oli-obk
[rust.git] / compiler / rustc_attr / src / builtin.rs
index 64a6f91f02206f6472f00a6ada3ef730d94c5045..10a9cfb626e63391ae7ae22a439f1d13d9f2a907 100644 (file)
@@ -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 @@ pub fn is_stable(&self) -> bool {
     }
 }
 
+#[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 @@ fn find_stability_generic<'a, I>(
                                 );
                                 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 {