Skip to content

Commit 3d2fbb4

Browse files
committed
---
yaml --- r: 167386 b: refs/heads/snap-stage3 c: becbd81 h: refs/heads/master v: v3
1 parent 5bfe9f4 commit 3d2fbb4

File tree

15 files changed

+241
-109
lines changed

15 files changed

+241
-109
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 023dfb0c898d851dee6ace2f8339b73b5287136b
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 82787c2252267561777303bcc4e4d0394c34e5c9
4+
refs/heads/snap-stage3: becbd81aaa1b8c60eb13fee898163d1a2ac33de3
55
refs/heads/try: 5204084bd2e46af7cc6e0147430e44dd0d657bbb
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/src/librustc/metadata/tydecode.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ pub fn parse_bounds_data<'tcx>(data: &[u8], crate_num: ast::CrateNum,
200200
parse_bounds(&mut st, conv)
201201
}
202202

203-
pub fn parse_existential_bounds_data(data: &[u8], crate_num: ast::CrateNum,
204-
pos: uint, tcx: &ty::ctxt, conv: conv_did)
205-
-> ty::ExistentialBounds {
203+
pub fn parse_existential_bounds_data<'tcx>(data: &[u8], crate_num: ast::CrateNum,
204+
pos: uint, tcx: &ty::ctxt<'tcx>, conv: conv_did)
205+
-> ty::ExistentialBounds<'tcx> {
206206
let mut st = parse_state_from_data(data, crate_num, pos, tcx);
207207
parse_existential_bounds(&mut st, conv)
208208
}
@@ -744,10 +744,18 @@ fn parse_type_param_def<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did)
744744
}
745745
}
746746

