@@ -300,11 +300,24 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
300300 // const stability: inherit feature gate from regular stability.
301301 let mut const_stab = const_stab. map ( |( stab, _span) | stab) ;
302302
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+
303316 // 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 ( )
305319 // 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 ( ) )
308321 {
309322 const_stab = Some ( ConstStability {
310323 // We subject these implicitly-const functions to recursive const stability.
@@ -329,19 +342,6 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
329342 self . index . implications . insert ( implied_by, feature) ;
330343 }
331344
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-
345345 self . recurse_with_stability_attrs (
346346 depr. map ( |( d, _) | DeprecationEntry :: local ( d, def_id) ) ,
347347 stab,
@@ -418,6 +418,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
418418 kind = AnnotationKind :: DeprecationProhibited ;
419419 const_stab_inherit = InheritConstStability :: Yes ;
420420 }
421+ hir:: ItemKind :: Trait ( ..) => {
422+ const_stab_inherit = InheritConstStability :: Yes ;
423+ }
421424 hir:: ItemKind :: Struct ( ref sd, _) => {
422425 if let Some ( ctor_def_id) = sd. ctor_def_id ( ) {
423426 self . annotate (
0 commit comments