@@ -281,14 +281,21 @@ impl<'tcx> TyCtxt<'tcx> {
281
281
/// If `id` is `Some(_)`, this function will also check if the item at `def_id` has been
282
282
/// deprecated. If the item is indeed deprecated, we will emit a deprecation lint attached to
283
283
/// `id`.
284
- pub fn eval_stability ( self , def_id : DefId , id : Option < HirId > , span : Span ) -> EvalResult {
284
+ pub fn eval_stability (
285
+ self ,
286
+ def_id : DefId ,
287
+ id : Option < HirId > ,
288
+ span : Span ,
289
+ inherit_dep : bool ,
290
+ ) -> EvalResult {
285
291
// Deprecated attributes apply in-crate and cross-crate.
286
292
if let Some ( id) = id {
287
293
if let Some ( depr_entry) = self . lookup_deprecation_entry ( def_id) {
288
294
let parent_def_id = self . hir ( ) . local_def_id ( self . hir ( ) . get_parent_item ( id) ) ;
289
- let skip = self
290
- . lookup_deprecation_entry ( parent_def_id)
291
- . map_or ( false , |parent_depr| parent_depr. same_origin ( & depr_entry) ) ;
295
+ let skip = !inherit_dep
296
+ || self
297
+ . lookup_deprecation_entry ( parent_def_id)
298
+ . map_or ( false , |parent_depr| parent_depr. same_origin ( & depr_entry) ) ;
292
299
293
300
if !skip {
294
301
let ( message, lint) =
@@ -386,9 +393,26 @@ impl<'tcx> TyCtxt<'tcx> {
386
393
/// Additionally, this function will also check if the item is deprecated. If so, and `id` is
387
394
/// not `None`, a deprecated lint attached to `id` will be emitted.
388
395
pub fn check_stability ( self , def_id : DefId , id : Option < HirId > , span : Span ) {
396
+ self . check_stability_internal ( def_id, id, span, true )
397
+ }
398
+
399
+ /// Checks if an item is stable or error out.
400
+ ///
401
+ /// If the item defined by `def_id` is unstable and the corresponding `#![feature]` does not
402
+ /// exist, emits an error.
403
+ ///
404
+ /// Additionally when `inherit_dep` is `true`, this function will also check if the item is deprecated. If so, and `id` is
405
+ /// not `None`, a deprecated lint attached to `id` will be emitted.
406
+ pub fn check_stability_internal (
407
+ self ,
408
+ def_id : DefId ,
409
+ id : Option < HirId > ,
410
+ span : Span ,
411
+ inherit_dep : bool ,
412
+ ) {
389
413
let soft_handler =
390
414
|lint, span, msg : & _ | self . lint_hir ( lint, id. unwrap_or ( hir:: CRATE_HIR_ID ) , span, msg) ;
391
- match self . eval_stability ( def_id, id, span) {
415
+ match self . eval_stability ( def_id, id, span, inherit_dep ) {
392
416
EvalResult :: Allow => { }
393
417
EvalResult :: Deny { feature, reason, issue, is_soft } => {
394
418
report_unstable ( self . sess , feature, reason, issue, is_soft, span, soft_handler)
0 commit comments