pub fn simplify_type<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
                                     ty: Ty,
                                     can_simplify_params: bool)
                                     -> Option<SimplifiedType>
{
    match ty.sty {
        ty::Bool => Some(BoolSimplifiedType),
        ty::Char => Some(CharSimplifiedType),
        ty::Int(int_type) => Some(IntSimplifiedType(int_type)),
        ty::Uint(uint_type) => Some(UintSimplifiedType(uint_type)),
        ty::Float(float_type) => Some(FloatSimplifiedType(float_type)),
        ty::Adt(def, _) => Some(AdtSimplifiedType(def.did)),
        ty::Str => Some(StrSimplifiedType),
        ty::Array(..) | ty::Slice(_) => Some(ArraySimplifiedType),
        ty::RawPtr(_) => Some(PtrSimplifiedType),
        ty::Dynamic(ref trait_info, ..) => {
            trait_info.principal().map(|p| TraitSimplifiedType(p.def_id()))
        }
        ty::Ref(_, ty, _) => {
            // since we introduce auto-refs during method lookup, we
            // just treat &T and T as equivalent from the point of
            // view of possibly unifying
            simplify_type(tcx, ty, can_simplify_params)
        }
        ty::FnDef(def_id, _) |
        ty::Closure(def_id, _) => {
            Some(ClosureSimplifiedType(def_id))
        }
        ty::Generator(def_id, _, _) => {
            Some(GeneratorSimplifiedType(def_id))
        }
        ty::GeneratorWitness(ref tys) => {
            Some(GeneratorWitnessSimplifiedType(tys.skip_binder().len()))
        }
        ty::Never => Some(NeverSimplifiedType),
        ty::Tuple(ref tys) => {
            Some(TupleSimplifiedType(tys.len()))
        }
        ty::FnPtr(ref f) => {
            Some(FunctionSimplifiedType(f.skip_binder().inputs().len()))
        }
        ty::Projection(_) | ty::Param(_) => {
            if can_simplify_params {
                // In normalized types, projections don't unify with
                // anything. when lazy normalization happens, this
                // will change. It would still be nice to have a way
                // to deal with known-not-to-unify-with-anything
                // projections (e.g. the likes of <__S as Encoder>::Error).
                Some(ParameterSimplifiedType)
            } else {
                None
            }
        }
        ty::Opaque(def_id, _) => {
            Some(OpaqueSimplifiedType(def_id))
        }
        ty::Foreign(def_id) => {
            Some(ForeignSimplifiedType(def_id))
        }
        ty::Infer(_) | ty::Error => None,
    }
}
/// Tries to simplify a type by dropping type parameters, deref'ing away any reference types, etc.
/// The idea is to get something simple that we can use to quickly decide if two types could unify
/// during method lookup.
///
/// If `can_simplify_params` is false, then we will fail to simplify type parameters entirely. This
/// is useful when those type parameters would be instantiated with fresh type variables, since
/// then we can't say much about whether two types would unify. Put another way,
/// `can_simplify_params` should be true if type parameters appear free in `ty` and `false` if they
/// are to be considered bound.
Tries to simplify a type by dropping type parameters, deref'ing away any reference types, etc.
The idea is to get something simple that we can use to quickly decide if two types could unify
during method lookup.

