@@ -16,9 +16,9 @@ use rustc_session::lint::BuiltinLintDiag;
16
16
use rustc_session:: lint:: builtin:: UNEXPECTED_CFGS ;
17
17
use rustc_session:: parse:: feature_err;
18
18
use rustc_session:: { RustcVersion , Session } ;
19
+ use rustc_span:: Span ;
19
20
use rustc_span:: hygiene:: Transparency ;
20
21
use rustc_span:: symbol:: { Symbol , kw, sym} ;
21
- use rustc_span:: { DUMMY_SP , Span } ;
22
22
23
23
use crate :: fluent_generated;
24
24
use crate :: session_diagnostics:: { self , IncorrectReprFormatGenericCause } ;
@@ -92,9 +92,7 @@ impl Stability {
92
92
#[ derive( HashStable_Generic ) ]
93
93
pub struct ConstStability {
94
94
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 ,
98
96
/// This is true iff the `const_stable_indirect` attribute is present.
99
97
pub const_stable_indirect : bool ,
100
98
/// whether the function has a `#[rustc_promotable]` attribute
@@ -272,22 +270,19 @@ pub fn find_stability(
272
270
273
271
/// Collects stability info from `rustc_const_stable`/`rustc_const_unstable`/`rustc_promotable`
274
272
/// 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`.
277
273
pub fn find_const_stability (
278
274
sess : & Session ,
279
275
attrs : & [ Attribute ] ,
280
276
item_sp : Span ,
281
- is_const_fn : bool ,
282
277
) -> Option < ( ConstStability , Span ) > {
283
278
let mut const_stab: Option < ( ConstStability , Span ) > = None ;
284
279
let mut promotable = false ;
285
- let mut const_stable_indirect = None ;
280
+ let mut const_stable_indirect = false ;
286
281
287
282
for attr in attrs {
288
283
match attr. name_or_empty ( ) {
289
284
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 ,
291
286
sym:: rustc_const_unstable => {
292
287
if const_stab. is_some ( ) {
293
288
sess. dcx ( )
@@ -299,7 +294,7 @@ pub fn find_const_stability(
299
294
const_stab = Some ( (
300
295
ConstStability {
301
296
level,
302
- feature : Some ( feature ) ,
297
+ feature,
303
298
const_stable_indirect : false ,
304
299
promotable : false ,
305
300
} ,
@@ -317,7 +312,7 @@ pub fn find_const_stability(
317
312
const_stab = Some ( (
318
313
ConstStability {
319
314
level,
320
- feature : Some ( feature ) ,
315
+ feature,
321
316
const_stable_indirect : false ,
322
317
promotable : false ,
323
318
} ,
@@ -340,7 +335,7 @@ pub fn find_const_stability(
340
335
}
341
336
}
342
337
}
343
- if const_stable_indirect. is_some ( ) {
338
+ if const_stable_indirect {
344
339
match & mut const_stab {
345
340
Some ( ( stab, _) ) => {
346
341
if stab. is_const_unstable ( ) {
@@ -351,36 +346,37 @@ pub fn find_const_stability(
351
346
} )
352
347
}
353
348
}
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
+ }
355
354
}
356
355
}
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
- }
380
356
381
357
const_stab
382
358
}
383
359
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
+
384
380
/// Collects stability info from `rustc_default_body_unstable` attributes in `attrs`.
385
381
/// Returns `None` if no stability attributes are found.
386
382
pub fn find_body_stability (
0 commit comments