@@ -281,14 +281,21 @@ impl<'tcx> TyCtxt<'tcx> {
281281 /// If `id` is `Some(_)`, this function will also check if the item at `def_id` has been
282282 /// deprecated. If the item is indeed deprecated, we will emit a deprecation lint attached to
283283 /// `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 {
285291 // Deprecated attributes apply in-crate and cross-crate.
286292 if let Some ( id) = id {
287293 if let Some ( depr_entry) = self . lookup_deprecation_entry ( def_id) {
288294 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) ) ;
292299
293300 if !skip {
294301 let ( message, lint) =
@@ -386,9 +393,26 @@ impl<'tcx> TyCtxt<'tcx> {
386393 /// Additionally, this function will also check if the item is deprecated. If so, and `id` is
387394 /// not `None`, a deprecated lint attached to `id` will be emitted.
388395 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+ ) {
389413 let soft_handler =
390414 |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 ) {
392416 EvalResult :: Allow => { }
393417 EvalResult :: Deny { feature, reason, issue, is_soft } => {
394418 report_unstable ( self . sess , feature, reason, issue, is_soft, span, soft_handler)
0 commit comments