Skip to content

Commit 196b2e0

Browse files
committed
rustc: don't call Kind::from directly, use .into() instead.
1 parent e3df729 commit 196b2e0

File tree

8 files changed

+22
-44
lines changed

8 files changed

+22
-44
lines changed

src/librustc/infer/canonical.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,11 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
256256

257257
CanonicalTyVarKind::Float => self.tcx.mk_float_var(self.next_float_var_id()),
258258
};
259-
Kind::from(ty)
259+
ty.into()
260260
}
261261

262262
CanonicalVarKind::Region => {
263-
Kind::from(self.next_region_var(RegionVariableOrigin::MiscVariable(span)))
263+
self.next_region_var(RegionVariableOrigin::MiscVariable(span)).into()
264264
}
265265
}
266266
}
@@ -555,7 +555,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Canonicalizer<'cx, 'gcx, 'tcx>
555555
opportunistically resolved to {:?}",
556556
vid, r
557557
);
558-
let cvar = self.canonical_var(info, Kind::from(r));
558+
let cvar = self.canonical_var(info, r.into());
559559
self.tcx().mk_region(ty::ReCanonical(cvar))
560560
}
561561

@@ -570,7 +570,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Canonicalizer<'cx, 'gcx, 'tcx>
570570
let info = CanonicalVarInfo {
571571
kind: CanonicalVarKind::Region,
572572
};
573-
let cvar = self.canonical_var(info, Kind::from(r));
573+
let cvar = self.canonical_var(info, r.into());
574574
self.tcx().mk_region(ty::ReCanonical(cvar))
575575
} else {
576576
r
@@ -750,7 +750,7 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
750750
let info = CanonicalVarInfo {
751751
kind: CanonicalVarKind::Ty(ty_kind),
752752
};
753-
let cvar = self.canonical_var(info, Kind::from(ty_var));
753+
let cvar = self.canonical_var(info, ty_var.into());
754754
self.tcx().mk_infer(ty::InferTy::CanonicalTy(cvar))
755755
}
756756
}

