Skip to content

Commit 365c8c3

Browse files
committed
Remove GenericParamDef::to_type
1 parent 007de2f commit 365c8c3

File tree

5 files changed

+34
-23
lines changed

5 files changed

+34
-23
lines changed

src/librustc/ty/mod.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -743,13 +743,6 @@ pub struct GenericParamDef {
743743
}
744744

745745
impl GenericParamDef {
746-
pub fn to_type(&self) -> TypeParamDef {
747-
match self.kind {
748-
GenericParamDefKind::Type(ty) => ty,
749-
_ => bug!("cannot convert a non-type to a type")
750-
}
751-
}
752-
753746
pub fn to_early_bound_region_data(&self) -> ty::EarlyBoundRegion {
754747
match self.kind {
755748
GenericParamDefKind::Lifetime => {

src/librustc_typeck/astconv.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use middle::resolve_lifetime as rl;
2020
use namespace::Namespace;
2121
use rustc::ty::subst::{Kind, UnpackedKind, Subst, Substs};
2222
use rustc::traits;
23-
use rustc::ty::{self, RegionKind, Ty, TyCtxt, ToPredicate, TypeFoldable};
23+
use rustc::ty::{self, RegionKind, Ty, TyCtxt, GenericParamDefKind, ToPredicate, TypeFoldable};
2424
use rustc::ty::wf::object_region_bounds;
2525
use rustc_target::spec::abi;
2626
use std::slice;
@@ -246,11 +246,13 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
246246

247247
let is_object = self_ty.map_or(false, |ty| ty.sty == TRAIT_OBJECT_DUMMY_SELF);
248248
let default_needs_object_self = |param: &ty::GenericParamDef| {
249-
if is_object && param.to_type().has_default {
250-
if tcx.at(span).type_of(param.def_id).has_self_ty() {
251-
// There is no suitable inference default for a type parameter
252-
// that references self, in an object type.
253-
return true;
249+
if let GenericParamDefKind::Type(ty) = param.kind {
250+
if is_object && ty.has_default {
251+
if tcx.at(span).type_of(param.def_id).has_self_ty() {
252+
// There is no suitable inference default for a type parameter
253+
// that references self, in an object type.
254+
return true;
255+
}
254256
}
255257
}
256258

@@ -272,6 +274,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
272274
return ty;
273275
}
274276

277+
let has_default = match def.kind {
278+
GenericParamDefKind::Type(ty) => ty.has_default,
279+
_ => unreachable!()
280+
};
281+
275282
let i = i - (param_counts.lifetimes + own_self);
276283
if i < num_types_provided {
277284
// A provided type parameter.
@@ -284,7 +291,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
284291
self.ty_infer(span)
285292
};
286293
ty_var
287-
} else if def.to_type().has_default {
294+
} else if has_default {
288295
// No type parameter provided, but a default exists.
289296

290297
// If we are converting an object type, then the

src/librustc_typeck/check/compare_method.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -730,21 +730,22 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
730730
let trait_m_generics = tcx.generics_of(trait_m.def_id);
731731
let impl_m_type_params = impl_m_generics.params.iter().filter_map(|param| {
732732
match param.kind {
733-
GenericParamDefKind::Type(_) => Some(param),
733+
GenericParamDefKind::Type(ty) => Some((param.def_id, ty.synthetic)),
734734
GenericParamDefKind::Lifetime => None,
735735
}
736736
});
737737
let trait_m_type_params = trait_m_generics.params.iter().filter_map(|param| {
738738
match param.kind {
739-
GenericParamDefKind::Type(_) => Some(param),
739+
GenericParamDefKind::Type(ty) => Some((param.def_id, ty.synthetic)),
740740
GenericParamDefKind::Lifetime => None,
741741
}
742742
});
743-
for (impl_ty, trait_ty) in impl_m_type_params.zip(trait_m_type_params) {
744-
if impl_ty.to_type().synthetic != trait_ty.to_type().synthetic {
745-
let impl_node_id = tcx.hir.as_local_node_id(impl_ty.def_id).unwrap();
743+
for ((impl_def_id, impl_synthetic),
744+
(trait_def_id, trait_synthetic)) in impl_m_type_params.zip(trait_m_type_params) {
745+
if impl_synthetic != trait_synthetic {
746+
let impl_node_id = tcx.hir.as_local_node_id(impl_def_id).unwrap();
746747
let impl_span = tcx.hir.span(impl_node_id);
747-
let trait_span = tcx.def_span(trait_ty.def_id);
748+
let trait_span = tcx.def_span(trait_def_id);
748749
let mut err = struct_span_err!(tcx.sess,
749750
impl_span,
750751
E0643,

src/librustc_typeck/check/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ use rustc::middle::region;
9696
use rustc::mir::interpret::{GlobalId};
9797
use rustc::ty::subst::{Kind, Subst, Substs};
9898
use rustc::traits::{self, ObligationCause, ObligationCauseCode, TraitEngine};
99-
use rustc::ty::{self, Ty, TyCtxt, Visibility, ToPredicate};
99+
use rustc::ty::{self, Ty, TyCtxt, GenericParamDefKind, Visibility, ToPredicate};
100100
use rustc::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
101101
use rustc::ty::fold::TypeFoldable;
102102
use rustc::ty::maps::Providers;
@@ -4802,10 +4802,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
48024802
i -= generics.param_counts().lifetimes;
48034803
}
48044804

4805+
let has_default = match def.kind {
4806+
GenericParamDefKind::Type(ty) => ty.has_default,
4807+
_ => unreachable!()
4808+
};
4809+
48054810
if let Some(ast_ty) = types.get(i) {
48064811
// A provided type parameter.
48074812
self.to_ty(ast_ty)
4808-
} else if !infer_types && def.to_type().has_default {
4813+
} else if !infer_types && has_default {
48094814
// No type parameter provided, but a default exists.
48104815
let default = self.tcx.type_of(def.def_id);
48114816
self.normalize_ty(

src/librustc_typeck/check/wfcheck.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,12 @@ fn check_where_clauses<'a, 'gcx, 'fcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>,
371371

372372
let generics = tcx.generics_of(def_id);
373373
let is_our_default = |def: &ty::GenericParamDef| {
374-
def.to_type().has_default && def.index >= generics.parent_count as u32
374+
match def.kind {
375+
GenericParamDefKind::Type(ty) => {
376+
ty.has_default && def.index >= generics.parent_count as u32
377+
}
378+
_ => unreachable!()
379+
}
375380
};
376381

377382
// Check that concrete defaults are well-formed. See test `type-check-defaults.rs`.

0 commit comments

Comments
 (0)