Skip to content

Commit cc1f002

Browse files
committed
repr: add support for trait objects
Closes #8916
1 parent 7a52154 commit cc1f002

File tree

6 files changed

+20
-13
lines changed

6 files changed

+20
-13
lines changed

src/librustc/middle/trans/reflect.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ impl Reflector {
146146
// Entrypoint
147147
pub fn visit_ty(&mut self, t: ty::t) {
148148
let bcx = self.bcx;
149+
let tcx = bcx.ccx().tcx;
149150
debug!("reflect::visit_ty %s", ty_to_str(bcx.ccx().tcx, t));
150151

151152
match ty::get(t).sty {
@@ -248,8 +249,6 @@ impl Reflector {
248249
}
249250

250251
ty::ty_struct(did, ref substs) => {
251-
let bcx = self.bcx;
252-
let tcx = bcx.ccx().tcx;
253252
let fields = ty::struct_fields(tcx, did, substs);
254253

255254
let extra = ~[self.c_slice(ty_to_str(tcx, t).to_managed()),
@@ -270,7 +269,6 @@ impl Reflector {
270269
// let the visitor tell us if it wants to visit only a particular
271270
// variant?
272271
ty::ty_enum(did, ref substs) => {
273-
let bcx = self.bcx;
274272
let ccx = bcx.ccx();
275273
let repr = adt::represent_type(bcx.ccx(), t);
276274
let variants = ty::substd_enum_variants(ccx.tcx, did, substs);
@@ -336,8 +334,12 @@ impl Reflector {
336334
}
337335
}
338336

339-
// Miscallaneous extra types
340-
ty::ty_trait(_, _, _, _, _) => self.leaf("trait"),
337+
ty::ty_trait(_, _, _, _, _) => {
338+
let extra = [self.c_slice(ty_to_str(tcx, t).to_managed())];
339+
self.visit("trait", extra);
340+
}
341+
342+
// Miscellaneous extra types
341343
ty::ty_infer(_) => self.leaf("infer"),
342344
ty::ty_err => self.leaf("err"),
343345
ty::ty_param(ref p) => {

src/libstd/reflect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,9 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
450450
true
451451
}
452452

453-
fn visit_trait(&mut self) -> bool {
453+
fn visit_trait(&mut self, name: &str) -> bool {
454454
self.align_to::<@TyVisitor>();
455-
if ! self.inner.visit_trait() { return false; }
455+
if ! self.inner.visit_trait(name) { return false; }
456456
self.bump_past::<@TyVisitor>();
457457
true
458458
}

src/libstd/repr.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,11 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
571571
_n_inputs: uint, _retstyle: uint) -> bool { true }
572572

573573

574-
fn visit_trait(&mut self) -> bool { true }
574+
fn visit_trait(&mut self, name: &str) -> bool {
575+
self.writer.write(name.as_bytes());
576+
true
577+
}
578+
575579
fn visit_param(&mut self, _i: uint) -> bool { true }
576580
fn visit_self(&mut self) -> bool { true }
577581
fn visit_type(&mut self) -> bool { true }
@@ -661,6 +665,7 @@ fn test_repr() {
661665
"(10u64, ~\"hello\")");
662666

663667
exact_test(&(&println), "&fn()");
668+
exact_test(&(~5 as ~ToStr), "~to_str::ToStr:Send");
664669

665670
struct Foo;
666671
exact_test(&(~[Foo, Foo]), "~[repr::test_repr::Foo, repr::test_repr::Foo]");

src/libstd/unstable/intrinsics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ pub trait TyVisitor {
256256
fn visit_leave_fn(&mut self, purity: uint, proto: uint,
257257
n_inputs: uint, retstyle: uint) -> bool;
258258

259-
fn visit_trait(&mut self) -> bool;
259+
fn visit_trait(&mut self, name: &str) -> bool;
260260
fn visit_param(&mut self, i: uint) -> bool;
261261
fn visit_self(&mut self) -> bool;
262262
fn visit_type(&mut self) -> bool;

src/test/run-pass/reflect-visit-data.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,9 @@ impl<V:TyVisitor + movable_ptr> TyVisitor for ptr_visit_adaptor<V> {
428428
true
429429
}
430430

431-
fn visit_trait(&mut self) -> bool {
431+
fn visit_trait(&mut self, name: &str) -> bool {
432432
self.align_to::<@TyVisitor>();
433-
if ! self.inner.visit_trait() { return false; }
433+
if ! self.inner.visit_trait(name) { return false; }
434434
self.bump_past::<@TyVisitor>();
435435
true
436436
}
@@ -616,7 +616,7 @@ impl TyVisitor for my_visitor {
616616
_n_inputs: uint, _retstyle: uint) -> bool { true }
617617

618618

619-
fn visit_trait(&mut self) -> bool { true }
619+
fn visit_trait(&mut self, _name: &str) -> bool { true }
620620
fn visit_param(&mut self, _i: uint) -> bool { true }
621621
fn visit_self(&mut self) -> bool { true }
622622
fn visit_type(&mut self) -> bool { true }

src/test/run-pass/reflect-visit-type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl TyVisitor for MyVisitor {
139139
_n_inputs: uint, _retstyle: uint) -> bool { true }
140140

141141

142-
fn visit_trait(&mut self) -> bool { true }
142+
fn visit_trait(&mut self, _name: &str) -> bool { true }
143143
fn visit_param(&mut self, _i: uint) -> bool { true }
144144
fn visit_self(&mut self) -> bool { true }
145145
fn visit_type(&mut self) -> bool { true }

0 commit comments

Comments
 (0)