@@ -300,11 +300,27 @@ 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 ! (
313+ fn_sig. is_none_or( |s| !s. header. is_const( ) ) ,
314+ "should never have parent const stability for a const fn"
315+ ) ;
316+ self . index . const_stab_map . insert ( def_id, parent) ;
317+ }
318+
303319 // 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 ( ) &&
320+ if fn_sig. is_some_and ( |s| s. header . is_const ( ) )
321+ && const_stab. is_none ( )
305322 // We only ever inherit unstable features.
306- let Some ( inherit_regular_stab) =
307- final_stab. filter ( |s| s. is_unstable ( ) )
323+ && let Some ( inherit_regular_stab) = final_stab. filter ( |s| s. is_unstable ( ) )
308324 {
309325 const_stab = Some ( ConstStability {
310326 // We subject these implicitly-const functions to recursive const stability.
@@ -329,19 +345,6 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
329345 self . index . implications . insert ( implied_by, feature) ;
330346 }
331347
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-
345348 self . recurse_with_stability_attrs (
346349 depr. map ( |( d, _) | DeprecationEntry :: local ( d, def_id) ) ,
347350 stab,
@@ -418,6 +421,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
418421 kind = AnnotationKind :: DeprecationProhibited ;
419422 const_stab_inherit = InheritConstStability :: Yes ;
420423 }
424+ hir:: ItemKind :: Trait ( ..) => {
425+ const_stab_inherit = InheritConstStability :: Yes ;
426+ }
421427 hir:: ItemKind :: Struct ( ref sd, _) => {
422428 if let Some ( ctor_def_id) = sd. ctor_def_id ( ) {
423429 self . annotate (
0 commit comments