@@ -41,67 +41,23 @@ enum AnnotationKind {
41
41
Container ,
42
42
}
43
43
44
- /// Whether to inherit deprecation flags for nested items. In most cases, we do want to inherit
45
- /// deprecation, because nested items rarely have individual deprecation attributes, and so
46
- /// should be treated as deprecated if their parent is. However, default generic parameters
47
- /// have separate deprecation attributes from their parents, so we do not wish to inherit
48
- /// deprecation in this case. For example, inheriting deprecation for `T` in `Foo<T>`
49
- /// would cause a duplicate warning arising from both `Foo` and `T` being deprecated.
50
- #[ derive( Clone ) ]
51
- enum InheritDeprecation {
52
- Yes ,
53
- No ,
54
- }
55
-
56
- impl InheritDeprecation {
57
- fn yes ( & self ) -> bool {
58
- matches ! ( self , InheritDeprecation :: Yes )
59
- }
60
- }
61
-
62
- /// Whether to inherit const stability flags for nested items. In most cases, we do not want to
63
- /// inherit const stability: just because an enclosing `fn` is const-stable does not mean
64
- /// all `extern` imports declared in it should be const-stable! However, trait methods
65
- /// inherit const stability attributes from their parent and do not have their own.
66
- enum InheritConstStability {
67
- Yes ,
68
- No ,
69
- }
70
-
71
- impl InheritConstStability {
72
- fn yes ( & self ) -> bool {
73
- matches ! ( self , InheritConstStability :: Yes )
74
- }
75
- }
76
-
77
- enum InheritStability {
78
- Yes ,
79
- No ,
80
- }
81
-
82
- impl InheritStability {
83
- fn yes ( & self ) -> bool {
84
- matches ! ( self , InheritStability :: Yes )
85
- }
86
- }
87
-
88
- fn inherit_deprecation ( def_kind : DefKind ) -> InheritDeprecation {
44
+ fn inherit_deprecation ( def_kind : DefKind ) -> bool {
89
45
match def_kind {
90
- DefKind :: LifetimeParam | DefKind :: TyParam | DefKind :: ConstParam => InheritDeprecation :: No ,
91
- _ => InheritDeprecation :: Yes ,
46
+ DefKind :: LifetimeParam | DefKind :: TyParam | DefKind :: ConstParam => false ,
47
+ _ => true ,
92
48
}
93
49
}
94
50
95
- fn inherit_const_stability ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> InheritConstStability {
51
+ fn inherit_const_stability ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> bool {
96
52
let def_kind = tcx. def_kind ( def_id) ;
97
53
match def_kind {
98
54
DefKind :: AssocFn | DefKind :: AssocTy | DefKind :: AssocConst => {
99
55
match tcx. def_kind ( tcx. local_parent ( def_id) ) {
100
- DefKind :: Impl { of_trait : true } => InheritConstStability :: Yes ,
101
- _ => InheritConstStability :: No ,
56
+ DefKind :: Impl { of_trait : true } => true ,
57
+ _ => false ,
102
58
}
103
59
}
104
- _ => InheritConstStability :: No ,
60
+ _ => false ,
105
61
}
106
62
}
107
63
@@ -145,7 +101,7 @@ fn lookup_deprecation_entry(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<Depre
145
101
) ;
146
102
147
103
let Some ( depr) = depr else {
148
- if inherit_deprecation ( tcx. def_kind ( def_id) ) . yes ( ) {
104
+ if inherit_deprecation ( tcx. def_kind ( def_id) ) {
149
105
let parent_id = tcx. opt_local_parent ( def_id) ?;
150
106
let parent_depr = tcx. lookup_deprecation_entry ( parent_id) ?;
151
107
return Some ( parent_depr) ;
@@ -158,10 +114,10 @@ fn lookup_deprecation_entry(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<Depre
158
114
Some ( DeprecationEntry :: local ( depr, def_id) )
159
115
}
160
116
161
- fn inherit_stability ( def_kind : DefKind ) -> InheritStability {
117
+ fn inherit_stability ( def_kind : DefKind ) -> bool {
162
118
match def_kind {
163
- DefKind :: Field | DefKind :: Variant | DefKind :: Ctor ( ..) => InheritStability :: Yes ,
164
- _ => InheritStability :: No ,
119
+ DefKind :: Field | DefKind :: Variant | DefKind :: Ctor ( ..) => true ,
120
+ _ => false ,
165
121
}
166
122
}
167
123
@@ -193,7 +149,7 @@ fn lookup_stability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<Stability> {
193
149
194
150
let Some ( parent) = tcx. opt_local_parent ( def_id) else { return Some ( FORCE_UNSTABLE ) } ;
195
151
196
- if inherit_deprecation ( tcx. def_kind ( def_id) ) . yes ( ) {
152
+ if inherit_deprecation ( tcx. def_kind ( def_id) ) {
197
153
let parent = tcx. lookup_stability ( parent) ?;
198
154
if parent. is_unstable ( ) {
199
155
return Some ( parent) ;
@@ -212,7 +168,7 @@ fn lookup_stability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<Stability> {
212
168
return Some ( stab) ;
213
169
}
214
170
215
- if inherit_deprecation ( tcx. def_kind ( def_id) ) . yes ( ) {
171
+ if inherit_deprecation ( tcx. def_kind ( def_id) ) {
216
172
let Some ( parent) = tcx. opt_local_parent ( def_id) else {
217
173
return tcx
218
174
. sess
@@ -222,7 +178,7 @@ fn lookup_stability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<Stability> {
222
178
. then_some ( FORCE_UNSTABLE ) ;
223
179
} ;
224
180
let parent = tcx. lookup_stability ( parent) ?;
225
- if parent. is_unstable ( ) || inherit_stability ( tcx. def_kind ( def_id) ) . yes ( ) {
181
+ if parent. is_unstable ( ) || inherit_stability ( tcx. def_kind ( def_id) ) {
226
182
return Some ( parent) ;
227
183
}
228
184
}
@@ -249,7 +205,7 @@ fn lookup_const_stability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ConstSt
249
205
if !tcx. features ( ) . staged_api ( ) {
250
206
// Propagate unstability. This can happen even for non-staged-api crates in case
251
207
// -Zforce-unstable-if-unmarked is set.
252
- if inherit_deprecation ( tcx. def_kind ( def_id) ) . yes ( ) {
208
+ if inherit_deprecation ( tcx. def_kind ( def_id) ) {
253
209
let parent = tcx. opt_local_parent ( def_id) ?;
254
210
let parent_stab = tcx. lookup_stability ( parent) ?;
255
211
if parent_stab. is_unstable ( )
@@ -301,7 +257,7 @@ fn lookup_const_stability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ConstSt
301
257
// immediate children.
302
258
// FIXME(const_trait_impl): how is this supposed to interact with `#[rustc_const_stable_indirect]`?
303
259
// Currently, once that is set, we do not inherit anything from the parent any more.
304
- if inherit_const_stability ( tcx, def_id) . yes ( ) {
260
+ if inherit_const_stability ( tcx, def_id) {
305
261
let parent = tcx. opt_local_parent ( def_id) ?;
306
262
let parent = tcx. lookup_const_stability ( parent) ?;
307
263
if parent. is_const_unstable ( ) {
0 commit comments