6
6
//! [`core::error`] module is marked as stable since 1.81.0, so we want to show
7
7
//! [`core::error::Error`] as stable since 1.81.0 as well.
8
8
9
- use rustc_attr:: { Stability , StabilityLevel } ;
9
+ use rustc_attr:: Stability ;
10
10
use rustc_hir:: def_id:: CRATE_DEF_ID ;
11
11
12
12
use crate :: clean:: { Crate , Item , ItemId } ;
@@ -32,27 +32,46 @@ struct StabilityPropagator<'a, 'tcx> {
32
32
33
33
impl < ' a , ' tcx > DocFolder for StabilityPropagator < ' a , ' tcx > {
34
34
fn fold_item ( & mut self , mut item : Item ) -> Option < Item > {
35
+ use rustc_attr:: StabilityLevel :: * ;
36
+
35
37
let parent_stability = self . parent_stability . clone ( ) ;
36
38
37
39
let stability = match item. item_id {
38
40
ItemId :: DefId ( def_id) => {
39
41
let own_stability = self . cx . tcx . lookup_stability ( def_id) ;
40
42
41
- // If any of the item's parents was stabilized later or is still unstable,
42
- // then use the parent's stability instead.
43
- if let Some ( ref own_stab) = own_stability
44
- && let StabilityLevel :: Stable {
45
- since : own_since,
46
- allowed_through_unstable_modules : false ,
47
- ..
48
- } = own_stab. level
43
+ if let Some ( own_stab) = own_stability
49
44
&& let Some ( ref parent_stab) = parent_stability
50
- && ( parent_stab. is_unstable ( )
51
- || parent_stab
52
- . stable_since ( )
53
- . is_some_and ( |parent_since| parent_since > own_since) )
54
45
{
55
- parent_stability. clone ( )
46
+ match own_stab. level {
47
+ // If any of the item's parents was stabilized later or is still unstable,
48
+ // then use the parent's stability instead.
49
+ Stable {
50
+ since : own_since,
51
+ allowed_through_unstable_modules : false ,
52
+ ..
53
+ } if parent_stab. is_unstable ( )
54
+ || parent_stab
55
+ . stable_since ( )
56
+ . is_some_and ( |parent_since| parent_since > own_since) =>
57
+ {
58
+ parent_stability. clone ( )
59
+ }
60
+ // If any of an unstable item's parents depend on other unstable features,
61
+ // then use those as well.
62
+ Unstable { unstables : ref own_gates, is_soft }
63
+ if let Unstable { unstables : parent_gates, .. } =
64
+ & parent_stab. level =>
65
+ {
66
+ let missing_unstables = parent_gates
67
+ . iter ( )
68
+ . filter ( |p| !own_gates. iter ( ) . any ( |u| u. feature == p. feature ) ) ;
69
+ let unstables =
70
+ own_gates. iter ( ) . chain ( missing_unstables) . cloned ( ) . collect ( ) ;
71
+ Some ( Stability { level : Unstable { unstables, is_soft } } )
72
+ }
73
+ _ => own_stability. cloned ( ) ,
74
+ }
56
75
} else {
57
76
own_stability. cloned ( )
58
77
}
0 commit comments