pub fn for_item(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<Self> {
        use hir::BodyOwnerKind as HirKind;

        let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();

        let mode = match tcx.hir().body_owner_kind(hir_id) {
            HirKind::Closure => return None,

            // Note: this is deliberately checking for `is_const_fn_raw`, as the `is_const_fn`
            // checks take into account the `rustc_const_unstable` attribute combined with enabled
            // feature gates. Otherwise, const qualification would _not check_ whether this
            // function body follows the `const fn` rules, as an unstable `const fn` would
            // be considered "not const". More details are available in issue #67053.
            HirKind::Fn if tcx.is_const_fn_raw(def_id) => ConstKind::ConstFn,
            HirKind::Fn => return None,

            HirKind::Const => ConstKind::Const,

            HirKind::Static(hir::Mutability::Not) => ConstKind::Static,
            HirKind::Static(hir::Mutability::Mut) => ConstKind::StaticMut,
        };

        Some(mode)
    }
/// Returns the validation mode for the item with the given `DefId`, or `None` if this item
/// does not require validation (e.g. a non-const `fn`).
Returns the validation mode for the item with the given `DefId`, or `None` if this item
does not require validation .
Returns the validation mode for the item with the given ` DefId ` or ` None ` if this item does not require validation .
pub fn for_item(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<Self> {
        use hir::BodyOwnerKind as HirKind;
        let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
        let mode = match tcx.hir().body_owner_kind(hir_id) {
            HirKind::Closure => return None,
            // Note: this is deliberately checking for `is_const_fn_raw`, as the `is_const_fn`
            // checks take into account the `rustc_const_unstable` attribute combined with enabled
            // feature gates. Otherwise, const qualification would _not check_ whether this
            // function body follows the `const fn` rules, as an unstable `const fn` would
            // be considered "not const". More details are available in issue #67053.
            HirKind::Fn if tcx.is_const_fn_raw(def_id) => ConstKind::ConstFn,
            HirKind::Fn => return None,
            HirKind::Const => ConstKind::Const,
            HirKind::Static(hir::Mutability::Not) => ConstKind::Static,
            HirKind::Static(hir::Mutability::Mut) => ConstKind::StaticMut,
        };
        Some(mode)
    }
pub fn for_item ( tcx : TyCtxt < ' tcx > , def_id : DefId ) -> Option < Self > { use hir :: BodyOwnerKind as HirKind ; let hir_id = tcx . hir ( ) . as_local_hir_id ( def_id ) . unwrap ( ) ; let mode = match tcx . hir ( ) . body_owner_kind ( hir_id ) { HirKind :: Closure => return None , // Note: this is deliberately checking for `is_const_fn_raw`, as the `is_const_fn` // checks take into account the `rustc_const_unstable` attribute combined with enabled // feature gates. Otherwise, const qualification would _not check_ whether this // function body follows the `const fn` rules, as an unstable `const fn` would // be considered "not const". More details are available in issue #67053. HirKind :: Fn if tcx . is_const_fn_raw ( def_id ) => ConstKind :: ConstFn , HirKind :: Fn => return None , HirKind :: Const => ConstKind :: Const , HirKind :: Static ( hir :: Mutability :: Not ) => ConstKind :: Static , HirKind :: Static ( hir :: Mutability :: Mut ) => ConstKind :: StaticMut , } ; Some ( mode ) }
Returns the validation mode for the item with the given `DefId`, or `None` if this item
does not require validation (e.g.
Returns the validation mode for the item with the given ` DefId ` or ` None ` if this item does not require validation ( e . g .
tcx
TyCtxt<'tcx>
def_id
DefId