Pull common parameters into GenericParamDef
This leads to a lot of simplifications, as most code doesn't actually need to know about the specific lifetime/type data; rather, it's concerned with properties like name, index and def_id.
This commit is contained in:
parent
5e89312a22
commit
4bed895cab
27 changed files with 263 additions and 266 deletions
|
@ -753,34 +753,23 @@ impl<'a> HashStable<StableHashingContext<'a>> for ty::Generics {
|
|||
}
|
||||
}
|
||||
|
||||
impl_stable_hash_for!(enum ty::GenericParamDef {
|
||||
impl_stable_hash_for!(enum ty::GenericParamDefKind {
|
||||
Lifetime(lt),
|
||||
Type(ty)
|
||||
});
|
||||
|
||||
impl<'a> HashStable<StableHashingContext<'a>>
|
||||
for ty::RegionParamDef {
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
hcx: &mut StableHashingContext<'a>,
|
||||
hasher: &mut StableHasher<W>) {
|
||||
let ty::RegionParamDef {
|
||||
name,
|
||||
def_id,
|
||||
index,
|
||||
pure_wrt_drop
|
||||
} = *self;
|
||||
|
||||
name.hash_stable(hcx, hasher);
|
||||
def_id.hash_stable(hcx, hasher);
|
||||
index.hash_stable(hcx, hasher);
|
||||
pure_wrt_drop.hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
|
||||
impl_stable_hash_for!(struct ty::TypeParamDef {
|
||||
impl_stable_hash_for!(struct ty::GenericParamDef {
|
||||
name,
|
||||
def_id,
|
||||
index,
|
||||
kind
|
||||
});
|
||||
|
||||
impl_stable_hash_for!(struct ty::RegionParamDef {
|
||||
pure_wrt_drop
|
||||
});
|
||||
|
||||
impl_stable_hash_for!(struct ty::TypeParamDef {
|
||||
has_default,
|
||||
object_lifetime_default,
|
||||
pure_wrt_drop,
|
||||
|
|
|
@ -14,7 +14,7 @@ use infer::outlives::free_region_map::FreeRegionRelations;
|
|||
use rustc_data_structures::fx::FxHashMap;
|
||||
use syntax::ast;
|
||||
use traits::{self, PredicateObligation};
|
||||
use ty::{self, Ty, TyCtxt, GenericParamDef};
|
||||
use ty::{self, Ty, TyCtxt, GenericParamDefKind};
|
||||
use ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder};
|
||||
use ty::outlives::Component;
|
||||
use ty::subst::{Kind, Substs, UnpackedKind};
|
||||
|
@ -313,16 +313,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
// `['a]` for the first impl trait and `'b` for the
|
||||
// second.
|
||||
let mut least_region = None;
|
||||
for region_def in abstract_type_generics.params.iter().filter_map(|param| {
|
||||
if let GenericParamDef::Lifetime(lt) = param {
|
||||
Some(lt)
|
||||
for index in abstract_type_generics.params.iter().filter_map(|param| {
|
||||
if let GenericParamDefKind::Lifetime(_) = param.kind {
|
||||
// Find the index of this region in the list of substitutions.
|
||||
Some(param.index as usize)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}) {
|
||||
// Find the index of this region in the list of substitutions.
|
||||
let index = region_def.index as usize;
|
||||
|
||||
// Get the value supplied for this region from the substs.
|
||||
let subst_arg = anon_defn.substs.region_at(index);
|
||||
|
||||
|
|
|
@ -909,7 +909,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
/// region parameter definition.
|
||||
pub fn region_var_for_def(&self,
|
||||
span: Span,
|
||||
def: &ty::RegionParamDef)
|
||||
def: &ty::GenericParamDef)
|
||||
-> ty::Region<'tcx> {
|
||||
self.next_region_var(EarlyBoundRegion(span, def.name))
|
||||
}
|
||||
|
@ -924,7 +924,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
/// as the substitutions for the default, `(T, U)`.
|
||||
pub fn type_var_for_def(&self,
|
||||
span: Span,
|
||||
def: &ty::TypeParamDef)
|
||||
def: &ty::GenericParamDef)
|
||||
-> Ty<'tcx> {
|
||||
let ty_var_id = self.type_variables
|
||||
.borrow_mut()
|
||||
|
|
|
@ -20,7 +20,7 @@ use hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
|
|||
use hir::map::Map;
|
||||
use hir::ItemLocalId;
|
||||
use hir::LifetimeName;
|
||||
use ty::{self, TyCtxt, GenericParamDef};
|
||||
use ty::{self, TyCtxt, GenericParamDefKind};
|
||||
|
||||
use errors::DiagnosticBuilder;
|
||||
use rustc::lint;
|
||||
|
@ -1662,9 +1662,11 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
.params
|
||||
.iter()
|
||||
.filter_map(|param| {
|
||||
match *param {
|
||||
GenericParamDef::Type(ty) => Some(ty.object_lifetime_default),
|
||||
GenericParamDef::Lifetime(_) => None,
|
||||
match param.kind {
|
||||
GenericParamDefKind::Type(ty) => {
|
||||
Some(ty.object_lifetime_default)
|
||||
}
|
||||
GenericParamDefKind::Lifetime(_) => None,
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
|
|
|
@ -35,7 +35,8 @@ use infer::type_variable::TypeVariableOrigin;
|
|||
use std::fmt;
|
||||
use syntax::ast;
|
||||
use session::DiagnosticMessageId;
|
||||
use ty::{self, AdtKind, ToPredicate, ToPolyTraitRef, Ty, TyCtxt, TypeFoldable, GenericParamDef};
|
||||
use ty::{self, AdtKind, ToPredicate, ToPolyTraitRef, Ty, TyCtxt, TypeFoldable};
|
||||
use ty::GenericParamDefKind;
|
||||
use ty::error::ExpectedFound;
|
||||
use ty::fast_reject;
|
||||
use ty::fold::TypeFolder;
|
||||
|
@ -378,10 +379,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
flags.push(("_Self".to_string(), Some(self.tcx.type_of(def.did).to_string())));
|
||||
}
|
||||
|
||||
for param in generics.params.iter().filter_map(|param| {
|
||||
match *param {
|
||||
GenericParamDef::Type(ty) => Some(ty),
|
||||
GenericParamDef::Lifetime(_) => None,
|
||||
for param in generics.params.iter().filter(|param| {
|
||||
match param.kind {
|
||||
GenericParamDefKind::Type(_) => true,
|
||||
GenericParamDefKind::Lifetime(_) => false,
|
||||
}
|
||||
}) {
|
||||
let name = param.name.to_string();
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
use fmt_macros::{Parser, Piece, Position};
|
||||
|
||||
use hir::def_id::DefId;
|
||||
use ty::{self, TyCtxt, GenericParamDef};
|
||||
use ty::{self, TyCtxt, GenericParamDefKind};
|
||||
use util::common::ErrorReported;
|
||||
use util::nodemap::FxHashMap;
|
||||
|
||||
|
@ -254,9 +254,9 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedFormatString {
|
|||
Position::ArgumentNamed(s) if s == name => (),
|
||||
// So is `{A}` if A is a type parameter
|
||||
Position::ArgumentNamed(s) => match generics.params.iter().find(|param| {
|
||||
match *param {
|
||||
GenericParamDef::Type(ty) => ty.name == s,
|
||||
GenericParamDef::Lifetime(_) => false,
|
||||
match param.kind {
|
||||
GenericParamDefKind::Type(_) => param.name == s,
|
||||
GenericParamDefKind::Lifetime(_) => false,
|
||||
}
|
||||
}) {
|
||||
Some(_) => (),
|
||||
|
@ -291,11 +291,12 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedFormatString {
|
|||
let trait_str = tcx.item_path_str(trait_ref.def_id);
|
||||
let generics = tcx.generics_of(trait_ref.def_id);
|
||||
let generic_map = generics.params.iter().filter_map(|param| {
|
||||
match *param {
|
||||
GenericParamDef::Type(ty) => {
|
||||
Some((ty.name.to_string(), trait_ref.substs.type_for_def(&ty).to_string()))
|
||||
match param.kind {
|
||||
GenericParamDefKind::Type(_) => {
|
||||
Some((param.name.to_string(),
|
||||
trait_ref.substs.type_for_def(¶m).to_string()))
|
||||
},
|
||||
GenericParamDef::Lifetime(_) => None
|
||||
GenericParamDefKind::Lifetime(_) => None
|
||||
}
|
||||
}).collect::<FxHashMap<String, String>>();
|
||||
|
||||
|
|
|
@ -213,7 +213,7 @@ impl<'cx, 'gcx, 'tcx> Elaborator<'cx, 'gcx, 'tcx> {
|
|||
},
|
||||
|
||||
Component::Param(p) => {
|
||||
let ty = tcx.mk_param(p.idx, p.name);
|
||||
let ty = tcx.mk_ty_param(p.idx, p.name);
|
||||
Some(ty::Predicate::TypeOutlives(
|
||||
ty::Binder::dummy(ty::OutlivesPredicate(ty, r_min))))
|
||||
},
|
||||
|
|
|
@ -2457,18 +2457,18 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
self.mk_ty(TyInfer(it))
|
||||
}
|
||||
|
||||
pub fn mk_param(self,
|
||||
pub fn mk_ty_param(self,
|
||||
index: u32,
|
||||
name: InternedString) -> Ty<'tcx> {
|
||||
self.mk_ty(TyParam(ParamTy { idx: index, name: name }))
|
||||
}
|
||||
|
||||
pub fn mk_self_type(self) -> Ty<'tcx> {
|
||||
self.mk_param(0, keywords::SelfType.name().as_interned_str())
|
||||
self.mk_ty_param(0, keywords::SelfType.name().as_interned_str())
|
||||
}
|
||||
|
||||
pub fn mk_param_from_def(self, def: &ty::TypeParamDef) -> Ty<'tcx> {
|
||||
self.mk_param(def.index, def.name)
|
||||
pub fn mk_ty_param_from_def(self, def: &ty::GenericParamDef) -> Ty<'tcx> {
|
||||
self.mk_ty_param(def.index, def.name)
|
||||
}
|
||||
|
||||
pub fn mk_anon(self, def_id: DefId, substs: &'tcx Substs<'tcx>) -> Ty<'tcx> {
|
||||
|
|
|
@ -709,11 +709,8 @@ pub enum IntVarValue {
|
|||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub struct FloatVarValue(pub ast::FloatTy);
|
||||
|
||||
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
|
||||
#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)]
|
||||
pub struct TypeParamDef {
|
||||
pub name: InternedString,
|
||||
pub def_id: DefId,
|
||||
pub index: u32,
|
||||
pub has_default: bool,
|
||||
pub object_lifetime_default: ObjectLifetimeDefault,
|
||||
|
||||
|
@ -725,32 +722,14 @@ pub struct TypeParamDef {
|
|||
pub synthetic: Option<hir::SyntheticTyParamKind>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
|
||||
#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)]
|
||||
pub struct RegionParamDef {
|
||||
pub name: InternedString,
|
||||
pub def_id: DefId,
|
||||
pub index: u32,
|
||||
|
||||
/// `pure_wrt_drop`, set by the (unsafe) `#[may_dangle]` attribute
|
||||
/// on generic parameter `'a`, asserts data of lifetime `'a`
|
||||
/// won't be accessed during the parent type's `Drop` impl.
|
||||
pub pure_wrt_drop: bool,
|
||||
}
|
||||
|
||||
impl RegionParamDef {
|
||||
pub fn to_early_bound_region_data(&self) -> ty::EarlyBoundRegion {
|
||||
ty::EarlyBoundRegion {
|
||||
def_id: self.def_id,
|
||||
index: self.index,
|
||||
name: self.name,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_bound_region(&self) -> ty::BoundRegion {
|
||||
self.to_early_bound_region_data().to_bound_region()
|
||||
}
|
||||
}
|
||||
|
||||
impl ty::EarlyBoundRegion {
|
||||
pub fn to_bound_region(&self) -> ty::BoundRegion {
|
||||
ty::BoundRegion::BrNamed(self.def_id, self.name)
|
||||
|
@ -758,23 +737,53 @@ impl ty::EarlyBoundRegion {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
|
||||
pub enum GenericParamDef {
|
||||
pub enum GenericParamDefKind {
|
||||
Lifetime(RegionParamDef),
|
||||
Type(TypeParamDef),
|
||||
}
|
||||
|
||||
#[derive(Clone, RustcEncodable, RustcDecodable)]
|
||||
pub struct GenericParamDef {
|
||||
pub name: InternedString,
|
||||
pub def_id: DefId,
|
||||
pub index: u32,
|
||||
pub kind: GenericParamDefKind,
|
||||
}
|
||||
|
||||
impl GenericParamDef {
|
||||
pub fn index(&self) -> u32 {
|
||||
match self {
|
||||
GenericParamDef::Lifetime(lt) => lt.index,
|
||||
GenericParamDef::Type(ty) => ty.index,
|
||||
pub fn to_lifetime(&self) -> RegionParamDef {
|
||||
match self.kind {
|
||||
GenericParamDefKind::Lifetime(lt) => lt,
|
||||
_ => bug!("cannot convert a non-lifetime to a lifetime")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn def_id(&self) -> DefId {
|
||||
match self {
|
||||
GenericParamDef::Lifetime(lt) => lt.def_id,
|
||||
GenericParamDef::Type(ty) => ty.def_id,
|
||||
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(_) => {
|
||||
ty::EarlyBoundRegion {
|
||||
def_id: self.def_id,
|
||||
index: self.index,
|
||||
name: self.name,
|
||||
}
|
||||
}
|
||||
_ => bug!("cannot convert a non-lifetime parameter def to an early bound region")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_bound_region(&self) -> ty::BoundRegion {
|
||||
match self.kind {
|
||||
GenericParamDefKind::Lifetime(_) => {
|
||||
self.to_early_bound_region_data().to_bound_region()
|
||||
}
|
||||
_ => bug!("cannot convert a non-lifetime parameter def to an early bound region")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -817,9 +826,9 @@ impl<'a, 'gcx, 'tcx> Generics {
|
|||
};
|
||||
|
||||
for param in self.params.iter() {
|
||||
match param {
|
||||
GenericParamDef::Lifetime(_) => param_counts.lifetimes += 1,
|
||||
GenericParamDef::Type(_) => param_counts.types += 1,
|
||||
match param.kind {
|
||||
GenericParamDefKind::Lifetime(_) => param_counts.lifetimes += 1,
|
||||
GenericParamDefKind::Type(_) => param_counts.types += 1,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -828,9 +837,9 @@ impl<'a, 'gcx, 'tcx> Generics {
|
|||
|
||||
pub fn requires_monomorphization(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> bool {
|
||||
if self.params.iter().any(|param| {
|
||||
match *param {
|
||||
GenericParamDef::Type(_) => true,
|
||||
GenericParamDef::Lifetime(_) => false
|
||||
match param.kind {
|
||||
GenericParamDefKind::Type(_) => true,
|
||||
GenericParamDefKind::Lifetime(_) => false
|
||||
}
|
||||
}) {
|
||||
return true;
|
||||
|
@ -846,11 +855,12 @@ impl<'a, 'gcx, 'tcx> Generics {
|
|||
pub fn region_param(&'tcx self,
|
||||
param: &EarlyBoundRegion,
|
||||
tcx: TyCtxt<'a, 'gcx, 'tcx>)
|
||||
-> &'tcx RegionParamDef
|
||||
-> &'tcx GenericParamDef
|
||||
{
|
||||
if let Some(index) = param.index.checked_sub(self.parent_count as u32) {
|
||||
match self.params[index as usize] {
|
||||
ty::GenericParamDef::Lifetime(ref lt) => lt,
|
||||
let ref param = self.params[index as usize];
|
||||
match param.kind {
|
||||
ty::GenericParamDefKind::Lifetime(_) => param,
|
||||
_ => bug!("expected region parameter, but found another generic parameter")
|
||||
}
|
||||
} else {
|
||||
|
@ -863,7 +873,7 @@ impl<'a, 'gcx, 'tcx> Generics {
|
|||
pub fn type_param(&'tcx self,
|
||||
param: &ParamTy,
|
||||
tcx: TyCtxt<'a, 'gcx, 'tcx>)
|
||||
-> &TypeParamDef {
|
||||
-> &'tcx GenericParamDef {
|
||||
if let Some(index) = param.idx.checked_sub(self.parent_count as u32) {
|
||||
// non-Self type parameters are always offset by exactly
|
||||
// `self.regions.len()`. In the absence of a Self, this is obvious,
|
||||
|
@ -899,14 +909,16 @@ impl<'a, 'gcx, 'tcx> Generics {
|
|||
|
||||
if let Some(_) = (index as usize).checked_sub(type_param_offset) {
|
||||
assert!(!is_separated_self, "found a Self after type_param_offset");
|
||||
match self.params[index as usize] {
|
||||
ty::GenericParamDef::Type(ref ty) => ty,
|
||||
let ref param = self.params[index as usize];
|
||||
match param.kind {
|
||||
ty::GenericParamDefKind::Type(_) => param,
|
||||
_ => bug!("expected type parameter, but found another generic parameter")
|
||||
}
|
||||
} else {
|
||||
assert!(is_separated_self, "non-Self param before type_param_offset");
|
||||
match self.params[type_param_offset] {
|
||||
ty::GenericParamDef::Type(ref ty) => ty,
|
||||
let ref param = self.params[type_param_offset];
|
||||
match param.kind {
|
||||
ty::GenericParamDefKind::Type(_) => param,
|
||||
_ => bug!("expected type parameter, but found another generic parameter")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -928,12 +928,12 @@ impl<'a, 'gcx, 'tcx> ParamTy {
|
|||
ParamTy::new(0, keywords::SelfType.name().as_interned_str())
|
||||
}
|
||||
|
||||
pub fn for_def(def: &ty::TypeParamDef) -> ParamTy {
|
||||
pub fn for_def(def: &ty::GenericParamDef) -> ParamTy {
|
||||
ParamTy::new(def.index, def.name)
|
||||
}
|
||||
|
||||
pub fn to_ty(self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
|
||||
tcx.mk_param(self.idx, self.name)
|
||||
tcx.mk_ty_param(self.idx, self.name)
|
||||
}
|
||||
|
||||
pub fn is_self(&self) -> bool {
|
||||
|
|
|
@ -183,7 +183,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
|
|||
-> &'tcx Substs<'tcx> {
|
||||
Substs::for_item(tcx, def_id, |def, _| {
|
||||
tcx.mk_region(ty::ReEarlyBound(def.to_early_bound_region_data()))
|
||||
}, |def, _| tcx.mk_param_from_def(def))
|
||||
}, |def, _| tcx.mk_ty_param_from_def(def))
|
||||
}
|
||||
|
||||
/// Creates a Substs for generic parameter definitions,
|
||||
|
@ -196,8 +196,8 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
|
|||
mut mk_region: FR,
|
||||
mut mk_type: FT)
|
||||
-> &'tcx Substs<'tcx>
|
||||
where FR: FnMut(&ty::RegionParamDef, &[Kind<'tcx>]) -> ty::Region<'tcx>,
|
||||
FT: FnMut(&ty::TypeParamDef, &[Kind<'tcx>]) -> Ty<'tcx> {
|
||||
where FR: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> ty::Region<'tcx>,
|
||||
FT: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Ty<'tcx> {
|
||||
let defs = tcx.generics_of(def_id);
|
||||
let mut substs = Vec::with_capacity(defs.count());
|
||||
Substs::fill_item(&mut substs, tcx, defs, &mut mk_region, &mut mk_type);
|
||||
|
@ -210,8 +210,8 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
|
|||
mut mk_region: FR,
|
||||
mut mk_type: FT)
|
||||
-> &'tcx Substs<'tcx>
|
||||
where FR: FnMut(&ty::RegionParamDef, &[Kind<'tcx>]) -> ty::Region<'tcx>,
|
||||
FT: FnMut(&ty::TypeParamDef, &[Kind<'tcx>]) -> Ty<'tcx>
|
||||
where FR: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> ty::Region<'tcx>,
|
||||
FT: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Ty<'tcx>
|
||||
{
|
||||
let defs = tcx.generics_of(def_id);
|
||||
let mut result = Vec::with_capacity(defs.count());
|
||||
|
@ -225,8 +225,8 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
|
|||
defs: &ty::Generics,
|
||||
mk_region: &mut FR,
|
||||
mk_type: &mut FT)
|
||||
where FR: FnMut(&ty::RegionParamDef, &[Kind<'tcx>]) -> ty::Region<'tcx>,
|
||||
FT: FnMut(&ty::TypeParamDef, &[Kind<'tcx>]) -> Ty<'tcx> {
|
||||
where FR: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> ty::Region<'tcx>,
|
||||
FT: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Ty<'tcx> {
|
||||
|
||||
if let Some(def_id) = defs.parent {
|
||||
let parent_defs = tcx.generics_of(def_id);
|
||||
|
@ -239,15 +239,15 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
|
|||
defs: &ty::Generics,
|
||||
mk_region: &mut FR,
|
||||
mk_type: &mut FT)
|
||||
where FR: FnMut(&ty::RegionParamDef, &[Kind<'tcx>]) -> ty::Region<'tcx>,
|
||||
FT: FnMut(&ty::TypeParamDef, &[Kind<'tcx>]) -> Ty<'tcx> {
|
||||
for def in &defs.params {
|
||||
let param = match def {
|
||||
ty::GenericParamDef::Lifetime(ref lt) => mk_region(lt, substs).into(),
|
||||
ty::GenericParamDef::Type(ref ty) => mk_type(ty, substs).into(),
|
||||
where FR: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> ty::Region<'tcx>,
|
||||
FT: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Ty<'tcx> {
|
||||
for param in &defs.params {
|
||||
let kind = match param.kind {
|
||||
ty::GenericParamDefKind::Lifetime(_) => mk_region(param, substs).into(),
|
||||
ty::GenericParamDefKind::Type(_) => mk_type(param, substs).into(),
|
||||
};
|
||||
assert_eq!(def.index() as usize, substs.len());
|
||||
substs.push(param);
|
||||
assert_eq!(param.index as usize, substs.len());
|
||||
substs.push(kind);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -296,12 +296,12 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn type_for_def(&self, ty_param_def: &ty::TypeParamDef) -> Ty<'tcx> {
|
||||
pub fn type_for_def(&self, ty_param_def: &ty::GenericParamDef) -> Ty<'tcx> {
|
||||
self.type_at(ty_param_def.index as usize)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn region_for_def(&self, def: &ty::RegionParamDef) -> ty::Region<'tcx> {
|
||||
pub fn region_for_def(&self, def: &ty::GenericParamDef) -> ty::Region<'tcx> {
|
||||
self.region_at(def.index as usize)
|
||||
}
|
||||
|
||||
|
|
|
@ -505,12 +505,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
.filter(|&(_, &k)| {
|
||||
match k.unpack() {
|
||||
UnpackedKind::Lifetime(&ty::RegionKind::ReEarlyBound(ref ebr)) => {
|
||||
!impl_generics.region_param(ebr, self).pure_wrt_drop
|
||||
!impl_generics.region_param(ebr, self).to_lifetime().pure_wrt_drop
|
||||
}
|
||||
UnpackedKind::Type(&ty::TyS {
|
||||
sty: ty::TypeVariants::TyParam(ref pt), ..
|
||||
}) => {
|
||||
!impl_generics.type_param(pt, self).pure_wrt_drop
|
||||
!impl_generics.type_param(pt, self).to_type().pure_wrt_drop
|
||||
}
|
||||
UnpackedKind::Lifetime(_) | UnpackedKind::Type(_) => {
|
||||
// not a type or region param - this should be reported
|
||||
|
|
|
@ -19,7 +19,7 @@ use ty::{TyError, TyStr, TyArray, TySlice, TyFloat, TyFnDef, TyFnPtr};
|
|||
use ty::{TyParam, TyRawPtr, TyRef, TyNever, TyTuple};
|
||||
use ty::{TyClosure, TyGenerator, TyGeneratorWitness, TyForeign, TyProjection, TyAnon};
|
||||
use ty::{TyDynamic, TyInt, TyUint, TyInfer};
|
||||
use ty::{self, Ty, TyCtxt, TypeFoldable, GenericParamCount, GenericParamDef};
|
||||
use ty::{self, Ty, TyCtxt, TypeFoldable, GenericParamCount, GenericParamDefKind};
|
||||
use util::nodemap::FxHashSet;
|
||||
|
||||
use std::cell::Cell;
|
||||
|
@ -338,20 +338,21 @@ impl PrintContext {
|
|||
if !verbose {
|
||||
let mut type_params =
|
||||
generics.params.iter().rev().filter_map(|param| {
|
||||
match *param {
|
||||
GenericParamDef::Type(ty) => Some(ty),
|
||||
GenericParamDef::Lifetime(_) => None,
|
||||
match param.kind {
|
||||
GenericParamDefKind::Type(ty) => Some((param.def_id, ty.has_default)),
|
||||
GenericParamDefKind::Lifetime(_) => None,
|
||||
}
|
||||
});
|
||||
if let Some(last_ty) = type_params.next() {
|
||||
if last_ty.has_default {
|
||||
let (_, has_default) = last_ty;
|
||||
if has_default {
|
||||
if let Some(substs) = tcx.lift(&substs) {
|
||||
let mut tps = substs.types().rev().skip(child_types);
|
||||
let zipped = iter::once((last_ty, tps.next().unwrap()))
|
||||
.chain(type_params.zip(tps));
|
||||
for (ty, actual) in zipped {
|
||||
if !ty.has_default ||
|
||||
tcx.type_of(ty.def_id).subst(tcx, substs) != actual {
|
||||
let mut types = substs.types().rev().skip(child_types);
|
||||
let zipped = iter::once((last_ty, types.next().unwrap()))
|
||||
.chain(type_params.zip(types));
|
||||
for ((def_id, has_default), actual) in zipped {
|
||||
if !has_default ||
|
||||
tcx.type_of(def_id).subst(tcx, substs) != actual {
|
||||
break;
|
||||
}
|
||||
num_supplied_defaults += 1;
|
||||
|
@ -600,18 +601,14 @@ define_print! {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for ty::TypeParamDef {
|
||||
impl fmt::Debug for ty::GenericParamDef {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "TypeParamDef({}, {:?}, {})",
|
||||
self.name,
|
||||
self.def_id,
|
||||
self.index)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for ty::RegionParamDef {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "RegionParamDef({}, {:?}, {})",
|
||||
let type_name = match self.kind {
|
||||
ty::GenericParamDefKind::Lifetime(_) => "Region",
|
||||
ty::GenericParamDefKind::Type(_) => "Type",
|
||||
};
|
||||
write!(f, "{}({}, {:?}, {})",
|
||||
type_name,
|
||||
self.name,
|
||||
self.def_id,
|
||||
self.index)
|
||||
|
|
|
@ -308,7 +308,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
|
|||
|
||||
pub fn t_param(&self, index: u32) -> Ty<'tcx> {
|
||||
let name = format!("T{}", index);
|
||||
self.infcx.tcx.mk_param(index, Symbol::intern(&name).as_interned_str())
|
||||
self.infcx.tcx.mk_ty_param(index, Symbol::intern(&name).as_interned_str())
|
||||
}
|
||||
|
||||
pub fn re_early_bound(&self, index: u32, name: &'static str) -> ty::Region<'tcx> {
|
||||
|
|
|
@ -27,7 +27,7 @@ use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
|
|||
use rustc::hir::itemlikevisit::DeepVisitor;
|
||||
use rustc::lint;
|
||||
use rustc::middle::privacy::{AccessLevel, AccessLevels};
|
||||
use rustc::ty::{self, TyCtxt, Ty, TypeFoldable, GenericParamDef};
|
||||
use rustc::ty::{self, TyCtxt, Ty, TypeFoldable, GenericParamDefKind};
|
||||
use rustc::ty::fold::TypeVisitor;
|
||||
use rustc::ty::maps::Providers;
|
||||
use rustc::ty::subst::UnpackedKind;
|
||||
|
@ -399,14 +399,14 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
|
|||
|
||||
impl<'b, 'a, 'tcx> ReachEverythingInTheInterfaceVisitor<'b, 'a, 'tcx> {
|
||||
fn generics(&mut self) -> &mut Self {
|
||||
for def in self.ev.tcx.generics_of(self.item_def_id).params.iter() {
|
||||
match def {
|
||||
GenericParamDef::Type(ty) => {
|
||||
for param in self.ev.tcx.generics_of(self.item_def_id).params.iter() {
|
||||
match param.kind {
|
||||
GenericParamDefKind::Type(ty) => {
|
||||
if ty.has_default {
|
||||
self.ev.tcx.type_of(ty.def_id).visit_with(self);
|
||||
self.ev.tcx.type_of(param.def_id).visit_with(self);
|
||||
}
|
||||
}
|
||||
GenericParamDef::Lifetime(_) => {}
|
||||
GenericParamDefKind::Lifetime(_) => {}
|
||||
}
|
||||
}
|
||||
self
|
||||
|
@ -1340,14 +1340,14 @@ struct SearchInterfaceForPrivateItemsVisitor<'a, 'tcx: 'a> {
|
|||
|
||||
impl<'a, 'tcx: 'a> SearchInterfaceForPrivateItemsVisitor<'a, 'tcx> {
|
||||
fn generics(&mut self) -> &mut Self {
|
||||
for def in self.tcx.generics_of(self.item_def_id).params.iter() {
|
||||
match def {
|
||||
GenericParamDef::Type(ty) => {
|
||||
for param in self.tcx.generics_of(self.item_def_id).params.iter() {
|
||||
match param.kind {
|
||||
GenericParamDefKind::Type(ty) => {
|
||||
if ty.has_default {
|
||||
self.tcx.type_of(ty.def_id).visit_with(self);
|
||||
self.tcx.type_of(param.def_id).visit_with(self);
|
||||
}
|
||||
}
|
||||
GenericParamDef::Lifetime(_) => {}
|
||||
GenericParamDefKind::Lifetime(_) => {}
|
||||
}
|
||||
}
|
||||
self
|
||||
|
|
|
@ -13,7 +13,7 @@ use rustc::hir::def_id::DefId;
|
|||
use rustc::traits::{FulfillmentContext, Normalized, ObligationCause};
|
||||
use rustc::traits::query::{CanonicalTyGoal, NoSolution};
|
||||
use rustc::traits::query::dropck_outlives::{DtorckConstraint, DropckOutlivesResult};
|
||||
use rustc::ty::{self, ParamEnvAnd, Ty, TyCtxt, GenericParamDef};
|
||||
use rustc::ty::{self, ParamEnvAnd, Ty, TyCtxt};
|
||||
use rustc::ty::subst::Subst;
|
||||
use rustc::util::nodemap::FxHashSet;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
|
@ -278,13 +278,11 @@ crate fn adt_dtorck_constraint<'a, 'tcx>(
|
|||
debug!("dtorck_constraint: {:?}", def);
|
||||
|
||||
if def.is_phantom_data() {
|
||||
let type_param = match tcx.generics_of(def_id).params[0] {
|
||||
GenericParamDef::Type(ty) => ty,
|
||||
GenericParamDef::Lifetime(_) => unreachable!(),
|
||||
};
|
||||
// The first generic parameter here is guaranteed to be a type because it's `PhantomData`.
|
||||
let param = &tcx.generics_of(def_id).params[0];
|
||||
let result = DtorckConstraint {
|
||||
outlives: vec![],
|
||||
dtorck_types: vec![tcx.mk_param_from_def(&type_param)],
|
||||
dtorck_types: vec![tcx.mk_ty_param_from_def(param)],
|
||||
overflows: vec![],
|
||||
};
|
||||
debug!("dtorck_constraint: {:?} => {:?}", def, result);
|
||||
|
|
|
@ -26,7 +26,6 @@ use llvm::debuginfo::{DIFile, DIType, DIScope, DIBuilderRef, DISubprogram, DIArr
|
|||
use rustc::hir::TransFnAttrFlags;
|
||||
use rustc::hir::def_id::{DefId, CrateNum};
|
||||
use rustc::ty::subst::{Substs, UnpackedKind};
|
||||
use rustc::ty::GenericParamDef;
|
||||
|
||||
use abi::Abi;
|
||||
use common::CodegenCx;
|
||||
|
@ -425,12 +424,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
|
|||
let mut names = generics.parent.map_or(vec![], |def_id| {
|
||||
get_parameter_names(cx, cx.tcx.generics_of(def_id))
|
||||
});
|
||||
names.extend(generics.params.iter().map(|param| {
|
||||
match param {
|
||||
GenericParamDef::Lifetime(lt) => lt.name,
|
||||
GenericParamDef::Type(ty) => ty.name,
|
||||
}
|
||||
}));
|
||||
names.extend(generics.params.iter().map(|param| param.name));
|
||||
names
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ pub trait AstConv<'gcx, 'tcx> {
|
|||
-> ty::GenericPredicates<'tcx>;
|
||||
|
||||
/// What lifetime should we use when a lifetime is omitted (and not elided)?
|
||||
fn re_infer(&self, span: Span, _def: Option<&ty::RegionParamDef>)
|
||||
fn re_infer(&self, span: Span, _def: Option<&ty::GenericParamDef>)
|
||||
-> Option<ty::Region<'tcx>>;
|
||||
|
||||
/// What type should we use when a type is omitted?
|
||||
|
@ -51,7 +51,7 @@ pub trait AstConv<'gcx, 'tcx> {
|
|||
|
||||
/// Same as ty_infer, but with a known type parameter definition.
|
||||
fn ty_infer_for_def(&self,
|
||||
_def: &ty::TypeParamDef,
|
||||
_def: &ty::GenericParamDef,
|
||||
span: Span) -> Ty<'tcx> {
|
||||
self.ty_infer(span)
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ const TRAIT_OBJECT_DUMMY_SELF: ty::TypeVariants<'static> = ty::TyInfer(ty::Fresh
|
|||
impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
||||
pub fn ast_region_to_region(&self,
|
||||
lifetime: &hir::Lifetime,
|
||||
def: Option<&ty::RegionParamDef>)
|
||||
def: Option<&ty::GenericParamDef>)
|
||||
-> ty::Region<'tcx>
|
||||
{
|
||||
let tcx = self.tcx();
|
||||
|
@ -228,7 +228,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
|||
let type_params_without_defaults = {
|
||||
let mut count = 0;
|
||||
for param in decl_generics.params.iter() {
|
||||
if let ty::GenericParamDef::Type(ty) = param {
|
||||
if let ty::GenericParamDefKind::Type(ty) = param.kind {
|
||||
if !ty.has_default {
|
||||
count += 1
|
||||
}
|
||||
|
@ -245,9 +245,9 @@ 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 = |p: &ty::TypeParamDef| {
|
||||
if is_object && p.has_default {
|
||||
if tcx.at(span).type_of(p.def_id).has_self_ty() {
|
||||
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;
|
||||
|
@ -284,7 +284,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
|||
self.ty_infer(span)
|
||||
};
|
||||
ty_var
|
||||
} else if def.has_default {
|
||||
} else if def.to_type().has_default {
|
||||
// No type parameter provided, but a default exists.
|
||||
|
||||
// If we are converting an object type, then the
|
||||
|
@ -998,7 +998,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
|||
let item_def_id = tcx.hir.local_def_id(item_id);
|
||||
let generics = tcx.generics_of(item_def_id);
|
||||
let index = generics.param_def_id_to_index[&tcx.hir.local_def_id(node_id)];
|
||||
tcx.mk_param(index, tcx.hir.name(node_id).as_interned_str())
|
||||
tcx.mk_ty_param(index, tcx.hir.name(node_id).as_interned_str())
|
||||
}
|
||||
Def::SelfTy(_, Some(def_id)) => {
|
||||
// Self in impl (we know the concrete type).
|
||||
|
@ -1146,7 +1146,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
|||
&mut substs, tcx, parent_generics,
|
||||
&mut |def, _| tcx.mk_region(
|
||||
ty::ReEarlyBound(def.to_early_bound_region_data())),
|
||||
&mut |def, _| tcx.mk_param_from_def(def)
|
||||
&mut |def, _| tcx.mk_ty_param_from_def(def)
|
||||
);
|
||||
|
||||
// Replace all lifetimes with 'static
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
use rustc::hir::{self, ImplItemKind, TraitItemKind};
|
||||
use rustc::infer::{self, InferOk};
|
||||
use rustc::ty::{self, TyCtxt, GenericParamDef};
|
||||
use rustc::ty::{self, TyCtxt, GenericParamDefKind};
|
||||
use rustc::ty::util::ExplicitSelf;
|
||||
use rustc::traits::{self, ObligationCause, ObligationCauseCode, Reveal};
|
||||
use rustc::ty::error::{ExpectedFound, TypeError};
|
||||
|
@ -729,19 +729,19 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
let impl_m_generics = tcx.generics_of(impl_m.def_id);
|
||||
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 {
|
||||
GenericParamDef::Type(ty) => Some(ty),
|
||||
GenericParamDef::Lifetime(_) => None,
|
||||
match param.kind {
|
||||
GenericParamDefKind::Type(_) => Some(param),
|
||||
GenericParamDefKind::Lifetime(_) => None,
|
||||
}
|
||||
});
|
||||
let trait_m_type_params = trait_m_generics.params.iter().filter_map(|param| {
|
||||
match *param {
|
||||
GenericParamDef::Type(ty) => Some(ty),
|
||||
GenericParamDef::Lifetime(_) => None,
|
||||
match param.kind {
|
||||
GenericParamDefKind::Type(_) => Some(param),
|
||||
GenericParamDefKind::Lifetime(_) => None,
|
||||
}
|
||||
});
|
||||
for (impl_ty, trait_ty) in impl_m_type_params.zip(trait_m_type_params) {
|
||||
if impl_ty.synthetic != trait_ty.synthetic {
|
||||
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();
|
||||
let impl_span = tcx.hir.span(impl_node_id);
|
||||
let trait_span = tcx.def_span(trait_ty.def_id);
|
||||
|
|
|
@ -76,7 +76,7 @@ fn equate_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
/// and in libcore/intrinsics.rs
|
||||
pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
it: &hir::ForeignItem) {
|
||||
let param = |n| tcx.mk_param(n, Symbol::intern(&format!("P{}", n)).as_interned_str());
|
||||
let param = |n| tcx.mk_ty_param(n, Symbol::intern(&format!("P{}", n)).as_interned_str());
|
||||
let name = it.name.as_str();
|
||||
let (n_tps, inputs, output) = if name.starts_with("atomic_") {
|
||||
let split : Vec<&str> = name.split('_').collect();
|
||||
|
@ -342,7 +342,7 @@ pub fn check_platform_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
it: &hir::ForeignItem) {
|
||||
let param = |n| {
|
||||
let name = Symbol::intern(&format!("P{}", n)).as_interned_str();
|
||||
tcx.mk_param(n, name)
|
||||
tcx.mk_ty_param(n, name)
|
||||
};
|
||||
|
||||
let def_id = tcx.hir.local_def_id(it.id);
|
||||
|
|
|
@ -1730,7 +1730,7 @@ impl<'a, 'gcx, 'tcx> AstConv<'gcx, 'tcx> for FnCtxt<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn re_infer(&self, span: Span, def: Option<&ty::RegionParamDef>)
|
||||
fn re_infer(&self, span: Span, def: Option<&ty::GenericParamDef>)
|
||||
-> Option<ty::Region<'tcx>> {
|
||||
let v = match def {
|
||||
Some(def) => infer::EarlyBoundRegion(span, def.name),
|
||||
|
@ -1744,7 +1744,7 @@ impl<'a, 'gcx, 'tcx> AstConv<'gcx, 'tcx> for FnCtxt<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
|
||||
fn ty_infer_for_def(&self,
|
||||
ty_param_def: &ty::TypeParamDef,
|
||||
ty_param_def: &ty::GenericParamDef,
|
||||
span: Span) -> Ty<'tcx> {
|
||||
self.type_var_for_def(span, ty_param_def)
|
||||
}
|
||||
|
@ -4805,7 +4805,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
if let Some(ast_ty) = types.get(i) {
|
||||
// A provided type parameter.
|
||||
self.to_ty(ast_ty)
|
||||
} else if !infer_types && def.has_default {
|
||||
} else if !infer_types && def.to_type().has_default {
|
||||
// No type parameter provided, but a default exists.
|
||||
let default = self.tcx.type_of(def.def_id);
|
||||
self.normalize_ty(
|
||||
|
@ -4928,7 +4928,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
let type_params_without_defaults = {
|
||||
let mut count = 0;
|
||||
for param in generics.params.iter() {
|
||||
if let ty::GenericParamDef::Type(ty) = param {
|
||||
if let ty::GenericParamDefKind::Type(ty) = param.kind {
|
||||
if !ty.has_default {
|
||||
count += 1
|
||||
}
|
||||
|
@ -5025,7 +5025,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
let segment = segment.map(|(path_segment, generics)| {
|
||||
let explicit = !path_segment.infer_types;
|
||||
let impl_trait = generics.params.iter().any(|param| {
|
||||
if let ty::GenericParamDef::Type(ty) = param {
|
||||
if let ty::GenericParamDefKind::Type(ty) = param.kind {
|
||||
if let Some(hir::SyntheticTyParamKind::ImplTrait) = ty.synthetic {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
use check::{Inherited, FnCtxt};
|
||||
use constrained_type_params::{identify_constrained_type_params, Parameter};
|
||||
|
||||
use ty::GenericParamDef;
|
||||
use ty::GenericParamDefKind;
|
||||
|
||||
use hir::def_id::DefId;
|
||||
use rustc::traits::{self, ObligationCauseCode};
|
||||
|
@ -370,8 +370,8 @@ fn check_where_clauses<'a, 'gcx, 'fcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>,
|
|||
let mut substituted_predicates = Vec::new();
|
||||
|
||||
let generics = tcx.generics_of(def_id);
|
||||
let is_our_default = |def: &ty::TypeParamDef| {
|
||||
def.has_default && def.index >= generics.parent_count as u32
|
||||
let is_our_default = |def: &ty::GenericParamDef| {
|
||||
def.to_type().has_default && def.index >= generics.parent_count as u32
|
||||
};
|
||||
|
||||
// Check that concrete defaults are well-formed. See test `type-check-defaults.rs`.
|
||||
|
@ -379,9 +379,9 @@ fn check_where_clauses<'a, 'gcx, 'fcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>,
|
|||
// struct Foo<T = Vec<[u32]>> { .. }
|
||||
// Here the default `Vec<[u32]>` is not WF because `[u32]: Sized` does not hold.
|
||||
for d in generics.params.iter().filter_map(|param| {
|
||||
if let GenericParamDef::Type(ty) = *param {
|
||||
if is_our_default(&ty) {
|
||||
return Some(ty.def_id);
|
||||
if let GenericParamDefKind::Type(_) = param.kind {
|
||||
if is_our_default(¶m) {
|
||||
return Some(param.def_id);
|
||||
}
|
||||
}
|
||||
None
|
||||
|
@ -654,21 +654,18 @@ fn reject_shadowing_parameters(tcx: TyCtxt, def_id: DefId) {
|
|||
let impl_params: FxHashMap<_, _> =
|
||||
parent.params.iter()
|
||||
.flat_map(|param| {
|
||||
match param {
|
||||
GenericParamDef::Lifetime(_) => None,
|
||||
GenericParamDef::Type(ty) => Some((ty.name, ty.def_id)),
|
||||
match param.kind {
|
||||
GenericParamDefKind::Lifetime(_) => None,
|
||||
GenericParamDefKind::Type(_) => Some((param.name, param.def_id)),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
for method_param in generics.params.iter() {
|
||||
// Shadowing is checked in resolve_lifetime.
|
||||
if let GenericParamDef::Lifetime(_) = method_param {
|
||||
continue;
|
||||
}
|
||||
let (name, def_id) = match method_param {
|
||||
GenericParamDef::Lifetime(_) => continue,
|
||||
GenericParamDef::Type(ty) => (ty.name, ty.def_id),
|
||||
let (name, def_id) = match method_param.kind {
|
||||
// Shadowing is checked in resolve_lifetime.
|
||||
GenericParamDefKind::Lifetime(_) => continue,
|
||||
GenericParamDefKind::Type(_) => (method_param.name, method_param.def_id),
|
||||
};
|
||||
if impl_params.contains_key(&name) {
|
||||
// Tighten up the span to focus on only the shadowing type
|
||||
|
|
|
@ -181,7 +181,7 @@ impl<'a, 'tcx> AstConv<'tcx, 'tcx> for ItemCtxt<'a, 'tcx> {
|
|||
self.tcx.at(span).type_param_predicates((self.item_def_id, def_id))
|
||||
}
|
||||
|
||||
fn re_infer(&self, _span: Span, _def: Option<&ty::RegionParamDef>)
|
||||
fn re_infer(&self, _span: Span, _def: Option<&ty::GenericParamDef>)
|
||||
-> Option<ty::Region<'tcx>> {
|
||||
None
|
||||
}
|
||||
|
@ -244,7 +244,7 @@ fn type_param_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
let param_owner_def_id = tcx.hir.local_def_id(param_owner);
|
||||
let generics = tcx.generics_of(param_owner_def_id);
|
||||
let index = generics.param_def_id_to_index[&def_id];
|
||||
let ty = tcx.mk_param(index, tcx.hir.ty_param_name(param_id).as_interned_str());
|
||||
let ty = tcx.mk_ty_param(index, tcx.hir.ty_param_name(param_id).as_interned_str());
|
||||
|
||||
// Don't look for bounds where the type parameter isn't in scope.
|
||||
let parent = if item_def_id == param_owner_def_id {
|
||||
|
@ -840,14 +840,16 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
// the node id for the Self type parameter.
|
||||
let param_id = item.id;
|
||||
|
||||
opt_self = Some(ty::TypeParamDef {
|
||||
opt_self = Some(ty::GenericParamDef {
|
||||
index: 0,
|
||||
name: keywords::SelfType.name().as_interned_str(),
|
||||
def_id: tcx.hir.local_def_id(param_id),
|
||||
has_default: false,
|
||||
object_lifetime_default: rl::Set1::Empty,
|
||||
pure_wrt_drop: false,
|
||||
synthetic: None,
|
||||
kind: ty::GenericParamDefKind::Type(ty::TypeParamDef {
|
||||
has_default: false,
|
||||
object_lifetime_default: rl::Set1::Empty,
|
||||
pure_wrt_drop: false,
|
||||
synthetic: None,
|
||||
}),
|
||||
});
|
||||
|
||||
allow_defaults = true;
|
||||
|
@ -885,12 +887,14 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
});
|
||||
|
||||
let early_lifetimes = early_bound_lifetimes_from_generics(tcx, ast_generics);
|
||||
let regions = early_lifetimes.enumerate().map(|(i, l)| {
|
||||
ty::RegionParamDef {
|
||||
let lifetimes = early_lifetimes.enumerate().map(|(i, l)| {
|
||||
ty::GenericParamDef {
|
||||
name: l.lifetime.name.name().as_interned_str(),
|
||||
index: own_start + i as u32,
|
||||
def_id: tcx.hir.local_def_id(l.lifetime.id),
|
||||
pure_wrt_drop: l.pure_wrt_drop,
|
||||
kind: ty::GenericParamDefKind::Lifetime(ty::RegionParamDef {
|
||||
pure_wrt_drop: l.pure_wrt_drop,
|
||||
}),
|
||||
}
|
||||
}).collect::<Vec<_>>();
|
||||
|
||||
|
@ -898,7 +902,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
let object_lifetime_defaults = tcx.object_lifetime_defaults(hir_id);
|
||||
|
||||
// Now create the real type parameters.
|
||||
let type_start = own_start + regions.len() as u32;
|
||||
let type_start = own_start + lifetimes.len() as u32;
|
||||
let types = ast_generics.ty_params().enumerate().map(|(i, p)| {
|
||||
if p.name == keywords::SelfType.name() {
|
||||
span_bug!(p.span, "`Self` should not be the name of a regular parameter");
|
||||
|
@ -915,15 +919,17 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
}
|
||||
}
|
||||
|
||||
ty::TypeParamDef {
|
||||
ty::GenericParamDef {
|
||||
index: type_start + i as u32,
|
||||
name: p.name.as_interned_str(),
|
||||
def_id: tcx.hir.local_def_id(p.id),
|
||||
has_default: p.default.is_some(),
|
||||
object_lifetime_default:
|
||||
object_lifetime_defaults.as_ref().map_or(rl::Set1::Empty, |o| o[i]),
|
||||
pure_wrt_drop: p.pure_wrt_drop,
|
||||
synthetic: p.synthetic,
|
||||
kind: ty::GenericParamDefKind::Type(ty::TypeParamDef {
|
||||
has_default: p.default.is_some(),
|
||||
object_lifetime_default:
|
||||
object_lifetime_defaults.as_ref().map_or(rl::Set1::Empty, |o| o[i]),
|
||||
pure_wrt_drop: p.pure_wrt_drop,
|
||||
synthetic: p.synthetic,
|
||||
}),
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -940,41 +946,43 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
};
|
||||
|
||||
for (i, &arg) in dummy_args.iter().enumerate() {
|
||||
types.push(ty::TypeParamDef {
|
||||
types.push(ty::GenericParamDef {
|
||||
index: type_start + i as u32,
|
||||
name: Symbol::intern(arg).as_interned_str(),
|
||||
def_id,
|
||||
has_default: false,
|
||||
object_lifetime_default: rl::Set1::Empty,
|
||||
pure_wrt_drop: false,
|
||||
synthetic: None,
|
||||
kind: ty::GenericParamDefKind::Type(ty::TypeParamDef {
|
||||
has_default: false,
|
||||
object_lifetime_default: rl::Set1::Empty,
|
||||
pure_wrt_drop: false,
|
||||
synthetic: None,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
tcx.with_freevars(node_id, |fv| {
|
||||
types.extend(fv.iter().zip((dummy_args.len() as u32)..).map(|(_, i)| {
|
||||
ty::TypeParameterDef {
|
||||
ty::GenericParamDef {
|
||||
index: type_start + i,
|
||||
name: Symbol::intern("<upvar>").as_interned_str(),
|
||||
def_id,
|
||||
has_default: false,
|
||||
object_lifetime_default: rl::Set1::Empty,
|
||||
pure_wrt_drop: false,
|
||||
synthetic: None,
|
||||
kind: ty::GenericParamDefKind::Type(ty::TypeParamDef {
|
||||
has_default: false,
|
||||
object_lifetime_default: rl::Set1::Empty,
|
||||
pure_wrt_drop: false,
|
||||
synthetic: None,
|
||||
}),
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
let opt_self = opt_self.into_iter().map(|ty| ty::GenericParamDef::Type(ty));
|
||||
let lifetimes = regions.into_iter().map(|lt| ty::GenericParamDef::Lifetime(lt));
|
||||
let types = types.into_iter().map(|ty| ty::GenericParamDef::Type(ty));
|
||||
let params: Vec<_> = opt_self.chain(lifetimes)
|
||||
let params: Vec<_> = opt_self.into_iter()
|
||||
.chain(lifetimes)
|
||||
.chain(types)
|
||||
.collect();
|
||||
|
||||
let param_def_id_to_index = params.iter()
|
||||
.map(|param| (param.def_id(), param.index()))
|
||||
.map(|param| (param.def_id, param.index))
|
||||
.collect();
|
||||
|
||||
tcx.alloc_generics(ty::Generics {
|
||||
|
@ -1101,7 +1109,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
let region = def.to_early_bound_region_data();
|
||||
tcx.mk_region(ty::ReEarlyBound(region))
|
||||
},
|
||||
|def, _| tcx.mk_param_from_def(def)
|
||||
|def, _| tcx.mk_ty_param_from_def(def)
|
||||
)
|
||||
};
|
||||
|
||||
|
|
|
@ -117,24 +117,24 @@ fn enforce_impl_params_are_constrained<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
|
||||
for (ty_param, hir_param) in impl_generics.params.iter()
|
||||
.zip(impl_hir_generics.params.iter()) {
|
||||
match (ty_param, hir_param) {
|
||||
match (&ty_param.kind, hir_param) {
|
||||
// Disallow ANY unconstrained type parameters.
|
||||
(ty::GenericParamDef::Type(ty_ty), hir::GenericParam::Type(hir_ty)) => {
|
||||
let param_ty = ty::ParamTy::for_def(ty_ty);
|
||||
(&ty::GenericParamDefKind::Type(_), hir::GenericParam::Type(hir_ty)) => {
|
||||
let param_ty = ty::ParamTy::for_def(ty_param);
|
||||
if !input_parameters.contains(&ctp::Parameter::from(param_ty)) {
|
||||
report_unused_parameter(tcx, hir_ty.span, "type", ¶m_ty.to_string());
|
||||
}
|
||||
}
|
||||
(ty::GenericParamDef::Lifetime(ty_lt), hir::GenericParam::Lifetime(hir_lt)) => {
|
||||
let param = ctp::Parameter::from(ty_lt.to_early_bound_region_data());
|
||||
(&ty::GenericParamDefKind::Lifetime(_), hir::GenericParam::Lifetime(hir_lt)) => {
|
||||
let param = ctp::Parameter::from(ty_param.to_early_bound_region_data());
|
||||
if lifetimes_in_associated_types.contains(¶m) && // (*)
|
||||
!input_parameters.contains(¶m) {
|
||||
report_unused_parameter(tcx, hir_lt.lifetime.span,
|
||||
"lifetime", &hir_lt.lifetime.name.name().to_string());
|
||||
}
|
||||
}
|
||||
(ty::GenericParamDef::Type(_), _) => continue,
|
||||
(ty::GenericParamDef::Lifetime(_), _) => continue,
|
||||
(&ty::GenericParamDefKind::Type(_), _) => continue,
|
||||
(&ty::GenericParamDefKind::Lifetime(_), _) => continue,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -353,7 +353,7 @@ fn insert_outlives_predicate<'tcx>(
|
|||
// Vec<U>`. Decomposing `Vec<U>` into
|
||||
// components would yield `U`, and we add the
|
||||
// where clause that `U: 'a`.
|
||||
let ty: Ty<'tcx> = tcx.mk_param(param_ty.idx, param_ty.name);
|
||||
let ty: Ty<'tcx> = tcx.mk_ty_param(param_ty.idx, param_ty.name);
|
||||
required_predicates
|
||||
.insert(ty::OutlivesPredicate(ty.into(), outlived_region));
|
||||
}
|
||||
|
|
|
@ -228,12 +228,12 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
|
|||
let mut types = vec![];
|
||||
|
||||
for param in generics.params.iter() {
|
||||
match param {
|
||||
ty::GenericParamDef::Lifetime(lt) => {
|
||||
let name = if lt.name == "" {
|
||||
match param.kind {
|
||||
ty::GenericParamDefKind::Lifetime(_) => {
|
||||
let name = if param.name == "" {
|
||||
hir::LifetimeName::Static
|
||||
} else {
|
||||
hir::LifetimeName::Name(lt.name.as_symbol())
|
||||
hir::LifetimeName::Name(param.name.as_symbol())
|
||||
};
|
||||
|
||||
lifetimes.push(hir::Lifetime {
|
||||
|
@ -242,8 +242,8 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
|
|||
name,
|
||||
});
|
||||
}
|
||||
ty::GenericParamDef::Type(ty) => {
|
||||
types.push(P(self.ty_param_to_ty(ty.clone())));
|
||||
ty::GenericParamDefKind::Type(_) => {
|
||||
types.push(P(self.ty_param_to_ty(param.clone())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -256,7 +256,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn ty_param_to_ty(&self, param: ty::TypeParamDef) -> hir::Ty {
|
||||
fn ty_param_to_ty(&self, param: ty::GenericParamDef) -> hir::Ty {
|
||||
debug!("ty_param_to_ty({:?}) {:?}", param, param.def_id);
|
||||
hir::Ty {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
|
|
|
@ -1336,14 +1336,14 @@ impl Clean<TyParam> for hir::TyParam {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Clean<TyParam> for ty::TypeParamDef {
|
||||
impl<'tcx> Clean<TyParam> for ty::GenericParamDef {
|
||||
fn clean(&self, cx: &DocContext) -> TyParam {
|
||||
cx.renderinfo.borrow_mut().external_typarams.insert(self.def_id, self.name.clean(cx));
|
||||
TyParam {
|
||||
name: self.name.clean(cx),
|
||||
did: self.def_id,
|
||||
bounds: vec![], // these are filled in from the where-clauses
|
||||
default: if self.has_default {
|
||||
default: if self.to_type().has_default {
|
||||
Some(cx.tcx.type_of(self.def_id).clean(cx))
|
||||
} else {
|
||||
None
|
||||
|
@ -1577,8 +1577,8 @@ impl Clean<Lifetime> for hir::LifetimeDef {
|
|||
}
|
||||
}
|
||||
|
||||
impl Clean<Lifetime> for ty::RegionParamDef {
|
||||
fn clean(&self, _: &DocContext) -> Lifetime {
|
||||
impl<'tcx> Clean<Lifetime> for ty::GenericParamDef {
|
||||
fn clean(&self, _cx: &DocContext) -> Lifetime {
|
||||
Lifetime(self.name.to_string())
|
||||
}
|
||||
}
|
||||
|
@ -1800,17 +1800,17 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
|
|||
// predicates field (see rustc_typeck::collect::ty_generics), so remove
|
||||
// them.
|
||||
let stripped_typarams = gens.params.iter().filter_map(|param| {
|
||||
if let ty::GenericParamDef::Type(ty) = param {
|
||||
if ty.name == keywords::SelfType.name().as_str() {
|
||||
assert_eq!(ty.index, 0);
|
||||
if let ty::GenericParamDefKind::Type(_) = param.kind {
|
||||
if param.name == keywords::SelfType.name().as_str() {
|
||||
assert_eq!(param.index, 0);
|
||||
None
|
||||
} else {
|
||||
Some(ty.clean(cx))
|
||||
Some(param.clean(cx))
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}).collect::<Vec<_>>();
|
||||
}).collect::<Vec<TyParam>>();
|
||||
|
||||
let mut where_predicates = preds.predicates.to_vec().clean(cx);
|
||||
|
||||
|
@ -1855,8 +1855,8 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
|
|||
params: gens.params
|
||||
.iter()
|
||||
.flat_map(|param| {
|
||||
if let ty::GenericParamDef::Lifetime(lt) = param {
|
||||
Some(GenericParamDef::Lifetime(lt.clean(cx)))
|
||||
if let ty::GenericParamDefKind::Lifetime(_) = param.kind {
|
||||
Some(GenericParamDef::Lifetime(param.clean(cx)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue