@@ -89,13 +89,40 @@ impl InheritStability {
89
89
}
90
90
}
91
91
92
+ fn inherit_deprecation ( def_kind : DefKind ) -> InheritDeprecation {
93
+ match def_kind {
94
+ DefKind :: LifetimeParam | DefKind :: TyParam | DefKind :: ConstParam => InheritDeprecation :: No ,
95
+ _ => InheritDeprecation :: Yes ,
96
+ }
97
+ }
98
+
99
+ fn lookup_deprecation_entry ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> Option < DeprecationEntry > {
100
+ let attrs = tcx. hir_attrs ( tcx. local_def_id_to_hir_id ( def_id) ) ;
101
+ let depr = attrs:: find_attr!( attrs,
102
+ AttributeKind :: Deprecation { deprecation, span: _ } => * deprecation
103
+ ) ;
104
+
105
+ let Some ( depr) = depr else {
106
+ if inherit_deprecation ( tcx. def_kind ( def_id) ) . yes ( ) {
107
+ let parent_id = tcx. opt_local_parent ( def_id) ?;
108
+ let parent_depr = tcx. lookup_deprecation_entry ( parent_id) ?;
109
+ info ! ( "tagging child {:?} as deprecated from parent" , def_id) ;
110
+ return Some ( parent_depr) ;
111
+ }
112
+
113
+ return None ;
114
+ } ;
115
+
116
+ // `Deprecation` is just two pointers, no need to intern it
117
+ Some ( DeprecationEntry :: local ( depr, def_id) )
118
+ }
119
+
92
120
/// A private tree-walker for producing an `Index`.
93
121
struct Annotator < ' a , ' tcx > {
94
122
tcx : TyCtxt < ' tcx > ,
95
123
index : & ' a mut Index ,
96
124
parent_stab : Option < Stability > ,
97
125
parent_const_stab : Option < ConstStability > ,
98
- parent_depr : Option < DeprecationEntry > ,
99
126
in_trait_impl : bool ,
100
127
}
101
128
@@ -119,24 +146,9 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
119
146
let attrs = self . tcx . hir_attrs ( self . tcx . local_def_id_to_hir_id ( def_id) ) ;
120
147
debug ! ( "annotate(id = {:?}, attrs = {:?})" , def_id, attrs) ;
121
148
122
- let depr = attrs :: find_attr! ( attrs , AttributeKind :: Deprecation { deprecation , span } => ( * deprecation , * span ) ) ;
149
+ let depr = self . tcx . lookup_deprecation_entry ( def_id ) ;
123
150
let const_stability_indirect = find_attr ! ( attrs, AttributeKind :: ConstStabilityIndirect ) ;
124
151
125
- let mut is_deprecated = false ;
126
- if let Some ( ( depr, _) ) = & depr {
127
- is_deprecated = true ;
128
-
129
- // `Deprecation` is just two pointers, no need to intern it
130
- let depr_entry = DeprecationEntry :: local ( * depr, def_id) ;
131
- self . index . depr_map . insert ( def_id, depr_entry) ;
132
- } else if let Some ( parent_depr) = self . parent_depr {
133
- if inherit_deprecation. yes ( ) {
134
- is_deprecated = true ;
135
- info ! ( "tagging child {:?} as deprecated from parent" , def_id) ;
136
- self . index . depr_map . insert ( def_id, parent_depr) ;
137
- }
138
- }
139
-
140
152
if !self . tcx . features ( ) . staged_api ( ) {
141
153
// Propagate unstability. This can happen even for non-staged-api crates in case
142
154
// -Zforce-unstable-if-unmarked is set.
@@ -152,12 +164,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
152
164
}
153
165
}
154
166
155
- self . recurse_with_stability_attrs (
156
- depr. map ( |( d, _) | DeprecationEntry :: local ( d, def_id) ) ,
157
- None ,
158
- None ,
159
- visit_children,
160
- ) ;
167
+ self . recurse_with_stability_attrs ( None , None , visit_children) ;
161
168
return ;
162
169
}
163
170
@@ -166,11 +173,14 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
166
173
let body_stab =
167
174
attrs:: find_attr!( attrs, AttributeKind :: BodyStability { stability, .. } => * stability) ;
168
175
169
- if let Some ( ( depr, span ) ) = & depr
170
- && depr. is_since_rustc_version ( )
176
+ if let Some ( depr) = & depr
177
+ && depr. attr . is_since_rustc_version ( )
171
178
&& stab. is_none ( )
179
+ && let Some ( depr_span) = attrs:: find_attr!( attrs,
180
+ AttributeKind :: Deprecation { span, .. } => * span
181
+ )
172
182
{
173
- self . tcx . dcx ( ) . emit_err ( errors:: DeprecatedAttribute { span : * span } ) ;
183
+ self . tcx . dcx ( ) . emit_err ( errors:: DeprecatedAttribute { span : depr_span } ) ;
174
184
}
175
185
176
186
if let Some ( body_stab) = body_stab {
@@ -183,7 +193,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
183
193
let stab = stab. map ( |( stab, span) | {
184
194
// Error if prohibited, or can't inherit anything from a container.
185
195
if kind == AnnotationKind :: Prohibited
186
- || ( kind == AnnotationKind :: Container && stab. level . is_stable ( ) && is_deprecated )
196
+ || ( kind == AnnotationKind :: Container && stab. level . is_stable ( ) && depr . is_some ( ) )
187
197
{
188
198
self . tcx . dcx ( ) . emit_err ( errors:: UselessStability { span, item_sp } ) ;
189
199
}
@@ -195,7 +205,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
195
205
if let (
196
206
& Some ( DeprecatedSince :: RustcVersion ( dep_since) ) ,
197
207
& attrs:: StabilityLevel :: Stable { since : stab_since, .. } ,
198
- ) = ( & depr. as_ref ( ) . map ( |( d , _ ) | d. since ) , & stab. level )
208
+ ) = ( & depr. as_ref ( ) . map ( |d | d. attr . since ) , & stab. level )
199
209
{
200
210
match stab_since {
201
211
StableSince :: Current => {
@@ -343,7 +353,6 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
343
353
}
344
354
345
355
self . recurse_with_stability_attrs (
346
- depr. map ( |( d, _) | DeprecationEntry :: local ( d, def_id) ) ,
347
356
stab,
348
357
inherit_const_stability. yes ( ) . then_some ( const_stab) . flatten ( ) ,
349
358
visit_children,
@@ -352,19 +361,14 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
352
361
353
362
fn recurse_with_stability_attrs (
354
363
& mut self ,
355
- depr : Option < DeprecationEntry > ,
356
364
stab : Option < Stability > ,
357
365
const_stab : Option < ConstStability > ,
358
366
f : impl FnOnce ( & mut Self ) ,
359
367
) {
360
368
// These will be `Some` if this item changes the corresponding stability attribute.
361
- let mut replaced_parent_depr = None ;
362
369
let mut replaced_parent_stab = None ;
363
370
let mut replaced_parent_const_stab = None ;
364
371
365
- if let Some ( depr) = depr {
366
- replaced_parent_depr = Some ( replace ( & mut self . parent_depr , Some ( depr) ) ) ;
367
- }
368
372
if let Some ( stab) = stab {
369
373
replaced_parent_stab = Some ( replace ( & mut self . parent_stab , Some ( stab) ) ) ;
370
374
}
@@ -375,9 +379,6 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
375
379
376
380
f ( self ) ;
377
381
378
- if let Some ( orig_parent_depr) = replaced_parent_depr {
379
- self . parent_depr = orig_parent_depr;
380
- }
381
382
if let Some ( orig_parent_stab) = replaced_parent_stab {
382
383
self . parent_stab = orig_parent_stab;
383
384
}
@@ -679,7 +680,6 @@ fn stability_index(tcx: TyCtxt<'_>, (): ()) -> Index {
679
680
stab_map : Default :: default ( ) ,
680
681
const_stab_map : Default :: default ( ) ,
681
682
default_body_stab_map : Default :: default ( ) ,
682
- depr_map : Default :: default ( ) ,
683
683
implications : Default :: default ( ) ,
684
684
} ;
685
685
@@ -689,7 +689,6 @@ fn stability_index(tcx: TyCtxt<'_>, (): ()) -> Index {
689
689
index : & mut index,
690
690
parent_stab : None ,
691
691
parent_const_stab : None ,
692
- parent_depr : None ,
693
692
in_trait_impl : false ,
694
693
} ;
695
694
@@ -741,7 +740,7 @@ pub(crate) fn provide(providers: &mut Providers) {
741
740
lookup_stability : |tcx, id| tcx. stability ( ) . local_stability ( id) ,
742
741
lookup_const_stability : |tcx, id| tcx. stability ( ) . local_const_stability ( id) ,
743
742
lookup_default_body_stability : |tcx, id| tcx. stability ( ) . local_default_body_stability ( id) ,
744
- lookup_deprecation_entry : |tcx , id| tcx . stability ( ) . local_deprecation_entry ( id ) ,
743
+ lookup_deprecation_entry,
745
744
..* providers
746
745
} ;
747
746
}
0 commit comments