Remove GenericParamDef::to_type
This commit is contained in:
parent
007de2f896
commit
365c8c3704
|
@ -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 => {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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`.
|
||||
|
|
Loading…
Reference in a new issue