pub fn characteristic_def_id_of_type(ty: Ty) -> Option<DefId> {
    match ty.sty {
        ty::Adt(adt_def, _) => Some(adt_def.did),

        ty::Dynamic(data, ..) => data.principal().map(|p| p.def_id()),

        ty::Array(subty, _) |
        ty::Slice(subty) => characteristic_def_id_of_type(subty),

        ty::RawPtr(mt) => characteristic_def_id_of_type(mt.ty),

        ty::Ref(_, ty, _) => characteristic_def_id_of_type(ty),

        ty::Tuple(ref tys) => tys.iter()
                                   .filter_map(|ty| characteristic_def_id_of_type(ty))
                                   .next(),

        ty::FnDef(def_id, _) |
        ty::Closure(def_id, _) |
        ty::Generator(def_id, _, _) |
        ty::Foreign(def_id) => Some(def_id),

        ty::Bool |
        ty::Char |
        ty::Int(_) |
        ty::Uint(_) |
        ty::Str |
        ty::FnPtr(_) |
        ty::Projection(_) |
        ty::Param(_) |
        ty::Opaque(..) |
        ty::Infer(_) |
        ty::Error |
        ty::GeneratorWitness(..) |
        ty::Never |
        ty::Float(_) => None,
    }
}
/// As a heuristic, when we see an impl, if we see that the
/// 'self-type' is a type defined in the same module as the impl,
/// we can omit including the path to the impl itself. This
/// function tries to find a "characteristic def-id" for a
/// type. It's just a heuristic so it makes some questionable
/// decisions and we may want to adjust it later.
As a heuristic, when we see an impl, if we see that the
'self-type' is a type defined in the same module as the impl,
we can omit including the path to the impl itself. This
function tries to find a "characteristic def-id" for a
type. It's just a heuristic so it makes some questionable
decisions and we may want to adjust it later.
As a heuristic when we see an impl if we see that the ' self - type ' is a type defined in the same module as the impl we can omit including the path to the impl itself . This function tries to find a " characteristic def - id " for a type . It ' s just a heuristic so it makes some questionable decisions and we may want to adjust it later .
pub fn characteristic_def_id_of_type(ty: Ty) -> Option<DefId> {
    match ty.sty {
        ty::Adt(adt_def, _) => Some(adt_def.did),
        ty::Dynamic(data, ..) => data.principal().map(|p| p.def_id()),
        ty::Array(subty, _) |
        ty::Slice(subty) => characteristic_def_id_of_type(subty),
        ty::RawPtr(mt) => characteristic_def_id_of_type(mt.ty),
        ty::Ref(_, ty, _) => characteristic_def_id_of_type(ty),
        ty::Tuple(ref tys) => tys.iter()
                                   .filter_map(|ty| characteristic_def_id_of_type(ty))
                                   .next(),
        ty::FnDef(def_id, _) |
        ty::Closure(def_id, _) |
        ty::Generator(def_id, _, _) |
        ty::Foreign(def_id) => Some(def_id),
        ty::Bool |
        ty::Char |
        ty::Int(_) |
        ty::Uint(_) |
        ty::Str |
        ty::FnPtr(_) |
        ty::Projection(_) |
        ty::Param(_) |
        ty::Opaque(..) |
        ty::Infer(_) |
        ty::Error |
        ty::GeneratorWitness(..) |
        ty::Never |
        ty::Float(_) => None,
    }
}
pub fn characteristic_def_id_of_type ( ty : Ty ) -> Option < DefId > { match ty . sty { ty :: Adt ( adt_def , _ ) => Some ( adt_def . did ) , ty :: Dynamic ( data , .. ) => data . principal ( ) . map ( | p | p . def_id ( ) ) , ty :: Array ( subty , _ ) | ty :: Slice ( subty ) => characteristic_def_id_of_type ( subty ) , ty :: RawPtr ( mt ) => characteristic_def_id_of_type ( mt . ty ) , ty :: Ref ( _ , ty , _ ) => characteristic_def_id_of_type ( ty ) , ty :: Tuple ( ref tys ) => tys . iter ( ) . filter_map ( | ty | characteristic_def_id_of_type ( ty ) ) . next ( ) , ty :: FnDef ( def_id , _ ) | ty :: Closure ( def_id , _ ) | ty :: Generator ( def_id , _ , _ ) | ty :: Foreign ( def_id ) => Some ( def_id ) , ty :: Bool | ty :: Char | ty :: Int ( _ ) | ty :: Uint ( _ ) | ty :: Str | ty :: FnPtr ( _ ) | ty :: Projection ( _ ) | ty :: Param ( _ ) | ty :: Opaque ( .. ) | ty :: Infer ( _ ) | ty :: Error | ty :: GeneratorWitness ( .. ) | ty :: Never | ty :: Float ( _ ) => None , } }
As a heuristic, when we see an impl, if we see that the
'self-type' is a type defined in the same module as the impl,
we can omit including the path to the impl itself.
As a heuristic when we see an impl if we see that the ' self - type ' is a type defined in the same module as the impl we can omit including the path to the impl itself .
ty
Ty
ty
Ty