If `can_simplify_params` is false, then we will fail to simplify type parameters entirely. This
is useful when those type parameters would be instantiated with fresh type variables, since
then we can't say much about whether two types would unify.
Tries to simplify a type by dropping type parameters deref ' ing away any reference types etc . The idea is to get something simple that we can use to quickly decide if two types could unify during method lookup . If ` can_simplify_params ` is false then we will fail to simplify type parameters entirely . This is useful when those type parameters would be instantiated with fresh type variables since then we can ' t say much about whether two types would unify .
pub fn simplify_type<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
                                     ty: Ty,
                                     can_simplify_params: bool)
                                     -> Option<SimplifiedType>
{
    match ty.sty {
        ty::Bool => Some(BoolSimplifiedType),
        ty::Char => Some(CharSimplifiedType),
        ty::Int(int_type) => Some(IntSimplifiedType(int_type)),
        ty::Uint(uint_type) => Some(UintSimplifiedType(uint_type)),
        ty::Float(float_type) => Some(FloatSimplifiedType(float_type)),
        ty::Adt(def, _) => Some(AdtSimplifiedType(def.did)),
        ty::Str => Some(StrSimplifiedType),
        ty::Array(..) | ty::Slice(_) => Some(ArraySimplifiedType),
        ty::RawPtr(_) => Some(PtrSimplifiedType),
        ty::Dynamic(ref trait_info, ..) => {
            trait_info.principal().map(|p| TraitSimplifiedType(p.def_id()))
        }
        ty::Ref(_, ty, _) => {
            // since we introduce auto-refs during method lookup, we
            // just treat &T and T as equivalent from the point of
            // view of possibly unifying
            simplify_type(tcx, ty, can_simplify_params)
        }
        ty::FnDef(def_id, _) |
        ty::Closure(def_id, _) => {
            Some(ClosureSimplifiedType(def_id))
        }
        ty::Generator(def_id, _, _) => {
            Some(GeneratorSimplifiedType(def_id))
        }
        ty::GeneratorWitness(ref tys) => {
            Some(GeneratorWitnessSimplifiedType(tys.skip_binder().len()))
        }
        ty::Never => Some(NeverSimplifiedType),
        ty::Tuple(ref tys) => {
            Some(TupleSimplifiedType(tys.len()))
        }
        ty::FnPtr(ref f) => {
            Some(FunctionSimplifiedType(f.skip_binder().inputs().len()))
        }
        ty::Projection(_) | ty::Param(_) => {
            if can_simplify_params {
                // In normalized types, projections don't unify with
                // anything. when lazy normalization happens, this
                // will change. It would still be nice to have a way
                // to deal with known-not-to-unify-with-anything
                // projections (e.g. the likes of <__S as Encoder>::Error).
                Some(ParameterSimplifiedType)
            } else {
                None
            }
        }
        ty::Opaque(def_id, _) => {
            Some(OpaqueSimplifiedType(def_id))
        }
        ty::Foreign(def_id) => {
            Some(ForeignSimplifiedType(def_id))
        }
        ty::Infer(_) | ty::Error => None,
    }
}
pub fn simplify_type < ' a , ' gcx , ' tcx > ( tcx : TyCtxt < ' a , ' gcx , ' tcx > , ty : Ty , can_simplify_params : bool ) -> Option < SimplifiedType > { match ty . sty { ty :: Bool => Some ( BoolSimplifiedType ) , ty :: Char => Some ( CharSimplifiedType ) , ty :: Int ( int_type ) => Some ( IntSimplifiedType ( int_type ) ) , ty :: Uint ( uint_type ) => Some ( UintSimplifiedType ( uint_type ) ) , ty :: Float ( float_type ) => Some ( FloatSimplifiedType ( float_type ) ) , ty :: Adt ( def , _ ) => Some ( AdtSimplifiedType ( def . did ) ) , ty :: Str => Some ( StrSimplifiedType ) , ty :: Array ( .. ) | ty :: Slice ( _ ) => Some ( ArraySimplifiedType ) , ty :: RawPtr ( _ ) => Some ( PtrSimplifiedType ) , ty :: Dynamic ( ref trait_info , .. ) => { trait_info . principal ( ) . map ( | p | TraitSimplifiedType ( p . def_id ( ) ) ) } ty :: Ref ( _ , ty , _ ) => { // since we introduce auto-refs during method lookup, we // just treat &T and T as equivalent from the point of // view of possibly unifying simplify_type ( tcx , ty , can_simplify_params ) } ty :: FnDef ( def_id , _ ) | ty :: Closure ( def_id , _ ) => { Some ( ClosureSimplifiedType ( def_id ) ) } ty :: Generator ( def_id , _ , _ ) => { Some ( GeneratorSimplifiedType ( def_id ) ) } ty :: GeneratorWitness ( ref tys ) => { Some ( GeneratorWitnessSimplifiedType ( tys . skip_binder ( ) . len ( ) ) ) } ty :: Never => Some ( NeverSimplifiedType ) , ty :: Tuple ( ref tys ) => { Some ( TupleSimplifiedType ( tys . len ( ) ) ) } ty :: FnPtr ( ref f ) => { Some ( FunctionSimplifiedType ( f . skip_binder ( ) . inputs ( ) . len ( ) ) ) } ty :: Projection ( _ ) | ty :: Param ( _ ) => { if can_simplify_params { // In normalized types, projections don't unify with // anything. when lazy normalization happens, this // will change. It would still be nice to have a way // to deal with known-not-to-unify-with-anything // projections (e.g. the likes of <__S as Encoder>::Error). Some ( ParameterSimplifiedType ) } else { None } } ty :: Opaque ( def_id , _ ) => { Some ( OpaqueSimplifiedType ( def_id ) ) } ty :: Foreign ( def_id ) => { Some ( ForeignSimplifiedType ( def_id ) ) } ty :: Infer ( _ ) | ty :: Error => None , } }
Tries to simplify a type by dropping type parameters, deref'ing away any reference types, etc.
Tries to simplify a type by dropping type parameters deref ' ing away any reference types etc .
tcx
TyCtxt<'a, 'gcx, 'tcx>
ty
Ty
can_simplify_params
bool
tcx
TyCtxt<'a, 'gcx, 'tcx>
ty
Ty
can_simplify_params
bool