Skip to content

Commit 3cf0fbe

Browse files
committed
Create distinct types for a PolyTraitRef (with bindings) and a normal TraitRef.
1 parent b3dcb85 commit 3cf0fbe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+516
-469
lines changed

src/librustc/lint/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1785,7 +1785,7 @@ impl LintPass for Stability {
17851785
..
17861786
}) => {
17871787
ty::trait_item(cx.tcx,
1788-
trait_ref.def_id,
1788+
trait_ref.def_id(),
17891789
index).def_id()
17901790
}
17911791
}

src/librustc/metadata/csearch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ pub fn get_field_type<'tcx>(tcx: &ty::ctxt<'tcx>, class_id: ast::DefId,
262262
// if there is one.
263263
pub fn get_impl_trait<'tcx>(tcx: &ty::ctxt<'tcx>,
264264
def: ast::DefId)
265-
-> Option<Rc<ty::TraitRef<'tcx>>> {
265+
-> Option<Rc<ty::PolyTraitRef<'tcx>>> {
266266
let cstore = &tcx.sess.cstore;
267267
let cdata = cstore.get_crate_data(def.krate);
268268
decoder::get_impl_trait(&*cdata, def.node, tcx)

src/librustc/metadata/decoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,11 @@ pub fn get_repr_attrs(cdata: Cmd, id: ast::NodeId) -> Vec<attr::ReprAttr> {
425425
pub fn get_impl_trait<'tcx>(cdata: Cmd,
426426
id: ast::NodeId,
427427
tcx: &ty::ctxt<'tcx>)
428-
-> Option<Rc<ty::TraitRef<'tcx>>>
428+
-> Option<Rc<ty::PolyTraitRef<'tcx>>>
429429
{
430430
let item_doc = lookup_item(id, cdata.data());
431431
reader::maybe_get_doc(item_doc, tag_item_trait_ref).map(|tp| {
432-
Rc::new(doc_trait_ref(tp, tcx, cdata))
432+
Rc::new(ty::bind(doc_trait_ref(tp, tcx, cdata)))
433433
})
434434
}
435435

src/librustc/metadata/tydecode.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ fn parse_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> Ty<'tcx> {
414414
}
415415
'x' => {
416416
assert_eq!(next(st), '[');
417-
let trait_ref = parse_trait_ref(st, |x,y| conv(x,y));
417+
let trait_ref = ty::bind(parse_trait_ref(st, |x,y| conv(x,y)));
418418
let bounds = parse_existential_bounds(st, |x,y| conv(x,y));
419419
assert_eq!(next(st), ']');
420420
return ty::mk_trait(st.tcx, trait_ref, bounds);
@@ -669,7 +669,7 @@ pub fn parse_predicate<'a,'tcx>(st: &mut PState<'a, 'tcx>,
669669
-> ty::Predicate<'tcx>
670670
{
671671
match next(st) {
672-
't' => ty::Predicate::Trait(Rc::new(parse_trait_ref(st, conv))),
672+
't' => ty::Predicate::Trait(Rc::new(ty::bind(parse_trait_ref(st, conv)))),
673673
'e' => ty::Predicate::Equate(parse_ty(st, |x,y| conv(x,y)),
674674
parse_ty(st, |x,y| conv(x,y))),
675675
'r' => ty::Predicate::RegionOutlives(parse_region(st, |x,y| conv(x,y)),
@@ -759,10 +759,12 @@ fn parse_bounds<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did)
759759
loop {
760760
match next(st) {
761761
'R' => {
762-
param_bounds.region_bounds.push(parse_region(st, |x, y| conv (x, y)));
762+
param_bounds.region_bounds.push(
763+
parse_region(st, |x, y| conv (x, y)));
763764
}
764765
'I' => {
765-
param_bounds.trait_bounds.push(Rc::new(parse_trait_ref(st, |x,y| conv(x,y))));
766+
param_bounds.trait_bounds.push(
767+
Rc::new(ty::bind(parse_trait_ref(st, |x,y| conv(x,y)))));
766768
}
767769
'.' => {
768770
return param_bounds;

src/librustc/metadata/tyencode.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ fn enc_sty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
251251
ty::ty_trait(box ty::TyTrait { ref principal,
252252
ref bounds }) => {
253253
mywrite!(w, "x[");
254-
enc_trait_ref(w, cx, principal);
254+
enc_trait_ref(w, cx, &principal.value);
255255
enc_existential_bounds(w, cx, bounds);
256256
mywrite!(w, "]");
257257
}
@@ -401,7 +401,7 @@ pub fn enc_bounds<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
401401

402402
for tp in bs.trait_bounds.iter() {
403403
mywrite!(w, "I");
404-
enc_trait_ref(w, cx, &**tp);
404+
enc_trait_ref(w, cx, &tp.value);
405405
}
406406

407407
mywrite!(w, ".");
@@ -425,7 +425,7 @@ pub fn enc_predicate<'a, 'tcx>(w: &mut SeekableMemWriter,
425425
match *p {
426426
ty::Predicate::Trait(ref trait_ref) => {
427427
mywrite!(w, "t");
428-
enc_trait_ref(w, cx, &**trait_ref);
428+
enc_trait_ref(w, cx, &trait_ref.value);
429429
}
430430
ty::Predicate::Equate(a, b) => {
431431
mywrite!(w, "e");

src/librustc/middle/astencode.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> {
887887
this.emit_enum_variant("MethodTypeParam", 2, 1, |this| {
888888
this.emit_struct("MethodParam", 2, |this| {
889889
try!(this.emit_struct_field("trait_ref", 0, |this| {
890-
Ok(this.emit_trait_ref(ecx, &*p.trait_ref))
890+
Ok(this.emit_trait_ref(ecx, &p.trait_ref.value))
891891
}));
892892
try!(this.emit_struct_field("method_num", 0, |this| {
893893
this.emit_uint(p.method_num)
@@ -901,7 +901,7 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> {
901901
this.emit_enum_variant("MethodTraitObject", 3, 1, |this| {
902902
this.emit_struct("MethodObject", 2, |this| {
903903
try!(this.emit_struct_field("trait_ref", 0, |this| {
904-
Ok(this.emit_trait_ref(ecx, &*o.trait_ref))
904+
Ok(this.emit_trait_ref(ecx, &o.trait_ref.value))
905905
}));
906906
try!(this.emit_struct_field("object_trait_id", 0, |this| {
907907
Ok(this.emit_def_id(o.object_trait_id))
@@ -1113,7 +1113,7 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> {
11131113
this.emit_enum_variant("UnsizeVtable", 2, 4, |this| {
11141114
this.emit_enum_variant_arg(0, |this| {
11151115
try!(this.emit_struct_field("principal", 0, |this| {
1116-
Ok(this.emit_trait_ref(ecx, &*principal))
1116+
Ok(this.emit_trait_ref(ecx, &principal.value))
11171117
}));
11181118
this.emit_struct_field("bounds", 1, |this| {
11191119
Ok(this.emit_existential_bounds(ecx, b))
@@ -1277,7 +1277,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
12771277
rbml_w.tag(c::tag_table_object_cast_map, |rbml_w| {
12781278
rbml_w.id(id);
12791279
rbml_w.tag(c::tag_table_val, |rbml_w| {
1280-
rbml_w.emit_trait_ref(ecx, &**trait_ref);
1280+
rbml_w.emit_trait_ref(ecx, &trait_ref.value);
12811281
})
12821282
})
12831283
}
@@ -1356,6 +1356,8 @@ trait rbml_decoder_decoder_helpers<'tcx> {
13561356
fn read_tys<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) -> Vec<Ty<'tcx>>;
13571357
fn read_trait_ref<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
13581358
-> Rc<ty::TraitRef<'tcx>>;
1359+
fn read_poly_trait_ref<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
1360+
-> Rc<ty::PolyTraitRef<'tcx>>;
13591361
fn read_type_param_def<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
13601362
-> ty::TypeParameterDef<'tcx>;
13611363
fn read_predicate<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
@@ -1455,7 +1457,7 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
14551457
ty::MethodParam {
14561458
trait_ref: {
14571459
this.read_struct_field("trait_ref", 0, |this| {
1458-
Ok(this.read_trait_ref(dcx))
1460+
Ok(this.read_poly_trait_ref(dcx))
14591461
}).unwrap()
14601462
},
14611463
method_num: {
@@ -1473,7 +1475,7 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
14731475
ty::MethodObject {
14741476
trait_ref: {
14751477
this.read_struct_field("trait_ref", 0, |this| {
1476-
Ok(this.read_trait_ref(dcx))
1478+
Ok(this.read_poly_trait_ref(dcx))
14771479
}).unwrap()
14781480
},
14791481
object_trait_id: {
@@ -1548,6 +1550,19 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
15481550
}).unwrap())
15491551
}
15501552

1553+
fn read_poly_trait_ref<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
1554+
-> Rc<ty::PolyTraitRef<'tcx>> {
1555+
Rc::new(ty::bind(self.read_opaque(|this, doc| {
1556+
let ty = tydecode::parse_trait_ref_data(
1557+
doc.data,
1558+
dcx.cdata.cnum,
1559+
doc.start,
1560+
dcx.tcx,
1561+
|s, a| this.convert_def_id(dcx, s, a));
1562+
Ok(ty)
1563+
}).unwrap()))
1564+
}
1565+
15511566
fn read_type_param_def<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
15521567
-> ty::TypeParameterDef<'tcx> {
15531568
self.read_opaque(|this, doc| {
@@ -1753,7 +1768,7 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
17531768
2 => {
17541769
let ty_trait = try!(this.read_enum_variant_arg(0, |this| {
17551770
let principal = try!(this.read_struct_field("principal", 0, |this| {
1756-
Ok(this.read_trait_ref(dcx))
1771+
Ok(this.read_poly_trait_ref(dcx))
17571772
}));
17581773
Ok(ty::TyTrait {
17591774
principal: (*principal).clone(),
@@ -1926,7 +1941,7 @@ fn decode_side_tables(dcx: &DecodeContext,
19261941
dcx.tcx.method_map.borrow_mut().insert(method_call, method);
19271942
}
19281943
c::tag_table_object_cast_map => {
1929-
let trait_ref = val_dsr.read_trait_ref(dcx);
1944+
let trait_ref = val_dsr.read_poly_trait_ref(dcx);
19301945
dcx.tcx.object_cast_map.borrow_mut()
19311946
.insert(id, trait_ref);
19321947
}

src/librustc/middle/check_static.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use middle::infer;
3131
use middle::traits;
3232
use middle::mem_categorization as mc;
3333
use middle::expr_use_visitor as euv;
34-
use util::common::ErrorReported;
3534
use util::nodemap::NodeSet;
3635

3736
use syntax::ast;
@@ -122,17 +121,12 @@ impl<'a, 'tcx> CheckStaticVisitor<'a, 'tcx> {
122121
let ty = ty::node_id_to_type(self.tcx, e.id);
123122
let infcx = infer::new_infer_ctxt(self.tcx);
124123
let mut fulfill_cx = traits::FulfillmentContext::new();
125-
match traits::trait_ref_for_builtin_bound(self.tcx, ty::BoundSync, ty) {
126-
Ok(trait_ref) => {
127-
fulfill_cx.register_trait_ref(self.tcx, trait_ref,
128-
traits::ObligationCause::dummy());
129-
let env = ty::empty_parameter_environment();
130-
if !fulfill_cx.select_all_or_error(&infcx, &env, self.tcx).is_ok() {
131-
self.tcx.sess.span_err(e.span, "shared static items must have a \
132-
type which implements Sync");
133-
}
134-
}
135-
Err(ErrorReported) => { }
124+
fulfill_cx.register_builtin_bound(self.tcx, ty, ty::BoundSync,
125+
traits::ObligationCause::dummy());
126+
let env = ty::empty_parameter_environment();
127+
if !fulfill_cx.select_all_or_error(&infcx, &env, self.tcx).is_ok() {
128+
self.tcx.sess.span_err(e.span, "shared static items must have a \
129+
type which implements Sync");
136130
}
137131
}
138132
}

src/librustc/middle/dead.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
112112
..
113113
}) => {
114114
let trait_item = ty::trait_item(self.tcx,
115-
trait_ref.def_id,
115+
trait_ref.def_id(),
116116
index);
117117
match trait_item {
118118
ty::MethodTraitItem(method) => {

src/librustc/middle/expr_use_visitor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl OverloadedCallType {
265265
}
266266
Some(ref trait_ref) => (*trait_ref).clone(),
267267
};
268-
OverloadedCallType::from_trait_id(tcx, trait_ref.def_id)
268+
OverloadedCallType::from_trait_id(tcx, trait_ref.value.def_id)
269269
}
270270

271271
fn from_unboxed_closure(tcx: &ty::ctxt, closure_did: ast::DefId)
@@ -292,7 +292,7 @@ impl OverloadedCallType {
292292
}
293293
MethodTypeParam(MethodParam { ref trait_ref, .. }) |
294294
MethodTraitObject(MethodObject { ref trait_ref, .. }) => {
295-
OverloadedCallType::from_trait_id(tcx, trait_ref.def_id)
295+
OverloadedCallType::from_trait_id(tcx, trait_ref.def_id())
296296
}
297297
}
298298
}

src/librustc/middle/fast_reject.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn simplify_type(tcx: &ty::ctxt,
6060
ty::ty_vec(..) => Some(VecSimplifiedType),
6161
ty::ty_ptr(_) => Some(PtrSimplifiedType),
6262
ty::ty_trait(ref trait_info) => {
63-
Some(TraitSimplifiedType(trait_info.principal.def_id))
63+
Some(TraitSimplifiedType(trait_info.principal.value.def_id))
6464
}
6565
ty::ty_struct(def_id, _) => {
6666
Some(StructSimplifiedType(def_id))

0 commit comments

Comments
 (0)