Skip to content

Commit e9c28b2

Browse files
committed
Use Kind instead of UnpackedKind in Substs methods
1 parent 3ae2468 commit e9c28b2

File tree

15 files changed

+75
-94
lines changed

15 files changed

+75
-94
lines changed

src/librustc/infer/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use hir::def_id::DefId;
2121
use middle::free_region::RegionRelations;
2222
use middle::region;
2323
use middle::lang_items;
24-
use ty::subst::{UnpackedKind, Substs};
24+
use ty::subst::{Kind, Substs};
2525
use ty::{TyVid, IntVid, FloatVid};
2626
use ty::{self, Ty, TyCtxt, GenericParamDefKind};
2727
use ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric};
@@ -908,12 +908,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
908908
pub fn var_for_def(&self,
909909
span: Span,
910910
param: &ty::GenericParamDef)
911-
-> UnpackedKind<'tcx> {
911+
-> Kind<'tcx> {
912912
match param.kind {
913913
GenericParamDefKind::Lifetime => {
914914
// Create a region inference variable for the given
915915
// region parameter definition.
916-
UnpackedKind::Lifetime(self.next_region_var(EarlyBoundRegion(span, param.name)))
916+
self.next_region_var(EarlyBoundRegion(span, param.name)).into()
917917
}
918918
GenericParamDefKind::Type(_) => {
919919
// Create a type inference variable for the given
@@ -930,7 +930,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
930930
false,
931931
TypeVariableOrigin::TypeParameterDefinition(span, param.name));
932932

933-
UnpackedKind::Type(self.tcx.mk_var(ty_var_id))
933+
self.tcx.mk_var(ty_var_id).into()
934934
}
935935
}
936936
}

