/// 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::TyStruct(adt_def, _) |
        ty::TyEnum(adt_def, _) => Some(adt_def.did),
        ty::TyTrait(ref data) => Some(data.principal_def_id()),
        ty::TyArray(subty, _) |
        ty::TySlice(subty) |
        ty::TyBox(subty) => characteristic_def_id_of_type(subty),
        ty::TyRawPtr(mt) |
        ty::TyRef(_, mt) => characteristic_def_id_of_type(mt.ty),
        ty::TyTuple(ref tys) => tys.iter()
                                   .filter_map(|ty| characteristic_def_id_of_type(ty))
                                   .next(),
        ty::TyFnDef(def_id, _, _) |
        ty::TyClosure(def_id, _) => Some(def_id),
        ty::TyBool |
        ty::TyChar |
        ty::TyInt(_) |
        ty::TyUint(_) |
        ty::TyStr |
        ty::TyFnPtr(_) |
        ty::TyProjection(_) |
        ty::TyParam(_) |
        ty::TyInfer(_) |
        ty::TyError |
        ty::TyFloat(_) => None,
    }
}
pub fn characteristic_def_id_of_type ( ty : Ty ) -> Option < DefId > { match ty . sty { ty :: TyStruct ( adt_def , _ ) | ty :: TyEnum ( adt_def , _ ) => Some ( adt_def . did ) , ty :: TyTrait ( ref data ) => Some ( data . principal_def_id ( ) ) , ty :: TyArray ( subty , _ ) | ty :: TySlice ( subty ) | ty :: TyBox ( subty ) => characteristic_def_id_of_type ( subty ) , ty :: TyRawPtr ( mt ) | ty :: TyRef ( _ , mt ) => characteristic_def_id_of_type ( mt . ty ) , ty :: TyTuple ( ref tys ) => tys . iter ( ) . filter_map ( | ty | characteristic_def_id_of_type ( ty ) ) . next ( ) , ty :: TyFnDef ( def_id , _ , _ ) | ty :: TyClosure ( def_id , _ ) => Some ( def_id ) , ty :: TyBool | ty :: TyChar | ty :: TyInt ( _ ) | ty :: TyUint ( _ ) | ty :: TyStr | ty :: TyFnPtr ( _ ) | ty :: TyProjection ( _ ) | ty :: TyParam ( _ ) | ty :: TyInfer ( _ ) | ty :: TyError | ty :: TyFloat ( _ ) => 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