Skip to content

Commit 3c84e31

Browse files
committed
Use a struct rather than a 4-tuple
1 parent fb9d0cc commit 3c84e31

File tree

2 files changed

+44
-12
lines changed

2 files changed

+44
-12
lines changed

src/librustc/middle/subst.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,17 @@ pub struct VecPerParamSpace<T> {
282282
content: Vec<T>,
283283
}
284284

285+
/**
286+
* The `split` function converts one `VecPerParamSpace` into this
287+
* `SeparateVecsPerParamSpace` structure.
288+
*/
289+
pub struct SeparateVecsPerParamSpace<T> {
290+
pub types: Vec<T>,
291+
pub selfs: Vec<T>,
292+
pub assocs: Vec<T>,
293+
pub fns: Vec<T>,
294+
}
295+
285296
impl<T:fmt::Show> fmt::Show for VecPerParamSpace<T> {
286297
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
287298
try!(write!(fmt, "VecPerParamSpace {{"));
@@ -464,24 +475,30 @@ impl<T> VecPerParamSpace<T> {
464475
}
465476

466477
pub fn map_move<U>(self, pred: |T| -> U) -> VecPerParamSpace<U> {
467-
let (t, s, a, f) = self.split();
478+
let SeparateVecsPerParamSpace {
479+
types: t,
480+
selfs: s,
481+
assocs: a,
482+
fns: f
483+
} = self.split();
484+
468485
VecPerParamSpace::new(t.into_iter().map(|p| pred(p)).collect(),
469486
s.into_iter().map(|p| pred(p)).collect(),
470487
a.into_iter().map(|p| pred(p)).collect(),
471488
f.into_iter().map(|p| pred(p)).collect())
472489
}
473490

474-
pub fn split(self) -> (Vec<T>, Vec<T>, Vec<T>, Vec<T>) {
491+
pub fn split(self) -> SeparateVecsPerParamSpace<T> {
475492
let VecPerParamSpace { type_limit, self_limit, assoc_limit, content } = self;
476493

477494
let mut content_iter = content.into_iter();
478495

479-
let types = content_iter.by_ref().take(type_limit).collect();
480-
let selfs = content_iter.by_ref().take(self_limit - type_limit).collect();
481-
let assocs = content_iter.by_ref().take(assoc_limit - self_limit).collect();
482-
let fns = content_iter.collect();
483-
484-
(types, selfs, assocs, fns)
496+
SeparateVecsPerParamSpace {
497+
types: content_iter.by_ref().take(type_limit).collect(),
498+
selfs: content_iter.by_ref().take(self_limit - type_limit).collect(),
499+
assocs: content_iter.by_ref().take(assoc_limit - self_limit).collect(),
500+
fns: content_iter.collect()
501+
}
485502
}
486503

487504
pub fn with_vec(mut self, space: ParamSpace, vec: Vec<T>)

src/librustc/middle/trans/meth.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,12 @@ pub fn trans_static_method_callee(bcx: Block,
205205
// type parameters that belong to the trait but also some that
206206
// belong to the method:
207207
let rcvr_substs = node_id_substs(bcx, ExprId(expr_id));
208-
let (rcvr_type, rcvr_self, rcvr_assoc, rcvr_method) = rcvr_substs.types.split();
208+
let subst::SeparateVecsPerParamSpace {
209+
types: rcvr_type,
210+
selfs: rcvr_self,
211+
assocs: rcvr_assoc,
212+
fns: rcvr_method
213+
} = rcvr_substs.types.split();
209214

210215
// Lookup the precise impl being called. To do that, we need to
211216
// create a trait reference identifying the self type and other
@@ -266,7 +271,12 @@ pub fn trans_static_method_callee(bcx: Block,
266271
// that with the `rcvr_method` from before, which tells us
267272
// the type parameters from the *method*, to yield
268273
// `callee_substs=[[T=int],[],[U=String]]`.
269-
let (impl_type, impl_self, impl_assoc, _) = impl_substs.types.split();
274+
let subst::SeparateVecsPerParamSpace {
275+
types: impl_type,
276+
selfs: impl_self,
277+
assocs: impl_assoc,
278+
fns: _
279+
} = impl_substs.types.split();
270280
let callee_substs =
271281
Substs::erased(VecPerParamSpace::new(impl_type,
272282
impl_self,
@@ -399,8 +409,13 @@ fn combine_impl_and_methods_tps(bcx: Block,
399409

400410
// Break apart the type parameters from the node and type
401411
// parameters from the receiver.
402-
let (_, _, _, node_method) = node_substs.types.split();
403-
let (rcvr_type, rcvr_self, rcvr_assoc, rcvr_method) = rcvr_substs.types.clone().split();
412+
let node_method = node_substs.types.split().fns;
413+
let subst::SeparateVecsPerParamSpace {
414+
types: rcvr_type,
415+
selfs: rcvr_self,
416+
assocs: rcvr_assoc,
417+
fns: rcvr_method
418+
} = rcvr_substs.types.clone().split();
404419
assert!(rcvr_method.is_empty());
405420
subst::Substs {
406421
regions: subst::ErasedRegions,

0 commit comments

Comments
 (0)