@@ -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.
187213pub 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 {
0 commit comments