about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorvarkor <github@varkor.com>2018-05-11 00:29:38 +0100
committervarkor <github@varkor.com>2018-05-15 14:21:32 +0100
commit365c8c3704fd65fa2dcb112c19eabec44696fea1 (patch)
treefc9b8f3336fb72afb0cd719132fdf62567ddff34 /src
parent007de2f89672559c8fd4593831c3edb93f1983a5 (diff)
downloadrust-365c8c3704fd65fa2dcb112c19eabec44696fea1.tar.gz
rust-365c8c3704fd65fa2dcb112c19eabec44696fea1.zip
Remove GenericParamDef::to_type
Diffstat (limited to 'src')
-rw-r--r--src/librustc/ty/mod.rs7
-rw-r--r--src/librustc_typeck/astconv.rs21
-rw-r--r--src/librustc_typeck/check/compare_method.rs13
-rw-r--r--src/librustc_typeck/check/mod.rs9
-rw-r--r--src/librustc_typeck/check/wfcheck.rs7
5 files changed, 34 insertions, 23 deletions
diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs
index 42aed9940ad..aef8e7f5eea 100644
--- a/src/librustc/ty/mod.rs
+++ b/src/librustc/ty/mod.rs
@@ -743,13 +743,6 @@ pub struct GenericParamDef {
 }
 
 impl GenericParamDef {
-    pub fn to_type(&self) -> TypeParamDef {
-        match self.kind {
-            GenericParamDefKind::Type(ty) => ty,
-            _ => bug!("cannot convert a non-type to a type")
-        }
-    }
-
     pub fn to_early_bound_region_data(&self) -> ty::EarlyBoundRegion {
         match self.kind {
             GenericParamDefKind::Lifetime => {
diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs
index e4d5ce05457..6c64d1ae021 100644
--- a/src/librustc_typeck/astconv.rs
+++ b/src/librustc_typeck/astconv.rs
@@ -20,7 +20,7 @@ use middle::resolve_lifetime as rl;
 use namespace::Namespace;
 use rustc::ty::subst::{Kind, UnpackedKind, Subst, Substs};
 use rustc::traits;
-use rustc::ty::{self, RegionKind, Ty, TyCtxt, ToPredicate, TypeFoldable};
+use rustc::ty::{self, RegionKind, Ty, TyCtxt, GenericParamDefKind, ToPredicate, TypeFoldable};
 use rustc::ty::wf::object_region_bounds;
 use rustc_target::spec::abi;
 use std::slice;
@@ -246,11 +246,13 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
 
         let is_object = self_ty.map_or(false, |ty| ty.sty == TRAIT_OBJECT_DUMMY_SELF);
         let default_needs_object_self = |param: &ty::GenericParamDef| {
-            if is_object && param.to_type().has_default {
-                if tcx.at(span).type_of(param.def_id).has_self_ty() {
-                    // There is no suitable inference default for a type parameter
-                    // that references self, in an object type.
-                    return true;
+            if let GenericParamDefKind::Type(ty) = param.kind {
+                if is_object && ty.has_default {
+                    if tcx.at(span).type_of(param.def_id).has_self_ty() {
+                        // There is no suitable inference default for a type parameter
+                        // that references self, in an object type.
+                        return true;
+                    }
                 }
             }
 
@@ -272,6 +274,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
                 return ty;
             }
 
+            let has_default = match def.kind {
+                GenericParamDefKind::Type(ty) => ty.has_default,
+                _ => unreachable!()
+            };
+
             let i = i - (param_counts.lifetimes + own_self);
             if i < num_types_provided {
                 // A provided type parameter.
@@ -284,7 +291,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
                     self.ty_infer(span)
                 };
                 ty_var
-            } else if def.to_type().has_default {
+            } else if has_default {
                 // No type parameter provided, but a default exists.
 
                 // If we are converting an object type, then the
diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs
index 86913fcadfa..355440769cd 100644
--- a/src/librustc_typeck/check/compare_method.rs
+++ b/src/librustc_typeck/check/compare_method.rs
@@ -730,21 +730,22 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
     let trait_m_generics = tcx.generics_of(trait_m.def_id);
     let impl_m_type_params = impl_m_generics.params.iter().filter_map(|param| {
         match param.kind {
-            GenericParamDefKind::Type(_) => Some(param),
+            GenericParamDefKind::Type(ty) => Some((param.def_id, ty.synthetic)),
             GenericParamDefKind::Lifetime => None,
         }
     });
     let trait_m_type_params = trait_m_generics.params.iter().filter_map(|param| {
         match param.kind {
-            GenericParamDefKind::Type(_) => Some(param),
+            GenericParamDefKind::Type(ty) => Some((param.def_id, ty.synthetic)),
             GenericParamDefKind::Lifetime => None,
         }
     });
-    for (impl_ty, trait_ty) in impl_m_type_params.zip(trait_m_type_params) {
-        if impl_ty.to_type().synthetic != trait_ty.to_type().synthetic {
-            let impl_node_id = tcx.hir.as_local_node_id(impl_ty.def_id).unwrap();
+    for ((impl_def_id, impl_synthetic),
+         (trait_def_id, trait_synthetic)) in impl_m_type_params.zip(trait_m_type_params) {
+        if impl_synthetic != trait_synthetic {
+            let impl_node_id = tcx.hir.as_local_node_id(impl_def_id).unwrap();
             let impl_span = tcx.hir.span(impl_node_id);
-            let trait_span = tcx.def_span(trait_ty.def_id);
+            let trait_span = tcx.def_span(trait_def_id);
             let mut err = struct_span_err!(tcx.sess,
                                            impl_span,
                                            E0643,
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index 256e44a2d6b..a6b072f3213 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -96,7 +96,7 @@ use rustc::middle::region;
 use rustc::mir::interpret::{GlobalId};
 use rustc::ty::subst::{Kind, Subst, Substs};
 use rustc::traits::{self, ObligationCause, ObligationCauseCode, TraitEngine};
-use rustc::ty::{self, Ty, TyCtxt, Visibility, ToPredicate};
+use rustc::ty::{self, Ty, TyCtxt, GenericParamDefKind, Visibility, ToPredicate};
 use rustc::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
 use rustc::ty::fold::TypeFoldable;
 use rustc::ty::maps::Providers;
@@ -4802,10 +4802,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
                 i -= generics.param_counts().lifetimes;
             }
 
+            let has_default = match def.kind {
+                GenericParamDefKind::Type(ty) => ty.has_default,
+                _ => unreachable!()
+            };
+
             if let Some(ast_ty) = types.get(i) {
                 // A provided type parameter.
                 self.to_ty(ast_ty)
-            } else if !infer_types && def.to_type().has_default {
+            } else if !infer_types && has_default {
                 // No type parameter provided, but a default exists.
                 let default = self.tcx.type_of(def.def_id);
                 self.normalize_ty(
diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs
index a96652f953e..a37137c68cb 100644
--- a/src/librustc_typeck/check/wfcheck.rs
+++ b/src/librustc_typeck/check/wfcheck.rs
@@ -371,7 +371,12 @@ fn check_where_clauses<'a, 'gcx, 'fcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>,
 
     let generics = tcx.generics_of(def_id);
     let is_our_default = |def: &ty::GenericParamDef| {
-        def.to_type().has_default && def.index >= generics.parent_count as u32
+        match def.kind {
+            GenericParamDefKind::Type(ty) => {
+                ty.has_default && def.index >= generics.parent_count as u32
+            }
+            _ => unreachable!()
+        }
     };
 
     // Check that concrete defaults are well-formed. See test `type-check-defaults.rs`.