Skip to content

Commit 36d0471

Browse files
committed
Remove bounds struct from TypeParameterDef. Bounds information is now
exclusively stored in the where clauses.
1 parent 3c782b7 commit 36d0471

File tree

6 files changed

+38
-57
lines changed

6 files changed

+38
-57
lines changed

src/librustc/metadata/tydecode.rs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,6 @@ fn parse_type_param_def_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F)
822822
assert_eq!(next(st), '|');
823823
let index = parse_u32(st);
824824
assert_eq!(next(st), '|');
825-
let bounds = parse_bounds_(st, conv);
826825
let default = parse_opt(st, |st| parse_ty_(st, conv));
827826
let object_lifetime_default = parse_object_lifetime_default(st, conv);
828827

@@ -831,28 +830,11 @@ fn parse_type_param_def_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F)
831830
def_id: def_id,
832831
space: space,
833832
index: index,
834-
bounds: bounds,
835833
default: default,
836834
object_lifetime_default: object_lifetime_default,
837835
}
838836
}
839837

840-
fn parse_object_lifetime_default<'a,'tcx, F>(st: &mut PState<'a,'tcx>,
841-
conv: &mut F)
842-
-> Option<ty::ObjectLifetimeDefault>
843-
where F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
844-
{
845-
match next(st) {
846-
'n' => None,
847-
'a' => Some(ty::ObjectLifetimeDefault::Ambiguous),
848-
's' => {
849-
let region = parse_region_(st, conv);
850-
Some(ty::ObjectLifetimeDefault::Specific(region))
851-
}
852-
_ => panic!("parse_object_lifetime_default: bad input")
853-
}
854-
}
855-
856838
fn parse_existential_bounds<'a,'tcx, F>(st: &mut PState<'a,'tcx>,
857839
mut conv: F)
858840
-> ty::ExistentialBounds<'tcx> where
@@ -924,18 +906,18 @@ fn parse_bounds_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F)
924906
{
925907
let builtin_bounds = parse_builtin_bounds_(st, conv);
926908

909+
let region_bounds = parse_region_bounds_(st, conv);
910+
927911
let mut param_bounds = ty::ParamBounds {
928-
region_bounds: Vec::new(),
912+
region_bounds: region_bounds,
929913
builtin_bounds: builtin_bounds,
930914
trait_bounds: Vec::new(),
931915
projection_bounds: Vec::new(),
932916
};
917+
918+
933919
loop {
934920
match next(st) {
935-
'R' => {
936-
param_bounds.region_bounds.push(
937-
parse_region_(st, conv));
938-
}
939921
'I' => {
940922
param_bounds.trait_bounds.push(
941923
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)
953935
}
954936
}
955937
}
938+
939+
fn parse_region_bounds_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F)
940+
-> Vec<ty::Region> where
941+
F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
942+
{
943+
let mut region_bounds = Vec::new();
944+
loop {
945+
match next(st) {
946+
'R' => { region_bounds.push(parse_region_(st, conv)); }
947+
'.' => { return region_bounds; }
948+
c => { panic!("parse_bounds: bad bounds ('{}')", c); }
949+
}
950+
}
951+
}
952+

src/librustc/metadata/tyencode.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,7 @@ pub fn enc_bounds<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
386386
bs: &ty::ParamBounds<'tcx>) {
387387
enc_builtin_bounds(w, cx, &bs.builtin_bounds);
388388

389-
for &r in &bs.region_bounds {
390-
mywrite!(w, "R");
391-
enc_region(w, cx, r);
392-
}
389+
enc_region_bounds(w, cx, &bs.region_bounds);
393390

394391
for tp in &bs.trait_bounds {
395392
mywrite!(w, "I");
@@ -404,12 +401,22 @@ pub fn enc_bounds<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
404401
mywrite!(w, ".");
405402
}
406403

404+
pub fn enc_region_bounds<'a, 'tcx>(w: &mut SeekableMemWriter,
405+
cx: &ctxt<'a, 'tcx>,
406+
rs: &[ty::Region]) {
407+
for &r in rs {
408+
mywrite!(w, "R");
409+
enc_region(w, cx, r);
410+
}
411+
412+
mywrite!(w, ".");
413+
}
414+
407415
pub fn enc_type_param_def<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
408416
v: &ty::TypeParameterDef<'tcx>) {
409417
mywrite!(w, "{}:{}|{}|{}|",
410418
token::get_name(v.name), (cx.ds)(v.def_id),
411419
v.space.to_uint(), v.index);
412-
enc_bounds(w, cx, &v.bounds);
413420
enc_opt(w, v.default, |w, t| enc_ty(w, cx, t));
414421
enc_object_lifetime_default(w, cx, v.object_lifetime_default);
415422
}