src/librustc/traits/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use hir::def_id::DefId;
2222
use infer::outlives::env::OutlivesEnvironment;
2323
use middle::region;
2424
use middle::const_val::ConstEvalErr;
25-
use ty::subst::{UnpackedKind, Substs};
25+
use ty::subst::Substs;
2626
use ty::{self, AdtKind, Slice, Ty, TyCtxt, GenericParamDefKind, TypeFoldable, ToPredicate};
2727
use ty::error::{ExpectedFound, TypeError};
2828
use infer::{InferCtxt};
@@ -843,11 +843,9 @@ fn vtable_methods<'a, 'tcx>(
843843
let substs = trait_ref.map_bound(|trait_ref| {
844844
Substs::for_item(tcx, def_id, |param, _| {
845845
match param.kind {
846-
GenericParamDefKind::Lifetime => {
847-
UnpackedKind::Lifetime(tcx.types.re_erased)
848-
}
846+
GenericParamDefKind::Lifetime => tcx.types.re_erased.into(),
849847
GenericParamDefKind::Type(_) => {
850-
UnpackedKind::Type(trait_ref.substs.type_for_def(param))
848+
trait_ref.substs.type_for_def(param).into()
851849
}
852850
}
853851
})

src/librustc/ty/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use middle::lang_items;
3232
use middle::resolve_lifetime::{self, ObjectLifetimeDefault};
3333
use middle::stability;
3434
use mir::{self, Mir, interpret};
35-
use ty::subst::{Kind, UnpackedKind, Substs, Subst};
35+
use ty::subst::{Kind, Substs, Subst};
3636
use ty::ReprOptions;
3737
use ty::Instance;
3838
use traits;
@@ -2331,10 +2331,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
23312331
GenericParamDefKind::Lifetime => bug!(),
23322332
GenericParamDefKind::Type(ty_param) => {
23332333
if param.index == 0 {
2334-
UnpackedKind::Type(ty)
2334+
ty.into()
23352335
} else {
23362336
assert!(ty_param.has_default);
2337-
UnpackedKind::Type(self.type_of(param.def_id).subst(self, substs))
2337+
self.type_of(param.def_id).subst(self, substs).into()
23382338
}
23392339
}
23402340
}

src/librustc/ty/subst.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,9 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
184184
Substs::for_item(tcx, def_id, |param, _| {
185185
match param.kind {
186186
GenericParamDefKind::Lifetime => {
187-
UnpackedKind::Lifetime(
188-
tcx.mk_region(ty::ReEarlyBound(param.to_early_bound_region_data())))
189-
}
190-
GenericParamDefKind::Type(_) => {
191-
UnpackedKind::Type(tcx.mk_ty_param_from_def(param))
187+
tcx.mk_region(ty::ReEarlyBound(param.to_early_bound_region_data())).into()
192188
}
189+
GenericParamDefKind::Type(_) => tcx.mk_ty_param_from_def(param).into(),
193190
}
194191
})
195192
}
@@ -203,7 +200,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
203200
def_id: DefId,
204201
mut mk_kind: F)
205202
-> &'tcx Substs<'tcx>
206-
where F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> UnpackedKind<'tcx>
203+
where F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Kind<'tcx>
207204
{
208205
let defs = tcx.generics_of(def_id);
209206
let mut substs = Vec::with_capacity(defs.count());
@@ -216,7 +213,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
216213
def_id: DefId,
217214
mut mk_kind: F)
218215
-> &'tcx Substs<'tcx>
219-
where F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> UnpackedKind<'tcx>
216+
where F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Kind<'tcx>
220217
{
221218
let defs = tcx.generics_of(def_id);
222219
let mut result = Vec::with_capacity(defs.count());
@@ -229,7 +226,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
229226
tcx: TyCtxt<'a, 'gcx, 'tcx>,
230227
defs: &ty::Generics,
231228
mk_kind: &mut F)
232-
where F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> UnpackedKind<'tcx>
229+
where F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Kind<'tcx>
233230
{
234231

235232
if let Some(def_id) = defs.parent {
@@ -242,12 +239,12 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
242239
fn fill_single<F>(substs: &mut Vec<Kind<'tcx>>,
243240
defs: &ty::Generics,
244241
mk_kind: &mut F)
245-
where F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> UnpackedKind<'tcx>
242+
where F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Kind<'tcx>
246243
{
247244
for param in &defs.params {
248245
let kind = mk_kind(param, substs);
249246
assert_eq!(param.index as usize, substs.len());
250-
substs.push(kind.pack());
247+
substs.push(kind);
251248
}
252249
}
253250

src/librustc/ty/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
576576
pub fn empty_substs_for_def_id(self, item_def_id: DefId) -> &'tcx Substs<'tcx> {
577577
Substs::for_item(self, item_def_id, |param, _| {
578578
match param.kind {
579-
GenericParamDefKind::Lifetime => UnpackedKind::Lifetime(self.types.re_erased),
579+
GenericParamDefKind::Lifetime => self.types.re_erased.into(),
580580
GenericParamDefKind::Type(_) => {
581581
bug!("empty_substs_for_def_id: {:?} has type parameters", item_def_id)
582582
}

src/librustc_mir/monomorphize/collector.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ use rustc::hir::def_id::DefId;
196196
use rustc::middle::const_val::ConstVal;
197197
use rustc::mir::interpret::{AllocId, ConstValue};
198198
use rustc::middle::lang_items::{ExchangeMallocFnLangItem, StartFnLangItem};
199-
use rustc::ty::subst::{Substs, Kind, UnpackedKind};
199+
use rustc::ty::subst::{Substs, Kind};
200200
use rustc::ty::{self, TypeFoldable, Ty, TyCtxt, GenericParamDefKind};
201201
use rustc::ty::adjustment::CustomCoerceUnsized;
202202
use rustc::session::config;
@@ -1114,11 +1114,9 @@ fn create_mono_items_for_default_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11141114

11151115
let substs = Substs::for_item(tcx, method.def_id, |param, _| {
11161116
match param.kind {
1117-
GenericParamDefKind::Lifetime => {
1118-
UnpackedKind::Lifetime(tcx.types.re_erased)
1119-
}
1117+
GenericParamDefKind::Lifetime => tcx.types.re_erased.into(),
11201118
GenericParamDefKind::Type(_) => {
1121-
UnpackedKind::Type(trait_ref.substs.type_for_def(param))
1119+
trait_ref.substs.type_for_def(param).into()
11221120
}
11231121
}
11241122
});

src/librustc_mir/shim.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc::hir::def_id::DefId;
1313
use rustc::infer;
1414
use rustc::mir::*;
1515
use rustc::ty::{self, Ty, TyCtxt, GenericParamDefKind};
16-
use rustc::ty::subst::{Kind, UnpackedKind, Subst, Substs};
16+
use rustc::ty::subst::{Kind, Subst, Substs};
1717
use rustc::ty::maps::Providers;
1818

1919
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
@@ -429,8 +429,8 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
429429

430430
let substs = Substs::for_item(tcx, self.def_id, |param, _| {
431431
match param.kind {
432-
GenericParamDefKind::Lifetime => UnpackedKind::Lifetime(tcx.types.re_erased),
433-
GenericParamDefKind::Type(_) => UnpackedKind::Type(ty),
432+
GenericParamDefKind::Lifetime => tcx.types.re_erased.into(),
433+
GenericParamDefKind::Type(_) => ty.into(),
434434
}
435435
});
436436

src/librustc_typeck/astconv.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -269,31 +269,30 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
269269
match param.kind {
270270
GenericParamDefKind::Lifetime => {
271271
let i = param.index as usize - own_self;
272-
let lt = if let Some(lifetime) = parameters.lifetimes.get(i) {
273-
self.ast_region_to_region(lifetime, Some(param))
272+
if let Some(lifetime) = parameters.lifetimes.get(i) {
273+
self.ast_region_to_region(lifetime, Some(param)).into()
274274
} else {
275-
tcx.types.re_static
276-
};
277-
UnpackedKind::Lifetime(lt)
275+
tcx.types.re_static.into()
276+
}
278277
}
279278
GenericParamDefKind::Type(ty) => {
280279
let i = param.index as usize;
281280

282281
// Handle Self first, so we can adjust the index to match the AST.
283282
if let (0, Some(ty)) = (i, self_ty) {
284-
return UnpackedKind::Type(ty);
283+
return ty.into();
285284
}
286285

287286
let i = i - (lt_accepted + own_self);
288-
let ty = if i < ty_provided {
287+
if i < ty_provided {
289288
// A provided type parameter.
290-
self.ast_ty_to_ty(&parameters.types[i])
289+
self.ast_ty_to_ty(&parameters.types[i]).into()
291290
} else if infer_types {
292291
// No type parameters were provided, we can infer all.
293292
if !default_needs_object_self(param) {
294-
self.ty_infer_for_def(param, span)
293+
self.ty_infer_for_def(param, span).into()
295294
} else {
296-
self.ty_infer(span)
295+
self.ty_infer(span).into()
297296
}
298297
} else if ty.has_default {
299298
// No type parameter provided, but a default exists.
@@ -314,20 +313,19 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
314313
type parameters must be specified on object \
315314
types"))
316315
.emit();
317-
tcx.types.err
316+
tcx.types.err.into()
318317
} else {
319318
// This is a default type parameter.
320319
self.normalize_ty(
321320
span,
322321
tcx.at(span).type_of(param.def_id)
323322
.subst_spanned(tcx, substs, Some(span))
324-
)
323+
).into()
325324
}
326325
} else {
327326
// We've already errored above about the mismatch.
328-
tcx.types.err
329-
};
330-
UnpackedKind::Type(ty)
327+
tcx.types.err.into()
328+
}
331329
}
332330
}
333331
});
@@ -1162,12 +1160,10 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
11621160
Substs::fill_item(&mut substs, tcx, parent_generics, &mut |param, _| {
11631161
match param.kind {
11641162
GenericParamDefKind::Lifetime => {
1165-
UnpackedKind::Lifetime(
1166-
tcx.mk_region(ty::ReEarlyBound(param.to_early_bound_region_data())))
1167-
}
1168-
GenericParamDefKind::Type(_) => {
1169-
UnpackedKind::Type(tcx.mk_ty_param_from_def(param))
1163+
tcx.mk_region(
1164+
ty::ReEarlyBound(param.to_early_bound_region_data())).into()
11701165
}
1166+
GenericParamDefKind::Type(_) => tcx.mk_ty_param_from_def(param).into(),
11711167
}
11721168
});
11731169

src/librustc_typeck/check/closure.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc::infer::LateBoundRegionConversionTime;
1919
use rustc::infer::type_variable::TypeVariableOrigin;
2020
use rustc::traits::error_reporting::ArgKind;
2121
use rustc::ty::{self, ToPolyTraitRef, Ty, GenericParamDefKind};
22-
use rustc::ty::subst::{UnpackedKind, Substs};
22+
use rustc::ty::subst::Substs;
2323
use rustc::ty::TypeFoldable;
2424
use std::cmp;
2525
use std::iter;
@@ -110,8 +110,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
110110
span_bug!(expr.span, "closure has region param")
111111
}
112112
GenericParamDefKind::Type(_) => {
113-
UnpackedKind::Type(self.infcx
114-
.next_ty_var(TypeVariableOrigin::ClosureSynthetic(expr.span)))
113+
self.infcx
114+
.next_ty_var(TypeVariableOrigin::ClosureSynthetic(expr.span)).into()
115115
}
116116
}
117117
});

