Remove allocation in push_type_params

This commit is contained in:
Mark-Simulacrum 2016-11-25 21:54:48 -07:00
parent a79c80d0b0
commit 8b82fd7a94

View file

@ -36,6 +36,7 @@
use abi::{Abi, FnType};
use back::symbol_names;
use std::fmt::Write;
use std::iter;
#[derive(PartialEq, Eq, Clone, Copy, Debug, Hash)]
pub enum TransItem<'tcx> {
@ -410,7 +411,7 @@ pub fn push_type_name(&self, t: Ty<'tcx>, output: &mut String) {
ty::TyFloat(ast::FloatTy::F64) => output.push_str("f64"),
ty::TyAdt(adt_def, substs) => {
self.push_def_path(adt_def.did, output);
self.push_type_params(substs, &[], output);
self.push_type_params(substs, iter::empty(), output);
},
ty::TyTuple(component_types) => {
output.push('(');
@ -461,7 +462,7 @@ pub fn push_type_name(&self, t: Ty<'tcx>, output: &mut String) {
if let Some(principal) = trait_data.principal() {
self.push_def_path(principal.def_id(), output);
self.push_type_params(principal.skip_binder().substs,
&trait_data.projection_bounds().collect::<Vec<_>>()[..],
trait_data.projection_bounds(),
output);
}
},
@ -513,7 +514,7 @@ pub fn push_type_name(&self, t: Ty<'tcx>, output: &mut String) {
self.push_def_path(def_id, output);
let generics = self.tcx.item_generics(self.tcx.closure_base_def_id(def_id));
let substs = closure_substs.substs.truncate_to(self.tcx, generics);
self.push_type_params(substs, &[], output);
self.push_type_params(substs, iter::empty(), output);
}
ty::TyError |
ty::TyInfer(_) |
@ -553,11 +554,14 @@ pub fn push_def_path(&self,
output.pop();
}
pub fn push_type_params(&self,
fn push_type_params<I>(&self,
substs: &Substs<'tcx>,
projections: &[ty::PolyExistentialProjection<'tcx>],
output: &mut String) {
if substs.types().next().is_none() && projections.is_empty() {
projections: I,
output: &mut String)
where I: Iterator<Item=ty::PolyExistentialProjection<'tcx>>
{
let mut projections = projections.peekable();
if substs.types().next().is_none() && projections.peek().is_none() {
return;
}
@ -587,6 +591,6 @@ pub fn push_instance_as_string(&self,
instance: Instance<'tcx>,
output: &mut String) {
self.push_def_path(instance.def, output);
self.push_type_params(instance.substs, &[], output);
self.push_type_params(instance.substs, iter::empty(), output);
}
}