Skip to content

Commit c87063f

Browse files
committed
rustc: avoid using subst::VecPerParamSpace::{empty,new} directly.
1 parent 77dc61b commit c87063f

File tree

9 files changed

+38
-44
lines changed

9 files changed

+38
-44
lines changed

src/librustc/traits/error_reporting.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
180180
ity.ty);
181181

182182
let rps = self.region_vars_for_defs(obligation.cause.span, rps);
183-
let mut substs = subst::Substs::new(
184-
subst::VecPerParamSpace::empty(),
185-
subst::VecPerParamSpace::new(Vec::new(), rps, Vec::new()));
183+
let mut substs = subst::Substs::new_type(vec![], rps);
186184
self.type_vars_for_defs(obligation.cause.span,
187185
TypeSpace,
188186
&mut substs,

src/librustc/ty/mod.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,15 @@ pub struct ItemVariances {
429429
pub regions: VecPerParamSpace<Variance>,
430430
}
431431

432+
impl ItemVariances {
433+
pub fn empty() -> ItemVariances {
434+
ItemVariances {
435+
types: VecPerParamSpace::empty(),
436+
regions: VecPerParamSpace::empty(),
437+
}
438+
}
439+
}
440+
432441
#[derive(Clone, PartialEq, RustcDecodable, RustcEncodable, Copy)]
433442
pub enum Variance {
434443
Covariant, // T<A> <: T<B> iff A <: B -- e.g., function return type
@@ -2864,22 +2873,20 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
28642873
pub fn construct_free_substs(self, generics: &Generics<'gcx>,
28652874
free_id_outlive: CodeExtent) -> Substs<'gcx> {
28662875
// map T => T
2867-
let mut types = VecPerParamSpace::empty();
2868-
for def in generics.types.as_full_slice() {
2876+
let types = generics.types.map(|def| {
28692877
debug!("construct_parameter_environment(): push_types_from_defs: def={:?}",
28702878
def);
2871-
types.push(def.space, self.global_tcx().mk_param_from_def(def));
2872-
}
2879+
self.global_tcx().mk_param_from_def(def)
2880+
});
28732881

28742882
// map bound 'a => free 'a
2875-
let mut regions = VecPerParamSpace::empty();
2876-
for def in generics.regions.as_full_slice() {
2883+
let regions = generics.regions.map(|def| {
28772884
let region =
28782885
ReFree(FreeRegion { scope: free_id_outlive,
28792886
bound_region: def.to_bound_region() });
28802887
debug!("push_region_params {:?}", region);
2881-
regions.push(def.space, region);
2882-
}
2888+
region
2889+
});
28832890

28842891
Substs {
28852892
types: types,

src/librustc/ty/subst.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
4141
Substs { types: t, regions: r }
4242
}
4343

44+
pub fn new_fn(t: Vec<Ty<'tcx>>,
45+
r: Vec<ty::Region>)
46+
-> Substs<'tcx>
47+
{
48+
Substs::new(VecPerParamSpace::new(vec![], vec![], t),
49+
VecPerParamSpace::new(vec![], vec![], r))
50+
}
51+
4452
pub fn new_type(t: Vec<Ty<'tcx>>,
4553
r: Vec<ty::Region>)
4654
-> Substs<'tcx>

src/librustc_metadata/decoder.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ use middle::cstore::{DefLike, DlDef, DlField, DlImpl, tls};
3535
use rustc::hir::def::Def;
3636
use rustc::hir::def_id::{DefId, DefIndex};
3737
use middle::lang_items;
38-
use rustc::ty::subst;
3938
use rustc::ty::{ImplContainer, TraitContainer};
4039
use rustc::ty::{self, Ty, TyCtxt, TypeFoldable, VariantKind};
4140

@@ -1580,25 +1579,24 @@ fn doc_generics<'a, 'tcx>(base_doc: rbml::Doc,
15801579
{
15811580
let doc = reader::get_doc(base_doc, tag);
15821581

1583-
let mut types = subst::VecPerParamSpace::empty();
1582+
let mut generics = ty::Generics::empty();
15841583
for p in reader::tagged_docs(doc, tag_type_param_def) {
15851584
let bd =
15861585
TyDecoder::with_doc(tcx, cdata.cnum, p,
15871586
&mut |did| translate_def_id(cdata, did))
15881587
.parse_type_param_def();
1589-
types.push(bd.space, bd);
1588+
generics.types.push(bd.space, bd);
15901589
}
15911590

1592-
let mut regions = subst::VecPerParamSpace::empty();
15931591
for p in reader::tagged_docs(doc, tag_region_param_def) {
15941592
let bd =
15951593
TyDecoder::with_doc(tcx, cdata.cnum, p,
15961594
&mut |did| translate_def_id(cdata, did))
15971595
.parse_region_param_def();
1598-
regions.push(bd.space, bd);
1596+
generics.regions.push(bd.space, bd);
15991597
}
16001598

1601-
ty::Generics { types: types, regions: regions }
1599+
generics
16021600
}
16031601

16041602
fn doc_predicate<'a, 'tcx>(cdata: Cmd,

src/librustc_mir/build/scope.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ should go to.
8989
use build::{BlockAnd, BlockAndExtension, Builder, CFG, ScopeAuxiliary, ScopeId};
9090
use rustc::middle::region::{CodeExtent, CodeExtentData};
9191
use rustc::middle::lang_items;
92-
use rustc::ty::subst::{Substs, Subst, VecPerParamSpace};
92+
use rustc::ty::subst::{Substs, Subst};
9393
use rustc::ty::{Ty, TyCtxt};
9494
use rustc::mir::repr::*;
9595
use syntax_pos::Span;
@@ -750,10 +750,7 @@ fn build_free<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
750750
-> TerminatorKind<'tcx> {
751751
let free_func = tcx.lang_items.require(lang_items::BoxFreeFnLangItem)
752752
.unwrap_or_else(|e| tcx.sess.fatal(&e));
753-
let substs = tcx.mk_substs(Substs::new(
754-
VecPerParamSpace::new(vec![], vec![], vec![data.item_ty]),
755-
VecPerParamSpace::new(vec![], vec![], vec![])
756-
));
753+
let substs = tcx.mk_substs(Substs::new_fn(vec![data.item_ty], vec![]));
757754
TerminatorKind::Call {
758755
func: Operand::Constant(Constant {
759756
span: data.span,

src/librustc_trans/base.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use rustc::cfg;
3939
use rustc::hir::def_id::DefId;
4040
use middle::lang_items::{LangItem, ExchangeMallocFnLangItem, StartFnLangItem};
4141
use rustc::hir::pat_util::simple_name;
42-
use rustc::ty::subst::{self, Substs};
42+
use rustc::ty::subst::Substs;
4343
use rustc::traits;
4444
use rustc::ty::{self, Ty, TyCtxt, TypeFoldable};
4545
use rustc::ty::adjustment::CustomCoerceUnsized;
@@ -675,10 +675,7 @@ pub fn custom_coerce_unsize_info<'scx, 'tcx>(scx: &SharedCrateContext<'scx, 'tcx
675675
source_ty: Ty<'tcx>,
676676
target_ty: Ty<'tcx>)
677677
-> CustomCoerceUnsized {
678-
let trait_substs = Substs::new(subst::VecPerParamSpace::new(vec![source_ty],
679-
vec![target_ty],
680-
Vec::new()),
681-
subst::VecPerParamSpace::empty());
678+
let trait_substs = Substs::new_trait(vec![target_ty], vec![], source_ty);
682679

683680
let trait_ref = ty::Binder(ty::TraitRef {
684681
def_id: scx.tcx().lang_items.coerce_unsized_trait().unwrap(),

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2796,9 +2796,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
27962796
debug!("impl_self_ty: tps={:?} rps={:?} raw_ty={:?}", tps, rps, raw_ty);
27972797

27982798
let rps = self.region_vars_for_defs(span, rps);
2799-
let mut substs = subst::Substs::new(
2800-
VecPerParamSpace::empty(),
2801-
VecPerParamSpace::new(Vec::new(), rps, Vec::new()));
2799+
let mut substs = subst::Substs::new_type(vec![], rps);
28022800
self.type_vars_for_defs(span, ParamSpace::TypeSpace, &mut substs, tps);
28032801
let substd_ty = self.instantiate_type_scheme(span, &substs, &raw_ty);
28042802

src/librustc_typeck/variance/solve.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
//! optimal solution to the constraints. The final variance for each
1616
//! inferred is then written into the `variance_map` in the tcx.
1717
18-
use rustc::ty::subst::VecPerParamSpace;
1918
use rustc::ty;
2019
use std::rc::Rc;
2120

@@ -109,26 +108,21 @@ impl<'a, 'tcx> SolveContext<'a, 'tcx> {
109108
let num_inferred = self.terms_cx.num_inferred();
110109
while index < num_inferred {
111110
let item_id = inferred_infos[index].item_id;
112-
let mut types = VecPerParamSpace::empty();
113-
let mut regions = VecPerParamSpace::empty();
111+
let mut item_variances = ty::ItemVariances::empty();
114112

115113
while index < num_inferred && inferred_infos[index].item_id == item_id {
116114
let info = &inferred_infos[index];
117115
let variance = solutions[index];
118116
debug!("Index {} Info {} / {:?} / {:?} Variance {:?}",
119117
index, info.index, info.kind, info.space, variance);
120118
match info.kind {
121-
TypeParam => { types.push(info.space, variance); }
122-
RegionParam => { regions.push(info.space, variance); }
119+
TypeParam => { item_variances.types.push(info.space, variance); }
120+
RegionParam => { item_variances.regions.push(info.space, variance); }
123121
}
124122

125123
index += 1;
126124
}
127125

128-
let item_variances = ty::ItemVariances {
129-
types: types,
130-
regions: regions
131-
};
132126
debug!("item_id={} item_variances={:?}",
133127
item_id,
134128
item_variances);

src/librustc_typeck/variance/terms.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
use arena::TypedArena;
2323
use dep_graph::DepTrackingMapConfig;
24-
use rustc::ty::subst::{ParamSpace, FnSpace, TypeSpace, SelfSpace, VecPerParamSpace};
24+
use rustc::ty::subst::{ParamSpace, FnSpace, TypeSpace, SelfSpace};
2525
use rustc::ty::{self, TyCtxt};
2626
use rustc::ty::maps::ItemVariances;
2727
use std::fmt;
@@ -112,10 +112,7 @@ pub fn determine_parameters_to_be_inferred<'a, 'tcx>(
112112

113113
// cache and share the variance struct used for items with
114114
// no type/region parameters
115-
empty_variances: Rc::new(ty::ItemVariances {
116-
types: VecPerParamSpace::empty(),
117-
regions: VecPerParamSpace::empty()
118-
})
115+
empty_variances: Rc::new(ty::ItemVariances::empty())
119116
};
120117

121118
// See README.md for a discussion on dep-graph management.

0 commit comments

Comments
 (0)