crate fn eval_nullary_intrinsic<'tcx>(
    tcx: TyCtxt<'tcx>,
    param_env: ty::ParamEnv<'tcx>,
    def_id: DefId,
    substs: SubstsRef<'tcx>,
) -> InterpResult<'tcx, ConstValue<'tcx>> {
    let tp_ty = substs.type_at(0);
    let name = tcx.item_name(def_id);
    Ok(match name {
        sym::type_name => {
            ensure_monomorphic_enough(tcx, tp_ty)?;
            let alloc = type_name::alloc_type_name(tcx, tp_ty);
            ConstValue::Slice { data: alloc, start: 0, end: alloc.len() }
        }
        sym::needs_drop => {
            ensure_monomorphic_enough(tcx, tp_ty)?;
            ConstValue::from_bool(tp_ty.needs_drop(tcx, param_env))
        }
        sym::min_align_of | sym::pref_align_of => {
            // Correctly handles non-monomorphic calls, so there is no need for ensure_monomorphic_enough.
            let layout = tcx.layout_of(param_env.and(tp_ty)).map_err(|e| err_inval!(Layout(e)))?;
            let n = match name {
                sym::pref_align_of => layout.align.pref.bytes(),
                sym::min_align_of => layout.align.abi.bytes(),
                _ => bug!(),
            };
            ConstValue::from_machine_usize(n, &tcx)
        }
        sym::type_id => {
            ensure_monomorphic_enough(tcx, tp_ty)?;
            ConstValue::from_u64(tcx.type_id_hash(tp_ty))
        }
        sym::variant_count => match tp_ty.kind() {
            // Correctly handles non-monomorphic calls, so there is no need for ensure_monomorphic_enough.
            ty::Adt(ref adt, _) => ConstValue::from_machine_usize(adt.variants.len() as u64, &tcx),
            ty::Projection(_)
            | ty::Opaque(_, _)
            | ty::Param(_)
            | ty::Bound(_, _)
            | ty::Placeholder(_)
            | ty::Infer(_) => throw_inval!(TooGeneric),
            ty::Bool
            | ty::Char
            | ty::Int(_)
            | ty::Uint(_)
            | ty::Float(_)
            | ty::Foreign(_)
            | ty::Str
            | ty::Array(_, _)
            | ty::Slice(_)
            | ty::RawPtr(_)
            | ty::Ref(_, _, _)
            | ty::FnDef(_, _)
            | ty::FnPtr(_)
            | ty::Dynamic(_, _)
            | ty::Closure(_, _)
            | ty::Generator(_, _, _)
            | ty::GeneratorWitness(_)
            | ty::Never
            | ty::Tuple(_)
            | ty::Error(_) => ConstValue::from_machine_usize(0u64, &tcx),
        },
        other => bug!("`{}` is not a zero arg intrinsic", other),
    })
}
/// The logic for all nullary intrinsics is implemented here. These intrinsics don't get evaluated
/// inside an `InterpCx` and instead have their value computed directly from rustc internal info.
The logic for all nullary intrinsics is implemented here. These intrinsics don't get evaluated
inside an `InterpCx` and instead have their value computed directly from rustc internal info.
The logic for all nullary intrinsics is implemented here . These intrinsics don ' t get evaluated inside an ` InterpCx ` and instead have their value computed directly from rustc internal info .
crate fn eval_nullary_intrinsic<'tcx>(
    tcx: TyCtxt<'tcx>,
    param_env: ty::ParamEnv<'tcx>,
    def_id: DefId,
    substs: SubstsRef<'tcx>,
) -> InterpResult<'tcx, ConstValue<'tcx>> {
    let tp_ty = substs.type_at(0);
    let name = tcx.item_name(def_id);
    Ok(match name {
        sym::type_name => {
            ensure_monomorphic_enough(tcx, tp_ty)?;
            let alloc = type_name::alloc_type_name(tcx, tp_ty);
            ConstValue::Slice { data: alloc, start: 0, end: alloc.len() }
        }
        sym::needs_drop => {
            ensure_monomorphic_enough(tcx, tp_ty)?;
            ConstValue::from_bool(tp_ty.needs_drop(tcx, param_env))
        }
        sym::min_align_of | sym::pref_align_of => {
            // Correctly handles non-monomorphic calls, so there is no need for ensure_monomorphic_enough.
            let layout = tcx.layout_of(param_env.and(tp_ty)).map_err(|e| err_inval!(Layout(e)))?;
            let n = match name {
                sym::pref_align_of => layout.align.pref.bytes(),
                sym::min_align_of => layout.align.abi.bytes(),
                _ => bug!(),
            };
            ConstValue::from_machine_usize(n, &tcx)
        }
        sym::type_id => {
            ensure_monomorphic_enough(tcx, tp_ty)?;
            ConstValue::from_u64(tcx.type_id_hash(tp_ty))
        }
        sym::variant_count => match tp_ty.kind() {
            // Correctly handles non-monomorphic calls, so there is no need for ensure_monomorphic_enough.
            ty::Adt(ref adt, _) => ConstValue::from_machine_usize(adt.variants.len() as u64, &tcx),
            ty::Projection(_)
            | ty::Opaque(_, _)
            | ty::Param(_)
            | ty::Bound(_, _)
            | ty::Placeholder(_)
            | ty::Infer(_) => throw_inval!(TooGeneric),
            ty::Bool
            | ty::Char
            | ty::Int(_)
            | ty::Uint(_)
            | ty::Float(_)
            | ty::Foreign(_)
            | ty::Str
            | ty::Array(_, _)
            | ty::Slice(_)
            | ty::RawPtr(_)
            | ty::Ref(_, _, _)
            | ty::FnDef(_, _)
            | ty::FnPtr(_)
            | ty::Dynamic(_, _)
            | ty::Closure(_, _)
            | ty::Generator(_, _, _)
            | ty::GeneratorWitness(_)
            | ty::Never
            | ty::Tuple(_)
            | ty::Error(_) => ConstValue::from_machine_usize(0u64, &tcx),
        },
        other => bug!("`{}` is not a zero arg intrinsic", other),
    })
}
crate fn eval_nullary_intrinsic < ' tcx > ( tcx : TyCtxt < ' tcx > , param_env : ty :: ParamEnv < ' tcx > , def_id : DefId , substs : SubstsRef < ' tcx > , ) -> InterpResult < ' tcx , ConstValue < ' tcx > > { let tp_ty = substs . type_at ( 0 ) ; let name = tcx . item_name ( def_id ) ; Ok ( match name { sym :: type_name => { ensure_monomorphic_enough ( tcx , tp_ty ) ? ; let alloc = type_name :: alloc_type_name ( tcx , tp_ty ) ; ConstValue :: Slice { data : alloc , start : 0 , end : alloc . len ( ) } } sym :: needs_drop => { ensure_monomorphic_enough ( tcx , tp_ty ) ? ; ConstValue :: from_bool ( tp_ty . needs_drop ( tcx , param_env ) ) } sym :: min_align_of | sym :: pref_align_of => { // Correctly handles non-monomorphic calls, so there is no need for ensure_monomorphic_enough. let layout = tcx . layout_of ( param_env . and ( tp_ty ) ) . map_err ( | e | err_inval ! ( Layout ( e ) ) ) ? ; let n = match name { sym :: pref_align_of => layout . align . pref . bytes ( ) , sym :: min_align_of => layout . align . abi . bytes ( ) , _ => bug ! ( ) , } ; ConstValue :: from_machine_usize ( n , & tcx ) } sym :: type_id => { ensure_monomorphic_enough ( tcx , tp_ty ) ? ; ConstValue :: from_u64 ( tcx . type_id_hash ( tp_ty ) ) } sym :: variant_count => match tp_ty . kind ( ) { // Correctly handles non-monomorphic calls, so there is no need for ensure_monomorphic_enough. ty :: Adt ( ref adt , _ ) => ConstValue :: from_machine_usize ( adt . variants . len ( ) as u64 , & tcx ) , ty :: Projection ( _ ) | ty :: Opaque ( _ , _ ) | ty :: Param ( _ ) | ty :: Bound ( _ , _ ) | ty :: Placeholder ( _ ) | ty :: Infer ( _ ) => throw_inval ! ( TooGeneric ) , ty :: Bool | ty :: Char | ty :: Int ( _ ) | ty :: Uint ( _ ) | ty :: Float ( _ ) | ty :: Foreign ( _ ) | ty :: Str | ty :: Array ( _ , _ ) | ty :: Slice ( _ ) | ty :: RawPtr ( _ ) | ty :: Ref ( _ , _ , _ ) | ty :: FnDef ( _ , _ ) | ty :: FnPtr ( _ ) | ty :: Dynamic ( _ , _ ) | ty :: Closure ( _ , _ ) | ty :: Generator ( _ , _ , _ ) | ty :: GeneratorWitness ( _ ) | ty :: Never | ty :: Tuple ( _ ) | ty :: Error ( _ ) => ConstValue :: from_machine_usize ( 0u64 , & tcx ) , } , other => bug ! ( " " other ) , } ) }
The logic for all nullary intrinsics is implemented here.
The logic for all nullary intrinsics is implemented here .
tcx
TyCtxt<'tcx>
param_env
ty::ParamEnv<'tcx>
def_id
DefId
substs
SubstsRef<'tcx>
tcx
TyCtxt<'tcx>
param_env
ty::ParamEnv<'tcx>
def_id
DefId
substs
SubstsRef<'tcx>