Skip to content

Commit 9730370

Browse files
committed
Allow casting to mutable trait objects.
1 parent 07e087b commit 9730370

File tree

21 files changed

+162
-65
lines changed

21 files changed

+162
-65
lines changed

src/librustc/metadata/tydecode.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,9 @@ fn parse_ty(st: @mut PState, conv: conv_did) -> ty::t {
313313
let def = parse_def(st, NominalType, conv);
314314
let substs = parse_substs(st, conv);
315315
let store = parse_trait_store(st);
316+
let mt = parse_mutability(st);
316317
assert!(next(st) == ']');
317-
return ty::mk_trait(st.tcx, def, substs, store);
318+
return ty::mk_trait(st.tcx, def, substs, store, mt);
318319
}
319320
'p' => {
320321
let did = parse_def(st, TypeParameter, conv);
@@ -396,13 +397,16 @@ fn parse_ty(st: @mut PState, conv: conv_did) -> ty::t {
396397
}
397398
}
398399

399-
fn parse_mt(st: @mut PState, conv: conv_did) -> ty::mt {
400-
let mut m;
400+
fn parse_mutability(st: @mut PState) -> ast::mutability {
401401
match peek(st) {
402-
'm' => { next(st); m = ast::m_mutbl; }
403-
'?' => { next(st); m = ast::m_const; }
404-
_ => { m = ast::m_imm; }
402+
'm' => { next(st); ast::m_mutbl }
403+
'?' => { next(st); ast::m_const }
404+
_ => { ast::m_imm }
405405
}
406+
}
407+
408+
fn parse_mt(st: @mut PState, conv: conv_did) -> ty::mt {
409+
let m = parse_mutability(st);
406410
ty::mt { ty: parse_ty(st, conv), mutbl: m }
407411
}
408412

src/librustc/metadata/tyencode.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use core::io;
2222
use core::uint;
2323
use core::vec;
2424
use syntax::abi::AbiSet;
25+
use syntax::ast;
2526
use syntax::ast::*;
2627
use syntax::diagnostic::span_handler;
2728
use syntax::print::pprust::*;
@@ -113,12 +114,17 @@ pub fn enc_ty(w: @io::Writer, cx: @ctxt, t: ty::t) {
113114
}
114115
}
115116
}
116-
fn enc_mt(w: @io::Writer, cx: @ctxt, mt: ty::mt) {
117-
match mt.mutbl {
117+
118+
fn enc_mutability(w: @io::Writer, mt: ast::mutability) {
119+
match mt {
118120
m_imm => (),
119121
m_mutbl => w.write_char('m'),
120122
m_const => w.write_char('?')
121123
}
124+
}
125+
126+
fn enc_mt(w: @io::Writer, cx: @ctxt, mt: ty::mt) {
127+
enc_mutability(w, mt.mutbl);
122128
enc_ty(w, cx, mt.ty);
123129
}
124130

@@ -269,12 +275,13 @@ fn enc_sty(w: @io::Writer, cx: @ctxt, +st: ty::sty) {
269275
enc_substs(w, cx, (*substs));
270276
w.write_char(']');
271277
}
272-
ty::ty_trait(def, ref substs, store) => {
278+
ty::ty_trait(def, ref substs, store, mt) => {
273279
w.write_str(&"x[");
274280
w.write_str((cx.ds)(def));
275281
w.write_char('|');
276282
enc_substs(w, cx, (*substs));
277283
enc_trait_store(w, cx, store);
284+
enc_mutability(w, mt);
278285
w.write_char(']');
279286
}
280287
ty::ty_tup(ts) => {

src/librustc/middle/kind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ pub fn check_cast_for_escaping_regions(
589589
pub fn check_kind_bounds_of_cast(cx: Context, source: @expr, target: @expr) {
590590
let target_ty = ty::expr_ty(cx.tcx, target);
591591
match ty::get(target_ty).sty {
592-
ty::ty_trait(_, _, ty::UniqTraitStore) => {
592+
ty::ty_trait(_, _, ty::UniqTraitStore, _) => {
593593
let source_ty = ty::expr_ty(cx.tcx, source);
594594
if !ty::type_is_owned(cx.tcx, source_ty) {
595595
cx.tcx.sess.span_err(

src/librustc/middle/trans/debuginfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ fn create_ty(cx: @CrateContext, t: ty::t, span: span)
671671
ty::ty_closure(ref _closurety) => {
672672
cx.sess.span_bug(span, ~"debuginfo for closure NYI")
673673
},
674-
ty::ty_trait(_did, ref _substs, ref _vstore) => {
674+
ty::ty_trait(_did, ref _substs, ref _vstore, _) => {
675675
cx.sess.span_bug(span, ~"debuginfo for trait NYI")
676676
},
677677
ty::ty_struct(did, ref substs) => {

src/librustc/middle/trans/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr,
667667
}
668668
ast::expr_cast(val, _) => {
669669
match ty::get(node_id_type(bcx, expr.id)).sty {
670-
ty::ty_trait(_, _, store) => {
670+
ty::ty_trait(_, _, store, _) => {
671671
return meth::trans_trait_cast(bcx, val, expr.id, dest,
672672
store);
673673
}

src/librustc/middle/trans/glue.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -551,11 +551,11 @@ pub fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
551551
ty::ty_closure(_) => {
552552
closure::make_closure_glue(bcx, v0, t, drop_ty)
553553
}
554-
ty::ty_trait(_, _, ty::BoxTraitStore) => {
554+
ty::ty_trait(_, _, ty::BoxTraitStore, _) => {
555555
let llbox = Load(bcx, GEPi(bcx, v0, [0u, 1u]));
556556
decr_refcnt_maybe_free(bcx, llbox, ty::mk_opaque_box(ccx.tcx))
557557
}
558-
ty::ty_trait(_, _, ty::UniqTraitStore) => {
558+
ty::ty_trait(_, _, ty::UniqTraitStore, _) => {
559559
let lluniquevalue = GEPi(bcx, v0, [0, 1]);
560560
let lltydesc = Load(bcx, GEPi(bcx, v0, [0, 2]));
561561
call_tydesc_glue_full(bcx, lluniquevalue, lltydesc,
@@ -617,12 +617,12 @@ pub fn make_take_glue(bcx: block, v: ValueRef, t: ty::t) {
617617
ty::ty_closure(_) => {
618618
closure::make_closure_glue(bcx, v, t, take_ty)
619619
}
620-
ty::ty_trait(_, _, ty::BoxTraitStore) => {
620+
ty::ty_trait(_, _, ty::BoxTraitStore, _) => {
621621
let llbox = Load(bcx, GEPi(bcx, v, [0u, 1u]));
622622
incr_refcnt_of_boxed(bcx, llbox);
623623
bcx
624624
}
625-
ty::ty_trait(_, _, ty::UniqTraitStore) => {
625+
ty::ty_trait(_, _, ty::UniqTraitStore, _) => {
626626
let llval = GEPi(bcx, v, [0, 1]);
627627
let lltydesc = Load(bcx, GEPi(bcx, v, [0, 2]));
628628
call_tydesc_glue_full(bcx, llval, lltydesc,

src/librustc/middle/trans/monomorphize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ pub fn normalize_for_monomorphization(tcx: ty::ctxt,
303303
ty::ty_closure(ref fty) => {
304304
Some(normalized_closure_ty(tcx, fty.sigil))
305305
}
306-
ty::ty_trait(_, _, ref store) => {
306+
ty::ty_trait(_, _, ref store, _) => {
307307
let sigil = match *store {
308308
ty::UniqTraitStore => ast::OwnedSigil,
309309
ty::BoxTraitStore => ast::ManagedSigil,

src/librustc/middle/trans/reflect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ pub impl Reflector {
323323
}
324324

325325
// Miscallaneous extra types
326-
ty::ty_trait(_, _, _) => self.leaf(~"trait"),
326+
ty::ty_trait(_, _, _, _) => self.leaf(~"trait"),
327327
ty::ty_infer(_) => self.leaf(~"infer"),
328328
ty::ty_err => self.leaf(~"err"),
329329
ty::ty_param(ref p) => {

src/librustc/middle/trans/type_of.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub fn sizing_type_of(cx: @CrateContext, t: ty::t) -> TypeRef {
133133

134134
ty::ty_bare_fn(*) => T_ptr(T_i8()),
135135
ty::ty_closure(*) => T_struct(~[T_ptr(T_i8()), T_ptr(T_i8())], false),
136-
ty::ty_trait(_, _, store) => T_opaque_trait(cx, store),
136+
ty::ty_trait(_, _, store, _) => T_opaque_trait(cx, store),
137137

138138
ty::ty_estr(ty::vstore_fixed(size)) => T_array(T_i8(), size),
139139
ty::ty_evec(mt, ty::vstore_fixed(size)) => {
@@ -249,7 +249,7 @@ pub fn type_of(cx: @CrateContext, t: ty::t) -> TypeRef {
249249

250250
ty::ty_bare_fn(_) => T_ptr(type_of_fn_from_ty(cx, t)),
251251
ty::ty_closure(_) => T_fn_pair(cx, type_of_fn_from_ty(cx, t)),
252-
ty::ty_trait(_, _, store) => T_opaque_trait(cx, store),
252+
ty::ty_trait(_, _, store, _) => T_opaque_trait(cx, store),
253253
ty::ty_type => T_ptr(cx.tydesc_type),
254254
ty::ty_tup(*) => {
255255
let repr = adt::represent_type(cx, t);

src/librustc/middle/trans/type_use.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ pub fn type_needs_inner(cx: Context,
216216
ty::ty_bare_fn(*) |
217217
ty::ty_ptr(_) |
218218
ty::ty_rptr(_, _) |
219-
ty::ty_trait(_, _, _) => false,
219+
ty::ty_trait(_, _, _, _) => false,
220220

221221
ty::ty_enum(did, ref substs) => {
222222
if list::find(enums_seen, |id| *id == did).is_none() {

0 commit comments

Comments
 (0)