src/librustc/middle/ty.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,6 @@ pub struct TypeParameterDef<'tcx> {
17501750
pub def_id: ast::DefId,
17511751
pub space: subst::ParamSpace,
17521752
pub index: u32,
1753-
pub bounds: ParamBounds<'tcx>,
17541753
pub default: Option<Ty<'tcx>>,
17551754
pub object_lifetime_default: Option<ObjectLifetimeDefault>,
17561755
}

src/librustc/middle/ty_fold.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,6 @@ impl<'tcx> TypeFoldable<'tcx> for ty::TypeParameterDef<'tcx> {
377377
def_id: self.def_id,
378378
space: self.space,
379379
index: self.index,
380-
bounds: self.bounds.fold_with(folder),
381380
default: self.default.fold_with(folder),
382381
object_lifetime_default: self.object_lifetime_default.fold_with(folder),
383382
}

src/librustc_typeck/collect.rs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,10 +1225,10 @@ fn convert_trait_predicates<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, it: &ast::Item)
12251225
};
12261226
base_predicates.predicates.extend(subst::TypeSpace, assoc_predicates.into_iter());
12271227

1228-
let self_bounds = &trait_def.generics.types.get_self().unwrap().bounds;
1229-
base_predicates.predicates.extend(
1230-
subst::SelfSpace,
1231-
ty::predicates(ccx.tcx, self_param_ty, self_bounds).into_iter());
1228+
// Add in a predicate that `Self:Trait` (where `Trait` is the
1229+
// current trait). This is needed for builtin bounds.
1230+
let self_predicate = trait_def.trait_ref.to_poly_trait_ref().as_predicate();
1231+
base_predicates.predicates.push(SelfSpace, self_predicate);
12321232

12331233
// add in the explicit where-clauses
12341234
let trait_predicates =
@@ -1532,21 +1532,11 @@ fn ty_generics_for_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
15321532
// the node id for the Self type parameter.
15331533
let param_id = trait_id;
15341534

1535-
let self_trait_ref =
1536-
Rc::new(ty::TraitRef { def_id: local_def(trait_id),
1537-
substs: substs });
1538-
15391535
let def = ty::TypeParameterDef {
15401536
space: subst::SelfSpace,
15411537
index: 0,
15421538
name: special_idents::type_self.name,
15431539
def_id: local_def(param_id),
1544-
bounds: ty::ParamBounds {
1545-
region_bounds: vec!(),
1546-
builtin_bounds: ty::empty_builtin_bounds(),
1547-
trait_bounds: vec!(ty::Binder(self_trait_ref.clone())),
1548-
projection_bounds: vec!(),
1549-
},
15501540
default: None,
15511541
object_lifetime_default: None,
15521542
};
@@ -1761,13 +1751,6 @@ fn get_or_create_type_parameter_def<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
17611751
None => { }
17621752
}
17631753

1764-
let param_ty = ty::ParamTy::new(space, index, param.ident.name);
1765-
let bounds = compute_bounds(ccx,
1766-
generics_so_far,
1767-
param_ty.to_ty(ccx.tcx),
1768-
&param.bounds,
1769-
SizedByDefault::Yes,
1770-
param.span);
17711754
let default = match param.default {
17721755
None => None,
17731756
Some(ref path) => {
@@ -1797,7 +1780,6 @@ fn get_or_create_type_parameter_def<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
17971780
index: index,
17981781
name: param.ident.name,
17991782
def_id: local_def(param.id),
1800-
bounds: bounds,
18011783
default: default,
18021784
object_lifetime_default: object_lifetime_default,
18031785
};

src/librustdoc/clean/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -479,11 +479,10 @@ impl<'tcx> Clean<TyParam> for ty::TypeParameterDef<'tcx> {
479479
fn clean(&self, cx: &DocContext) -> TyParam {
480480
cx.external_typarams.borrow_mut().as_mut().unwrap()
481481
.insert(self.def_id, self.name.clean(cx));
482-
let bounds = self.bounds.clean(cx);
483482
TyParam {
484483
name: self.name.clean(cx),
485484
did: self.def_id,
486-
bounds: bounds,
485+
bounds: vec![], // these are filled in from the where-clauses
487486
default: self.default.clean(cx),
488487
}
489488
}
@@ -892,9 +891,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics<'tcx>,
892891
// Bounds in the type_params and lifetimes fields are repeated in the predicates
893892
// field (see rustc_typeck::collect::ty_generics), so remove them.
894893
let stripped_typarams = gens.types.get_slice(space).iter().map(|tp| {
895-
let mut stp = tp.clone();
896-
stp.bounds = ty::ParamBounds::empty();
897-
stp.clean(cx)
894+
tp.clean(cx)
898895
}).collect::<Vec<_>>();
899896
let stripped_lifetimes = gens.regions.get_slice(space).iter().map(|rp| {
900897
let mut srp = rp.clone();

0 commit comments

Comments
 (0)