Remove bounds struct from TypeParameterDef. Bounds information is now
exclusively stored in the where clauses.
This commit is contained in:
parent
3c782b742b
commit
36d04711b7
6 changed files with 38 additions and 57 deletions
|
@ -822,7 +822,6 @@ fn parse_type_param_def_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F)
|
|||
assert_eq!(next(st), '|');
|
||||
let index = parse_u32(st);
|
||||
assert_eq!(next(st), '|');
|
||||
let bounds = parse_bounds_(st, conv);
|
||||
let default = parse_opt(st, |st| parse_ty_(st, conv));
|
||||
let object_lifetime_default = parse_object_lifetime_default(st, conv);
|
||||
|
||||
|
@ -831,28 +830,11 @@ fn parse_type_param_def_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F)
|
|||
def_id: def_id,
|
||||
space: space,
|
||||
index: index,
|
||||
bounds: bounds,
|
||||
default: default,
|
||||
object_lifetime_default: object_lifetime_default,
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_object_lifetime_default<'a,'tcx, F>(st: &mut PState<'a,'tcx>,
|
||||
conv: &mut F)
|
||||
-> Option<ty::ObjectLifetimeDefault>
|
||||
where F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
|
||||
{
|
||||
match next(st) {
|
||||
'n' => None,
|
||||
'a' => Some(ty::ObjectLifetimeDefault::Ambiguous),
|
||||
's' => {
|
||||
let region = parse_region_(st, conv);
|
||||
Some(ty::ObjectLifetimeDefault::Specific(region))
|
||||
}
|
||||
_ => panic!("parse_object_lifetime_default: bad input")
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_existential_bounds<'a,'tcx, F>(st: &mut PState<'a,'tcx>,
|
||||
mut conv: F)
|
||||
-> ty::ExistentialBounds<'tcx> where
|
||||
|
@ -924,18 +906,18 @@ fn parse_bounds_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F)
|
|||
{
|
||||
let builtin_bounds = parse_builtin_bounds_(st, conv);
|
||||
|
||||
let region_bounds = parse_region_bounds_(st, conv);
|
||||
|
||||
let mut param_bounds = ty::ParamBounds {
|
||||
region_bounds: Vec::new(),
|
||||
region_bounds: region_bounds,
|
||||
builtin_bounds: builtin_bounds,
|
||||
trait_bounds: Vec::new(),
|
||||
projection_bounds: Vec::new(),
|
||||
};
|
||||
|
||||
|
||||
loop {
|
||||
match next(st) {
|
||||
'R' => {
|
||||
param_bounds.region_bounds.push(
|
||||
parse_region_(st, conv));
|
||||
}
|
||||
'I' => {
|
||||
param_bounds.trait_bounds.push(
|
||||
ty::Binder(parse_trait_ref_(st, conv)));
|
||||
|
@ -953,3 +935,18 @@ fn parse_bounds_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_region_bounds_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F)
|
||||
-> Vec<ty::Region> where
|
||||
F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
|
||||
{
|
||||
let mut region_bounds = Vec::new();
|
||||
loop {
|
||||
match next(st) {
|
||||
'R' => { region_bounds.push(parse_region_(st, conv)); }
|
||||
'.' => { return region_bounds; }
|
||||
c => { panic!("parse_bounds: bad bounds ('{}')", c); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -386,10 +386,7 @@ pub fn enc_bounds<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
|
|||
bs: &ty::ParamBounds<'tcx>) {
|
||||
enc_builtin_bounds(w, cx, &bs.builtin_bounds);
|
||||
|
||||
for &r in &bs.region_bounds {
|
||||
mywrite!(w, "R");
|
||||
enc_region(w, cx, r);
|
||||
}
|
||||
enc_region_bounds(w, cx, &bs.region_bounds);
|
||||
|
||||
for tp in &bs.trait_bounds {
|
||||
mywrite!(w, "I");
|
||||
|
@ -404,12 +401,22 @@ pub fn enc_bounds<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
|
|||
mywrite!(w, ".");
|
||||
}
|
||||
|
||||
pub fn enc_region_bounds<'a, 'tcx>(w: &mut SeekableMemWriter,
|
||||
cx: &ctxt<'a, 'tcx>,
|
||||
rs: &[ty::Region]) {
|
||||
for &r in rs {
|
||||
mywrite!(w, "R");
|
||||
enc_region(w, cx, r);
|
||||
}
|
||||
|
||||
mywrite!(w, ".");
|
||||
}
|
||||
|
||||
pub fn enc_type_param_def<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
|
||||
v: &ty::TypeParameterDef<'tcx>) {
|
||||
mywrite!(w, "{}:{}|{}|{}|",
|
||||
token::get_name(v.name), (cx.ds)(v.def_id),
|
||||
v.space.to_uint(), v.index);
|
||||
enc_bounds(w, cx, &v.bounds);
|
||||
enc_opt(w, v.default, |w, t| enc_ty(w, cx, t));
|
||||
enc_object_lifetime_default(w, cx, v.object_lifetime_default);
|
||||
}
|
||||
|
|
|
@ -1750,7 +1750,6 @@ pub struct TypeParameterDef<'tcx> {
|
|||
pub def_id: ast::DefId,
|
||||
pub space: subst::ParamSpace,
|
||||
pub index: u32,
|
||||
pub bounds: ParamBounds<'tcx>,
|
||||
pub default: Option<Ty<'tcx>>,
|
||||
pub object_lifetime_default: Option<ObjectLifetimeDefault>,
|
||||
}
|
||||
|
|
|
@ -377,7 +377,6 @@ impl<'tcx> TypeFoldable<'tcx> for ty::TypeParameterDef<'tcx> {
|
|||
def_id: self.def_id,
|
||||
space: self.space,
|
||||
index: self.index,
|
||||
bounds: self.bounds.fold_with(folder),
|
||||
default: self.default.fold_with(folder),
|
||||
object_lifetime_default: self.object_lifetime_default.fold_with(folder),
|
||||
}
|
||||
|
|
|
@ -1225,10 +1225,10 @@ fn convert_trait_predicates<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, it: &ast::Item)
|
|||
};
|
||||
base_predicates.predicates.extend(subst::TypeSpace, assoc_predicates.into_iter());
|
||||
|
||||
let self_bounds = &trait_def.generics.types.get_self().unwrap().bounds;
|
||||
base_predicates.predicates.extend(
|
||||
subst::SelfSpace,
|
||||
ty::predicates(ccx.tcx, self_param_ty, self_bounds).into_iter());
|
||||
// Add in a predicate that `Self:Trait` (where `Trait` is the
|
||||
// current trait). This is needed for builtin bounds.
|
||||
let self_predicate = trait_def.trait_ref.to_poly_trait_ref().as_predicate();
|
||||
base_predicates.predicates.push(SelfSpace, self_predicate);
|
||||
|
||||
// add in the explicit where-clauses
|
||||
let trait_predicates =
|
||||
|
@ -1532,21 +1532,11 @@ fn ty_generics_for_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
|
|||
// the node id for the Self type parameter.
|
||||
let param_id = trait_id;
|
||||
|
||||
let self_trait_ref =
|
||||
Rc::new(ty::TraitRef { def_id: local_def(trait_id),
|
||||
substs: substs });
|
||||
|
||||
let def = ty::TypeParameterDef {
|
||||
space: subst::SelfSpace,
|
||||
index: 0,
|
||||
name: special_idents::type_self.name,
|
||||
def_id: local_def(param_id),
|
||||
bounds: ty::ParamBounds {
|
||||
region_bounds: vec!(),
|
||||
builtin_bounds: ty::empty_builtin_bounds(),
|
||||
trait_bounds: vec!(ty::Binder(self_trait_ref.clone())),
|
||||
projection_bounds: vec!(),
|
||||
},
|
||||
default: None,
|
||||
object_lifetime_default: None,
|
||||
};
|
||||
|
@ -1761,13 +1751,6 @@ fn get_or_create_type_parameter_def<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
|
|||
None => { }
|
||||
}
|
||||
|
||||
let param_ty = ty::ParamTy::new(space, index, param.ident.name);
|
||||
let bounds = compute_bounds(ccx,
|
||||
generics_so_far,
|
||||
param_ty.to_ty(ccx.tcx),
|
||||
¶m.bounds,
|
||||
SizedByDefault::Yes,
|
||||
param.span);
|
||||
let default = match param.default {
|
||||
None => None,
|
||||
Some(ref path) => {
|
||||
|
@ -1797,7 +1780,6 @@ fn get_or_create_type_parameter_def<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
|
|||
index: index,
|
||||
name: param.ident.name,
|
||||
def_id: local_def(param.id),
|
||||
bounds: bounds,
|
||||
default: default,
|
||||
object_lifetime_default: object_lifetime_default,
|
||||
};
|
||||
|
|
|
@ -479,11 +479,10 @@ impl<'tcx> Clean<TyParam> for ty::TypeParameterDef<'tcx> {
|
|||
fn clean(&self, cx: &DocContext) -> TyParam {
|
||||
cx.external_typarams.borrow_mut().as_mut().unwrap()
|
||||
.insert(self.def_id, self.name.clean(cx));
|
||||
let bounds = self.bounds.clean(cx);
|
||||
TyParam {
|
||||
name: self.name.clean(cx),
|
||||
did: self.def_id,
|
||||
bounds: bounds,
|
||||
bounds: vec![], // these are filled in from the where-clauses
|
||||
default: self.default.clean(cx),
|
||||
}
|
||||
}
|
||||
|
@ -892,9 +891,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics<'tcx>,
|
|||
// Bounds in the type_params and lifetimes fields are repeated in the predicates
|
||||
// field (see rustc_typeck::collect::ty_generics), so remove them.
|
||||
let stripped_typarams = gens.types.get_slice(space).iter().map(|tp| {
|
||||
let mut stp = tp.clone();
|
||||
stp.bounds = ty::ParamBounds::empty();
|
||||
stp.clean(cx)
|
||||
tp.clean(cx)
|
||||
}).collect::<Vec<_>>();
|
||||
let stripped_lifetimes = gens.regions.get_slice(space).iter().map(|rp| {
|
||||
let mut srp = rp.clone();
|
||||
|
|
Loading…
Add table
Reference in a new issue