src/librustc_typeck/check/method/confirm.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use hir::def_id::DefId;
1616
use rustc::ty::subst::Substs;
1717
use rustc::traits;
1818
use rustc::ty::{self, Ty, GenericParamDefKind};
19-
use rustc::ty::subst::{UnpackedKind, Subst};
19+
use rustc::ty::subst::Subst;
2020
use rustc::ty::adjustment::{Adjustment, Adjust, OverloadedDeref};
2121
use rustc::ty::adjustment::{AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
2222
use rustc::ty::fold::TypeFoldable;
@@ -320,22 +320,22 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
320320
Substs::for_item(self.tcx, pick.item.def_id, |param, _| {
321321
let i = param.index as usize;
322322
if i < parent_substs.len() {
323-
parent_substs[i].unpack()
323+
parent_substs[i]
324324
} else {
325325
match param.kind {
326326
GenericParamDefKind::Lifetime => {
327327
if let Some(lifetime) = provided.as_ref().and_then(|p| {
328328
p.lifetimes.get(i - parent_substs.len())
329329
}) {
330-
return UnpackedKind::Lifetime(
331-
AstConv::ast_region_to_region(self.fcx, lifetime, Some(param)));
330+
return AstConv::ast_region_to_region(
331+
self.fcx, lifetime, Some(param)).into();
332332
}
333333
}
334334
GenericParamDefKind::Type(_) => {
335335
if let Some(ast_ty) = provided.as_ref().and_then(|p| {
336336
p.types.get(i - parent_substs.len() - own_counts.lifetimes)
337337
}) {
338-
return UnpackedKind::Type(self.to_ty(ast_ty));
338+
return self.to_ty(ast_ty).into();
339339
}
340340
}
341341
}

src/librustc_typeck/check/method/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc::ty::subst::Substs;
2020
use rustc::traits;
2121
use rustc::ty::{self, Ty, ToPredicate, ToPolyTraitRef, TraitRef, TypeFoldable};
2222
use rustc::ty::GenericParamDefKind;
23-
use rustc::ty::subst::{UnpackedKind, Subst};
23+
use rustc::ty::subst::Subst;
2424
use rustc::infer::{self, InferOk};
2525

2626
use syntax::ast;
@@ -259,9 +259,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
259259
GenericParamDefKind::Lifetime => {}
260260
GenericParamDefKind::Type(_) => {
261261
if param.index == 0 {
262-
return UnpackedKind::Type(self_ty);
262+
return self_ty.into();
263263
} else if let Some(ref input_types) = opt_input_types {
264-
return UnpackedKind::Type(input_types[param.index as usize - 1]);
264+
return input_types[param.index as usize - 1].into();
265265
}
266266
}
267267
}

src/librustc_typeck/check/method/probe.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use check::FnCtxt;
1717
use hir::def_id::DefId;
1818
use hir::def::Def;
1919
use namespace::Namespace;
20-
use rustc::ty::subst::{UnpackedKind, Subst, Substs};
20+
use rustc::ty::subst::{Subst, Substs};
2121
use rustc::traits::{self, ObligationCause};
2222
use rustc::ty::{self, Ty, ToPolyTraitRef, ToPredicate, TraitRef, TypeFoldable};
2323
use rustc::ty::GenericParamDefKind;
@@ -1391,13 +1391,13 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
13911391
let substs = Substs::for_item(self.tcx, method, |param, _| {
13921392
let i = param.index as usize;
13931393
if i < substs.len() {
1394-
substs[i].unpack()
1394+
substs[i]
13951395
} else {
13961396
match param.kind {
13971397
GenericParamDefKind::Lifetime => {
13981398
// In general, during probe we erase regions. See
13991399
// `impl_self_ty()` for an explanation.
1400-
UnpackedKind::Lifetime(self.tcx.types.re_erased)
1400+
self.tcx.types.re_erased.into()
14011401
}
14021402
GenericParamDefKind::Type(_) => self.var_for_def(self.span, param),
14031403
}
@@ -1415,13 +1415,10 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
14151415
fn fresh_item_substs(&self, def_id: DefId) -> &'tcx Substs<'tcx> {
14161416
Substs::for_item(self.tcx, def_id, |param, _| {
14171417
match param.kind {
1418-
GenericParamDefKind::Lifetime => {
1419-
UnpackedKind::Lifetime(self.tcx.types.re_erased)
1420-
}
1418+
GenericParamDefKind::Lifetime => self.tcx.types.re_erased.into(),
14211419
GenericParamDefKind::Type(_) => {
1422-
UnpackedKind::Type(self.next_ty_var(
1423-
TypeVariableOrigin::SubstitutionPlaceholder(
1424-
self.tcx.def_span(def_id))))
1420+
self.next_ty_var(TypeVariableOrigin::SubstitutionPlaceholder(
1421+
self.tcx.def_span(def_id))).into()
14251422
}
14261423
}
14271424
})

0 commit comments

Comments
 (0)