Pare down to_typename to match usage

This commit is contained in:
David Tolnay 2020-04-25 10:16:33 -07:00
parent 63da4d37b9
commit cd08c440ce
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -889,32 +889,21 @@ fn write_space_after_type(out: &mut OutFile, ty: &Type) {
}
}
// Only called for legal referent types of unique_ptr and element types of
// std::vector and Vec.
fn to_typename(namespace: &Namespace, ty: &Type) -> String {
match ty {
Type::Ident(ident) => {
let mut inner = String::new();
// Do not apply namespace to built-in type
let is_user_type = Atom::from(ident).is_none();
if is_user_type {
for name in namespace {
inner += name;
inner += "::";
}
let mut path = String::new();
for name in namespace {
path += name;
path += "::";
}
if let Some(ti) = Atom::from(ident) {
inner += ti.to_cxx();
} else {
inner += &ident.to_string();
};
inner
}
Type::RustBox(ptr) => format!("rust_box<{}>", to_typename(namespace, &ptr.inner)),
Type::RustVec(ptr) => format!("rust_vec<{}>", to_typename(namespace, &ptr.inner)),
Type::UniquePtr(ptr) => {
format!("::std::unique_ptr<{}>", to_typename(namespace, &ptr.inner))
path += &ident.to_string();
path
}
Type::CxxVector(ptr) => format!("::std::vector<{}>", to_typename(namespace, &ptr.inner)),
_ => unimplemented!(),
_ => unreachable!(),
}
}