src/librustc/traits/select.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use dep_graph::{DepNodeIndex, DepKind};
3737
use hir::def_id::DefId;
3838
use infer;
3939
use infer::{InferCtxt, InferOk, TypeFreshener};
40-
use ty::subst::{Kind, Subst, Substs};
40+
use ty::subst::{Subst, Substs};
4141
use ty::{self, ToPredicate, ToPolyTraitRef, Ty, TyCtxt, TypeFoldable};
4242
use ty::fast_reject;
4343
use ty::relate::TypeRelation;
@@ -3019,7 +3019,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
30193019
// with a potentially unsized trailing field.
30203020
let params = substs_a.iter().enumerate().map(|(i, &k)| {
30213021
if ty_params.contains(i) {
3022-
Kind::from(tcx.types.err)
3022+
tcx.types.err.into()
30233023
} else {
30243024
k
30253025
}

src/librustc/ty/subst.rs

+4-25
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// Type substitutions.
1212

1313
use hir::def_id::DefId;
14-
use ty::{self, Lift, Slice, Region, Ty, TyCtxt};
14+
use ty::{self, Lift, Slice, Ty, TyCtxt};
1515
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
1616

1717
use serialize::{self, Encodable, Encoder, Decodable, Decoder};
@@ -39,7 +39,7 @@ const TAG_MASK: usize = 0b11;
3939
const TYPE_TAG: usize = 0b00;
4040
const REGION_TAG: usize = 0b01;
4141

42-
#[derive(Debug)]
42+
#[derive(Debug, RustcEncodable, RustcDecodable)]
4343
pub enum UnpackedKind<'tcx> {
4444
Lifetime(ty::Region<'tcx>),
4545
Type(Ty<'tcx>),
@@ -142,34 +142,13 @@ impl<'tcx> TypeFoldable<'tcx> for Kind<'tcx> {
142142

143143
impl<'tcx> Encodable for Kind<'tcx> {
144144
fn encode<E: Encoder>(&self, e: &mut E) -> Result<(), E::Error> {
145-
e.emit_enum("Kind", |e| {
146-
match self.unpack() {
147-
UnpackedKind::Lifetime(lt) => {
148-
e.emit_enum_variant("Region", REGION_TAG, 1, |e| {
149-
e.emit_enum_variant_arg(0, |e| lt.encode(e))
150-
})
151-
}
152-
UnpackedKind::Type(ty) => {
153-
e.emit_enum_variant("Ty", TYPE_TAG, 1, |e| {
154-
e.emit_enum_variant_arg(0, |e| ty.encode(e))
155-
})
156-
}
157-
}
158-
})
145+
self.unpack().encode(e)
159146
}
160147
}
161148

162149
impl<'tcx> Decodable for Kind<'tcx> {
163150
fn decode<D: Decoder>(d: &mut D) -> Result<Kind<'tcx>, D::Error> {
164-
d.read_enum("Kind", |d| {
165-
d.read_enum_variant(&["Ty", "Region"], |d, tag| {
166-
match tag {
167-
TYPE_TAG => Ty::decode(d).map(Kind::from),
168-
REGION_TAG => Region::decode(d).map(Kind::from),
169-
_ => Err(d.error("invalid Kind tag"))
170-
}
171-
})
172-
})
151+
Ok(UnpackedKind::decode(d)?.pack())
173152
}
174153
}
175154

src/librustc_codegen_llvm/base.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ use rustc::ty::{self, Ty, TyCtxt};
4343
use rustc::ty::layout::{self, Align, TyLayout, LayoutOf};
4444
use rustc::ty::maps::Providers;
4545
use rustc::dep_graph::{DepNode, DepConstructor};
46-
use rustc::ty::subst::Kind;
4746
use rustc::middle::cstore::{self, LinkMeta, LinkagePreference};
4847
use rustc::middle::exported_symbols;
4948
use rustc::util::common::{time, print_time_passes_entry};
@@ -595,7 +594,7 @@ fn maybe_create_entry_wrapper(cx: &CodegenCx) {
595594
let start_fn = callee::resolve_and_get_fn(
596595
cx,
597596
start_def_id,
598-
cx.tcx.intern_substs(&[Kind::from(main_ret_ty)]),
597+
cx.tcx.intern_substs(&[main_ret_ty.into()]),
599598
);
600599
(start_fn, vec![bx.pointercast(rust_main, Type::i8p(cx).ptr_to()),
601600
arg_argc, arg_argv])

src/librustc_mir/monomorphize/collector.rs

+2-2
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};
199+
use rustc::ty::subst::Substs;
200200
use rustc::ty::{self, TypeFoldable, Ty, TyCtxt, GenericParamDefKind};
201201
use rustc::ty::adjustment::CustomCoerceUnsized;
202202
use rustc::session::config;
@@ -1067,7 +1067,7 @@ impl<'b, 'a, 'v> RootCollector<'b, 'a, 'v> {
10671067
self.tcx,
10681068
ty::ParamEnv::reveal_all(),
10691069
start_def_id,
1070-
self.tcx.intern_substs(&[Kind::from(main_ret_ty)])
1070+
self.tcx.intern_substs(&[main_ret_ty.into()])
10711071
).unwrap();
10721072

10731073
self.output.push(create_fn_mono_item(start_instance));

src/librustc_mir/shim.rs

+2-2
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, Subst, Substs};
16+
use rustc::ty::subst::{Subst, Substs};
1717
use rustc::ty::maps::Providers;
1818

1919
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
@@ -170,7 +170,7 @@ fn build_drop_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
170170
}
171171

172172
let substs = if let Some(ty) = ty {
173-
tcx.mk_substs(iter::once(Kind::from(ty)))
173+
tcx.mk_substs(iter::once(ty.into()))
174174
} else {
175175
Substs::identity_for_item(tcx, def_id)
176176
};

src/librustc_typeck/astconv.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ 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::{Kind, UnpackedKind, Subst, Substs};
21+
use rustc::ty::subst::{UnpackedKind, Subst, Substs};
2222
use rustc::traits;
23-
use rustc::ty::{self, RegionKind, Ty, TyCtxt, ToPredicate, TypeFoldable};
23+
use rustc::ty::{self, Ty, TyCtxt, ToPredicate, TypeFoldable};
2424
use rustc::ty::GenericParamDefKind;
2525
use rustc::ty::wf::object_region_bounds;
2626
use rustc_target::spec::abi;
@@ -1164,7 +1164,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
11641164
// Replace all lifetimes with 'static
11651165
for subst in &mut substs {
11661166
if let UnpackedKind::Lifetime(_) = subst.unpack() {
1167-
*subst = Kind::from(&RegionKind::ReStatic);
1167+
*subst = tcx.types.re_static.into();
11681168
}
11691169
}
11701170
debug!("impl_trait_ty_to_ty: substs from parent = {:?}", substs);
@@ -1173,7 +1173,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
11731173

11741174
// Fill in our own generics with the resolved lifetimes
11751175
assert_eq!(lifetimes.len(), generics.params.len());
1176-
substs.extend(lifetimes.iter().map(|lt| Kind::from(self.ast_region_to_region(lt, None))));
1176+
substs.extend(lifetimes.iter().map(|lt| self.ast_region_to_region(lt, None).into()));
11771177

11781178
debug!("impl_trait_ty_to_ty: final substs = {:?}", substs);
11791179

src/librustc_typeck/check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ use rustc::infer::anon_types::AnonTypeDecl;
9494
use rustc::infer::type_variable::{TypeVariableOrigin};
9595
use rustc::middle::region;
9696
use rustc::mir::interpret::{GlobalId};
97-
use rustc::ty::subst::{Kind, UnpackedKind, Subst, Substs};
97+
use rustc::ty::subst::{UnpackedKind, Subst, Substs};
9898
use rustc::traits::{self, ObligationCause, ObligationCauseCode, TraitEngine};
9999
use rustc::ty::{self, Ty, TyCtxt, GenericParamDefKind, Visibility, ToPredicate};
100100
use rustc::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
@@ -4754,7 +4754,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
47544754
if let GenericParamDefKind::Type(_) = param.kind {
47554755
// Handle Self first, so we can adjust the index to match the AST.
47564756
if has_self && i == 0 {
4757-
return opt_self_ty.map(|ty| Kind::from(ty)).unwrap_or_else(|| {
4757+
return opt_self_ty.map(|ty| ty.into()).unwrap_or_else(|| {
47584758
self.var_for_def(span, param)
47594759
});
47604760
}

0 commit comments

Comments
 (0)