@@ -300,11 +300,24 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
300
300
// const stability: inherit feature gate from regular stability.
301
301
let mut const_stab = const_stab. map ( |( stab, _span) | stab) ;
302
302
303
+ // `impl const Trait for Type` items forward their const stability to their
304
+ // immediate children.
305
+ // FIXME(const_trait_impl): how is this supposed to interact with `#[rustc_const_stable_indirect]`?
306
+ // Currently, once that is set, we do not inherit anything from the parent any more.
307
+ if const_stab. is_none ( )
308
+ && let Some ( parent) = self . parent_const_stab
309
+ && parent. is_const_unstable ( )
310
+ {
311
+ // For now, `const fn` in const traits/trait impls does not exist.
312
+ assert ! ( fn_sig. is_none_or( |s| !s. header. is_const( ) ) , "should never have parent const stability for a const fn" ) ;
313
+ self . index . const_stab_map . insert ( def_id, parent) ;
314
+ }
315
+
303
316
// If this is a const fn but not annotated with stability markers, see if we can inherit regular stability.
304
- if fn_sig. is_some_and ( |s| s. header . is_const ( ) ) && const_stab. is_none ( ) &&
317
+ if fn_sig. is_some_and ( |s| s. header . is_const ( ) )
318
+ && const_stab. is_none ( )
305
319
// We only ever inherit unstable features.
306
- let Some ( inherit_regular_stab) =
307
- final_stab. filter ( |s| s. is_unstable ( ) )
320
+ && let Some ( inherit_regular_stab) = final_stab. filter ( |s| s. is_unstable ( ) )
308
321
{
309
322
const_stab = Some ( ConstStability {
310
323
// We subject these implicitly-const functions to recursive const stability.
@@ -329,19 +342,6 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
329
342
self . index . implications . insert ( implied_by, feature) ;
330
343
}
331
344
332
- // `impl const Trait for Type` items forward their const stability to their
333
- // immediate children.
334
- // FIXME(const_trait_impl): how is this supposed to interact with `#[rustc_const_stable_indirect]`?
335
- // Currently, once that is set, we do not inherit anything from the parent any more.
336
- if const_stab. is_none ( ) {
337
- debug ! ( "annotate: const_stab not found, parent = {:?}" , self . parent_const_stab) ;
338
- if let Some ( parent) = self . parent_const_stab {
339
- if parent. is_const_unstable ( ) {
340
- self . index . const_stab_map . insert ( def_id, parent) ;
341
- }
342
- }
343
- }
344
-
345
345
self . recurse_with_stability_attrs (
346
346
depr. map ( |( d, _) | DeprecationEntry :: local ( d, def_id) ) ,
347
347
stab,
@@ -418,6 +418,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
418
418
kind = AnnotationKind :: DeprecationProhibited ;
419
419
const_stab_inherit = InheritConstStability :: Yes ;
420
420
}
421
+ hir:: ItemKind :: Trait ( ..) => {
422
+ const_stab_inherit = InheritConstStability :: Yes ;
423
+ }
421
424
hir:: ItemKind :: Struct ( ref sd, _) => {
422
425
if let Some ( ctor_def_id) = sd. ctor_def_id ( ) {
423
426
self . annotate (
0 commit comments