Skip to content

Commit dce288e

Browse files
committed
rustc: don't expose Substs::fill_item as public.
1 parent 7e4d871 commit dce288e

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

src/librustc/ty/subst.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
195195
tcx.intern_substs(&result)
196196
}
197197

198-
pub fn fill_item<F>(substs: &mut Vec<Kind<'tcx>>,
199-
tcx: TyCtxt<'a, 'gcx, 'tcx>,
200-
defs: &ty::Generics,
201-
mk_kind: &mut F)
198+
fn fill_item<F>(substs: &mut Vec<Kind<'tcx>>,
199+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
200+
defs: &ty::Generics,
201+
mk_kind: &mut F)
202202
where F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Kind<'tcx>
203203
{
204204

@@ -210,8 +210,8 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
210210
}
211211

212212
fn fill_single<F>(substs: &mut Vec<Kind<'tcx>>,
213-
defs: &ty::Generics,
214-
mk_kind: &mut F)
213+
defs: &ty::Generics,
214+
mk_kind: &mut F)
215215
where F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Kind<'tcx>
216216
{
217217
for param in &defs.params {

src/librustc_typeck/astconv.rs

+19-22
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use hir::def::Def;
1818
use hir::def_id::DefId;
1919
use middle::resolve_lifetime as rl;
2020
use namespace::Namespace;
21-
use rustc::ty::subst::{UnpackedKind, Subst, Substs};
21+
use rustc::ty::subst::{Subst, Substs};
2222
use rustc::traits;
2323
use rustc::ty::{self, Ty, TyCtxt, ToPredicate, TypeFoldable};
2424
use rustc::ty::GenericParamDefKind;
@@ -1152,32 +1152,29 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
11521152
let tcx = self.tcx();
11531153
let generics = tcx.generics_of(def_id);
11541154

1155-
// Fill in the substs of the parent generics
11561155
debug!("impl_trait_ty_to_ty: generics={:?}", generics);
1157-
let mut substs = Vec::with_capacity(generics.count());
1158-
if let Some(parent_id) = generics.parent {
1159-
let parent_generics = tcx.generics_of(parent_id);
1160-
Substs::fill_item(&mut substs, tcx, parent_generics, &mut |param, _| {
1161-
tcx.mk_param_from_def(param)
1162-
});
1163-
1164-
// Replace all lifetimes with 'static
1165-
for subst in &mut substs {
1166-
if let UnpackedKind::Lifetime(_) = subst.unpack() {
1167-
*subst = tcx.types.re_static.into();
1156+
let substs = Substs::for_item(tcx, def_id, |param, _| {
1157+
if let Some(i) = (param.index as usize).checked_sub(generics.parent_count) {
1158+
// Our own parameters are the resolved lifetimes.
1159+
match param.kind {
1160+
GenericParamDefKind::Lifetime => {
1161+
self.ast_region_to_region(&lifetimes[i], None).into()
1162+
}
1163+
_ => bug!()
1164+
}
1165+
} else {
1166+
// Replace all parent lifetimes with 'static.
1167+
match param.kind {
1168+
GenericParamDefKind::Lifetime => {
1169+
tcx.types.re_static.into()
1170+
}
1171+
_ => tcx.mk_param_from_def(param)
11681172
}
11691173
}
1170-
debug!("impl_trait_ty_to_ty: substs from parent = {:?}", substs);
1171-
}
1172-
assert_eq!(substs.len(), generics.parent_count);
1173-
1174-
// Fill in our own generics with the resolved lifetimes
1175-
assert_eq!(lifetimes.len(), generics.params.len());
1176-
substs.extend(lifetimes.iter().map(|lt| self.ast_region_to_region(lt, None).into()));
1177-
1174+
});
11781175
debug!("impl_trait_ty_to_ty: final substs = {:?}", substs);
11791176

1180-
tcx.mk_anon(def_id, tcx.intern_substs(&substs))
1177+
tcx.mk_anon(def_id, substs)
11811178
}
11821179

11831180
pub fn ty_of_arg(&self,

0 commit comments

Comments
 (0)