in checker/src/utils.rs [164:329]
fn append_mangled_type<'tcx>(str: &mut String, ty: Ty<'tcx>, tcx: TyCtxt<'tcx>) {
trace!("append_mangled_type {:?} to {}", ty.kind(), str);
use TyKind::*;
match ty.kind() {
Bool => str.push_str("bool"),
Char => str.push_str("char"),
Int(int_ty) => {
str.push_str(match int_ty {
IntTy::Isize => "isize",
IntTy::I8 => "i8",
IntTy::I16 => "i16",
IntTy::I32 => "i32",
IntTy::I64 => "i64",
IntTy::I128 => "i128",
});
}
Uint(uint_ty) => {
str.push_str(match uint_ty {
UintTy::Usize => "usize",
UintTy::U8 => "u8",
UintTy::U16 => "u16",
UintTy::U32 => "u32",
UintTy::U64 => "u64",
UintTy::U128 => "u128",
});
}
Float(float_ty) => {
str.push_str(match float_ty {
FloatTy::F32 => "f32",
FloatTy::F64 => "f64",
});
}
Adt(def, subs) => {
str.push_str(qualified_type_name(tcx, def.did()).as_str());
for sub in *subs {
if let GenericArgKind::Type(ty) = sub.unpack() {
str.push('_');
append_mangled_type(str, ty, tcx);
}
}
}
Closure(def_id, subs) => {
str.push_str("closure_");
str.push_str(qualified_type_name(tcx, *def_id).as_str());
for sub in subs.as_closure().substs {
if let GenericArgKind::Type(ty) = sub.unpack() {
str.push('_');
append_mangled_type(str, ty, tcx);
}
}
}
Dynamic(trait_data, ..) => {
str.push_str("trait_");
if let Some(principal) = trait_data.principal() {
let principal =
tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), principal);
str.push_str(qualified_type_name(tcx, principal.def_id).as_str());
for sub in principal.substs {
if let GenericArgKind::Type(ty) = sub.unpack() {
str.push('_');
append_mangled_type(str, ty, tcx);
}
}
}
}
Foreign(def_id) => {
str.push_str("extern_type_");
str.push_str(qualified_type_name(tcx, *def_id).as_str());
}
FnDef(def_id, subs) => {
str.push_str("fn_");
str.push_str(qualified_type_name(tcx, *def_id).as_str());
for sub in *subs {
if let GenericArgKind::Type(ty) = sub.unpack() {
str.push('_');
append_mangled_type(str, ty, tcx);
}
}
}
Generator(def_id, subs, ..) => {
str.push_str("generator_");
str.push_str(qualified_type_name(tcx, *def_id).as_str());
for sub in subs.as_generator().substs {
if let GenericArgKind::Type(ty) = sub.unpack() {
str.push('_');
append_mangled_type(str, ty, tcx);
}
}
}
GeneratorWitness(binder) => {
for ty in binder.skip_binder().iter() {
str.push('_');
append_mangled_type(str, ty, tcx)
}
}
Opaque(def_id, subs) => {
str.push_str("impl_");
str.push_str(qualified_type_name(tcx, *def_id).as_str());
for sub in *subs {
if let GenericArgKind::Type(ty) = sub.unpack() {
str.push('_');
append_mangled_type(str, ty, tcx);
}
}
}
Str => str.push_str("str"),
Array(ty, _) => {
str.push_str("array_");
append_mangled_type(str, *ty, tcx);
}
Slice(ty) => {
str.push_str("slice_");
append_mangled_type(str, *ty, tcx);
}
RawPtr(ty_and_mut) => {
str.push_str("pointer_");
match ty_and_mut.mutbl {
rustc_hir::Mutability::Mut => str.push_str("mut_"),
rustc_hir::Mutability::Not => str.push_str("const_"),
}
append_mangled_type(str, ty_and_mut.ty, tcx);
}
Ref(_, ty, mutability) => {
str.push_str("ref_");
if *mutability == rustc_hir::Mutability::Mut {
str.push_str("mut_");
}
append_mangled_type(str, *ty, tcx);
}
FnPtr(poly_fn_sig) => {
let fn_sig = poly_fn_sig.skip_binder();
str.push_str("fn_ptr_");
for arg_type in fn_sig.inputs() {
append_mangled_type(str, *arg_type, tcx);
str.push('_');
}
append_mangled_type(str, fn_sig.output(), tcx);
}
Tuple(types) => {
str.push_str("tuple_");
str.push_str(&format!("{}", types.len()));
types.iter().for_each(|t| {
str.push('_');
append_mangled_type(str, t, tcx);
});
}
Param(param_ty) => {
str.push_str("generic_par_");
str.push_str(param_ty.name.as_str());
}
Projection(projection_ty) => {
append_mangled_type(str, projection_ty.self_ty(), tcx);
str.push_str("_as_");
str.push_str(qualified_type_name(tcx, projection_ty.item_def_id).as_str());
}
Never => {
str.push('_');
}
_ => {
//todo: add cases as the need arises, meanwhile make the need obvious.
debug!("{:?}", ty);
debug!("{:?}", ty.kind());
str.push_str(&format!("default formatted {:?}", ty))
}
}
}