747-
fn parse_existential_bounds(st: &mut PState, conv: conv_did) -> ty::ExistentialBounds {
748-
let r = parse_region(st, |x,y| conv(x,y));
749-
let bb = parse_builtin_bounds(st, conv);
750-
return ty::ExistentialBounds { region_bound: r, builtin_bounds: bb };
747+
fn parse_existential_bounds<'a,'tcx>(st: &mut PState<'a,'tcx>,
748+
conv: conv_did)
749+
-> ty::ExistentialBounds<'tcx>
750+
{
751+
let ty::ParamBounds { trait_bounds, mut region_bounds, builtin_bounds, projection_bounds } =
752+
parse_bounds(st, conv);
753+
assert_eq!(region_bounds.len(), 1);
754+
assert_eq!(trait_bounds.len(), 0);
755+
let region_bound = region_bounds.pop().unwrap();
756+
return ty::ExistentialBounds { region_bound: region_bound,
757+
builtin_bounds: builtin_bounds,
758+
projection_bounds: projection_bounds };
751759
}
752760

753761
fn parse_builtin_bounds(st: &mut PState, _conv: conv_did) -> ty::BuiltinBounds {

branches/snap-stage3/src/librustc/metadata/tyencode.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,14 @@ pub fn enc_builtin_bounds(w: &mut SeekableMemWriter, _cx: &ctxt, bs: &ty::Builti
392392
mywrite!(w, ".");
393393
}
394394

395-
pub fn enc_existential_bounds(w: &mut SeekableMemWriter, cx: &ctxt, bs: &ty::ExistentialBounds) {
396-
enc_region(w, cx, bs.region_bound);
397-
enc_builtin_bounds(w, cx, &bs.builtin_bounds);
395+
pub fn enc_existential_bounds<'a,'tcx>(w: &mut SeekableMemWriter,
396+
cx: &ctxt<'a,'tcx>,
397+
bs: &ty::ExistentialBounds<'tcx>) {
398+
let param_bounds = ty::ParamBounds { trait_bounds: vec!(),
399+
region_bounds: vec!(bs.region_bound),
400+
builtin_bounds: bs.builtin_bounds,
401+
projection_bounds: bs.projection_bounds.clone() };
402+
enc_bounds(w, cx, &param_bounds);
398403
}
399404

400405
pub fn enc_bounds<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,

branches/snap-stage3/src/librustc/middle/astencode.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,8 @@ trait rbml_writer_helpers<'tcx> {
842842
type_scheme: ty::TypeScheme<'tcx>);
843843
fn emit_substs<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>,
844844
substs: &subst::Substs<'tcx>);
845-
fn emit_existential_bounds(&mut self, ecx: &e::EncodeContext, bounds: &ty::ExistentialBounds);
845+
fn emit_existential_bounds<'b>(&mut self, ecx: &e::EncodeContext<'b,'tcx>,
846+
bounds: &ty::ExistentialBounds<'tcx>);
846847
fn emit_builtin_bounds(&mut self, ecx: &e::EncodeContext, bounds: &ty::BuiltinBounds);
847848
fn emit_auto_adjustment<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>,
848849
adj: &ty::AutoAdjustment<'tcx>);
@@ -982,7 +983,8 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> {
982983
});
983984
}
984985

985-
fn emit_existential_bounds(&mut self, ecx: &e::EncodeContext, bounds: &ty::ExistentialBounds) {
986+
fn emit_existential_bounds<'b>(&mut self, ecx: &e::EncodeContext<'b,'tcx>,
987+
bounds: &ty::ExistentialBounds<'tcx>) {
986988
self.emit_opaque(|this| Ok(tyencode::enc_existential_bounds(this.writer,
987989
&ecx.ty_str_ctxt(),
988990
bounds)));
@@ -1372,7 +1374,7 @@ trait rbml_decoder_decoder_helpers<'tcx> {
13721374
fn read_type_scheme<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
13731375
-> ty::TypeScheme<'tcx>;
13741376
fn read_existential_bounds<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
1375-
-> ty::ExistentialBounds;
1377+
-> ty::ExistentialBounds<'tcx>;
13761378
fn read_substs<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
13771379
-> subst::Substs<'tcx>;
13781380
fn read_auto_adjustment<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
@@ -1626,7 +1628,7 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
16261628
}
16271629

16281630
fn read_existential_bounds<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
1629-
-> ty::ExistentialBounds
1631+
-> ty::ExistentialBounds<'tcx>
16301632
{
16311633
self.read_opaque(|this, doc| {
16321634
Ok(tydecode::parse_existential_bounds_data(doc.data,

branches/snap-stage3/src/librustc/middle/infer/coercion.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,11 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
351351
(&ty::ty_trait(..), &ty::ty_trait(..)) => {
352352
None
353353
}
354-
(_, &ty::ty_trait(box ty::TyTrait { ref principal, bounds })) => {
354+
(_, &ty::ty_trait(box ty::TyTrait { ref principal, ref bounds })) => {
355355
// FIXME what is the purpose of `ty`?
356-
let ty = ty::mk_trait(tcx, principal.clone(), bounds);
357-
Some((ty, ty::UnsizeVtable(ty::TyTrait { principal: (*principal).clone(),
358-
bounds: bounds },
356+
let ty = ty::mk_trait(tcx, principal.clone(), bounds.clone());
357+
Some((ty, ty::UnsizeVtable(ty::TyTrait { principal: principal.clone(),
358+
bounds: bounds.clone() },
359359
ty_a)))
360360
}
361361
(&ty::ty_struct(did_a, substs_a), &ty::ty_struct(did_b, substs_b))
@@ -458,10 +458,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
458458

459459
match a.sty {
460460
ty::ty_rptr(_, ty::mt{ty, mutbl}) => match ty.sty {
461-
ty::ty_trait(box ty::TyTrait { ref principal, bounds }) => {
461+
ty::ty_trait(box ty::TyTrait { ref principal, ref bounds }) => {
462462
debug!("mutbl={} b_mutbl={}", mutbl, b_mutbl);
463-
// FIXME what is purpose of this type `tr`?
464-
let tr = ty::mk_trait(tcx, principal.clone(), bounds);
463+
let tr = ty::mk_trait(tcx, principal.clone(), bounds.clone());
465464
try!(self.subtype(mk_ty(tr), b));
466465
Ok(Some(AdjustDerefRef(AutoDerefRef {
467466
autoderefs: 1,

branches/snap-stage3/src/librustc/middle/infer/combine.rs

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ pub trait Combine<'tcx> {
222222
};
223223
let unsafety = try!(self.unsafeties(a.unsafety, b.unsafety));
224224
let onceness = try!(self.oncenesses(a.onceness, b.onceness));
225-
let bounds = try!(self.existential_bounds(a.bounds, b.bounds));
225+
let bounds = try!(self.existential_bounds(&a.bounds, &b.bounds));
226226
let sig = try!(self.binders(&a.sig, &b.sig));
227227
let abi = try!(self.abi(a.abi, b.abi));
228228
Ok(ty::ClosureTy {
@@ -289,15 +289,61 @@ pub trait Combine<'tcx> {
289289

290290
fn oncenesses(&self, a: Onceness, b: Onceness) -> cres<'tcx, Onceness>;
291291

292+
fn projection_tys(&self,
293+
a: &ty::ProjectionTy<'tcx>,
294+
b: &ty::ProjectionTy<'tcx>)
295+
-> cres<'tcx, ty::ProjectionTy<'tcx>>
296+
{
297+
if a.item_name != b.item_name {
298+
Err(ty::terr_projection_name_mismatched(
299+
expected_found(self, a.item_name, b.item_name)))
300+
} else {
301+
let trait_ref = try!(self.trait_refs(&*a.trait_ref, &*b.trait_ref));
302+
Ok(ty::ProjectionTy { trait_ref: Rc::new(trait_ref), item_name: a.item_name })
303+
}
304+
}
305+
306+
fn projection_predicates(&self,
307+
a: &ty::ProjectionPredicate<'tcx>,
308+
b: &ty::ProjectionPredicate<'tcx>)
309+
-> cres<'tcx, ty::ProjectionPredicate<'tcx>>
310+
{
311+
let projection_ty = try!(self.projection_tys(&a.projection_ty, &b.projection_ty));
312+
let ty = try!(self.tys(a.ty, b.ty));
313+
Ok(ty::ProjectionPredicate { projection_ty: projection_ty, ty: ty })
314+
}
315+
316+
fn projection_bounds(&self,
317+
a: &Vec<ty::PolyProjectionPredicate<'tcx>>,
318+
b: &Vec<ty::PolyProjectionPredicate<'tcx>>)
319+
-> cres<'tcx, Vec<ty::PolyProjectionPredicate<'tcx>>>
320+
{
321+
// To be compatible, `a` and `b` must be for precisely the
322+
// same set of traits and item names. We always require that
323+
// projection bounds lists are sorted by trait-def-id and item-name,
324+
// so we can just iterate through the lists pairwise, so long as they are the
325+
// same length.
326+
if a.len() != b.len() {
327+
Err(ty::terr_projection_bounds_length(expected_found(self, a.len(), b.len())))
328+
} else {
329+
a.iter()
330+
.zip(b.iter())
331+
.map(|(a, b)| self.binders(a, b))
332+
.collect()
333+
}
334+
}
335+
292336
fn existential_bounds(&self,
293-
a: ty::ExistentialBounds,
294-
b: ty::ExistentialBounds)
295-
-> cres<'tcx, ty::ExistentialBounds>
337+
a: &ty::ExistentialBounds<'tcx>,
338+
b: &ty::ExistentialBounds<'tcx>)
339+
-> cres<'tcx, ty::ExistentialBounds<'tcx>>
296340
{
297341
let r = try!(self.contraregions(a.region_bound, b.region_bound));
298342
let nb = try!(self.builtin_bounds(a.builtin_bounds, b.builtin_bounds));
343+
let pb = try!(self.projection_bounds(&a.projection_bounds, &b.projection_bounds));
299344
Ok(ty::ExistentialBounds { region_bound: r,
300-
builtin_bounds: nb })
345+
builtin_bounds: nb,
346+
projection_bounds: pb })
301347
}
302348

303349
fn builtin_bounds(&self,
@@ -381,6 +427,16 @@ impl<'tcx> Combineable<'tcx> for ty::TraitRef<'tcx> {
381427
}
382428
}
383429

430+
impl<'tcx> Combineable<'tcx> for ty::ProjectionPredicate<'tcx> {
431+
fn combine<C:Combine<'tcx>>(combiner: &C,
432+
a: &ty::ProjectionPredicate<'tcx>,
433+
b: &ty::ProjectionPredicate<'tcx>)
434+
-> cres<'tcx, ty::ProjectionPredicate<'tcx>>
435+
{
436+
combiner.projection_predicates(a, b)
437+
}
438+
}
439+
384440
impl<'tcx> Combineable<'tcx> for ty::FnSig<'tcx> {
385441
fn combine<C:Combine<'tcx>>(combiner: &C,
386442
a: &ty::FnSig<'tcx>,
@@ -496,7 +552,7 @@ pub fn super_tys<'tcx, C: Combine<'tcx>>(this: &C,
496552
&ty::ty_trait(ref b_)) => {
497553
debug!("Trying to match traits {} and {}", a, b);
498554
let principal = try!(this.binders(&a_.principal, &b_.principal));
499-
let bounds = try!(this.existential_bounds(a_.bounds, b_.bounds));
555+
let bounds = try!(this.existential_bounds(&a_.bounds, &b_.bounds));
500556
Ok(ty::mk_trait(tcx, principal, bounds))
501557
}
502558

@@ -595,12 +651,8 @@ pub fn super_tys<'tcx, C: Combine<'tcx>>(this: &C,
595651
}
596652

597653
(&ty::ty_projection(ref a_data), &ty::ty_projection(ref b_data)) => {
598-
if a_data.item_name == b_data.item_name {
599-
let trait_ref = try!(this.trait_refs(&*a_data.trait_ref, &*b_data.trait_ref));
600-
Ok(ty::mk_projection(tcx, Rc::new(trait_ref), a_data.item_name))
601-
} else {
602-
Err(ty::terr_sorts(expected_found(this, a, b)))
603-
}
654+
let projection_ty = try!(this.projection_tys(a_data, b_data));
655+
Ok(ty::mk_projection(tcx, projection_ty.trait_ref, projection_ty.item_name))
604656
}
605657

606658
_ => Err(ty::terr_sorts(expected_found(this, a, b)))

0 commit comments

Comments
 (0)