@@ -16,9 +16,9 @@ use rustc_session::lint::BuiltinLintDiag;
1616use rustc_session:: lint:: builtin:: UNEXPECTED_CFGS ;
1717use rustc_session:: parse:: feature_err;
1818use rustc_session:: { RustcVersion , Session } ;
19+ use rustc_span:: Span ;
1920use rustc_span:: hygiene:: Transparency ;
2021use rustc_span:: symbol:: { Symbol , kw, sym} ;
21- use rustc_span:: { DUMMY_SP , Span } ;
2222
2323use crate :: fluent_generated;
2424use crate :: session_diagnostics:: { self , IncorrectReprFormatGenericCause } ;
@@ -92,9 +92,7 @@ impl Stability {
9292#[ derive( HashStable_Generic ) ]
9393pub struct ConstStability {
9494 pub level : StabilityLevel ,
95- /// This can be `None` for functions that do not have an explicit const feature.
96- /// We still track them for recursive const stability checks.
97- pub feature : Option < Symbol > ,
95+ pub feature : Symbol ,
9896 /// This is true iff the `const_stable_indirect` attribute is present.
9997 pub const_stable_indirect : bool ,
10098 /// whether the function has a `#[rustc_promotable]` attribute
@@ -272,22 +270,19 @@ pub fn find_stability(
272270
273271/// Collects stability info from `rustc_const_stable`/`rustc_const_unstable`/`rustc_promotable`
274272/// attributes in `attrs`. Returns `None` if no stability attributes are found.
275- ///
276- /// `is_const_fn` indicates whether this is a function marked as `const`.
277273pub fn find_const_stability (
278274 sess : & Session ,
279275 attrs : & [ Attribute ] ,
280276 item_sp : Span ,
281- is_const_fn : bool ,
282277) -> Option < ( ConstStability , Span ) > {
283278 let mut const_stab: Option < ( ConstStability , Span ) > = None ;
284279 let mut promotable = false ;
285- let mut const_stable_indirect = None ;
280+ let mut const_stable_indirect = false ;
286281
287282 for attr in attrs {
288283 match attr. name_or_empty ( ) {
289284 sym:: rustc_promotable => promotable = true ,
290- sym:: rustc_const_stable_indirect => const_stable_indirect = Some ( attr . span ) ,
285+ sym:: rustc_const_stable_indirect => const_stable_indirect = true ,
291286 sym:: rustc_const_unstable => {
292287 if const_stab. is_some ( ) {
293288 sess. dcx ( )
@@ -299,7 +294,7 @@ pub fn find_const_stability(
299294 const_stab = Some ( (
300295 ConstStability {
301296 level,
302- feature : Some ( feature ) ,
297+ feature,
303298 const_stable_indirect : false ,
304299 promotable : false ,
305300 } ,
@@ -317,7 +312,7 @@ pub fn find_const_stability(
317312 const_stab = Some ( (
318313 ConstStability {
319314 level,
320- feature : Some ( feature ) ,
315+ feature,
321316 const_stable_indirect : false ,
322317 promotable : false ,
323318 } ,
@@ -340,7 +335,7 @@ pub fn find_const_stability(
340335 }
341336 }
342337 }
343- if const_stable_indirect. is_some ( ) {
338+ if const_stable_indirect {
344339 match & mut const_stab {
345340 Some ( ( stab, _) ) => {
346341 if stab. is_const_unstable ( ) {
@@ -351,36 +346,37 @@ pub fn find_const_stability(
351346 } )
352347 }
353348 }
354- _ => { }
349+ _ => {
350+ // This function has no const stability attribute, but has `const_stable_indirect`.
351+ // We ignore that; unmarked functions are subject to recursive const stability
352+ // checks by default so we do carry out the user's intent.
353+ }
355354 }
356355 }
357- // Make sure if `const_stable_indirect` is present, that is recorded. Also make sure all `const
358- // fn` get *some* marker, since we are a staged_api crate and therefore will do recursive const
359- // stability checks for them. We need to do this because the default for whether an unmarked
360- // function enforces recursive stability differs between staged-api crates and force-unmarked
361- // crates: in force-unmarked crates, only functions *explicitly* marked `const_stable_indirect`
362- // enforce recursive stability. Therefore when `lookup_const_stability` is `None`, we have to
363- // assume the function does not have recursive stability. All functions that *do* have recursive
364- // stability must explicitly record this, and so that's what we do for all `const fn` in a
365- // staged_api crate.
366- if ( is_const_fn || const_stable_indirect. is_some ( ) ) && const_stab. is_none ( ) {
367- let c = ConstStability {
368- feature : None ,
369- const_stable_indirect : const_stable_indirect. is_some ( ) ,
370- promotable : false ,
371- level : StabilityLevel :: Unstable {
372- reason : UnstableReason :: Default ,
373- issue : None ,
374- is_soft : false ,
375- implied_by : None ,
376- } ,
377- } ;
378- const_stab = Some ( ( c, const_stable_indirect. unwrap_or ( DUMMY_SP ) ) ) ;
379- }
380356
381357 const_stab
382358}
383359
360+ /// Calculates the const stability for a const function in a `-Zforce-unstable-if-unmarked` crate
361+ /// without the `staged_api` feature.
362+ pub fn unmarked_crate_const_stab (
363+ _sess : & Session ,
364+ attrs : & [ Attribute ] ,
365+ regular_stab : Stability ,
366+ ) -> ConstStability {
367+ assert ! ( regular_stab. level. is_unstable( ) ) ;
368+ // The only attribute that matters here is `rustc_const_stable_indirect`.
369+ // We enforce recursive const stability rules for those functions.
370+ let const_stable_indirect =
371+ attrs. iter ( ) . any ( |a| a. name_or_empty ( ) == sym:: rustc_const_stable_indirect) ;
372+ ConstStability {
373+ feature : regular_stab. feature ,
374+ const_stable_indirect,
375+ promotable : false ,
376+ level : regular_stab. level ,
377+ }
378+ }
379+
384380/// Collects stability info from `rustc_default_body_unstable` attributes in `attrs`.
385381/// Returns `None` if no stability attributes are found.
386382pub fn find_body_stability (
0 commit comments