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