Skip to content

Commit 6f31981

Browse files
committed
ty: Add (but do not yet use) AutoBorrowObject option to adjustments
Note: some portions of this commit written by @Sodel-the-Vociferous (Daniel Ralston)
1 parent 38357eb commit 6f31981

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

src/librustc/middle/ty.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,10 @@ pub enum AutoRef {
226226
AutoBorrowFn(Region),
227227

228228
/// Convert from T to *T
229-
AutoUnsafe(ast::mutability)
229+
AutoUnsafe(ast::mutability),
230+
231+
/// Convert from @Trait/~Trait/&Trait to &Trait
232+
AutoBorrowObj(Region, ast::mutability),
230233
}
231234

232235
pub type ctxt = @ctxt_;
@@ -1004,7 +1007,13 @@ fn mk_t(cx: ctxt, st: sty) -> t {
10041007
&ty_self(_) => flags |= has_self as uint,
10051008
&ty_enum(_, ref substs) | &ty_struct(_, ref substs) |
10061009
&ty_trait(_, ref substs, _, _, _) => {
1007-
flags |= sflags(substs);
1010+
flags |= sflags(substs);
1011+
match st {
1012+
ty_trait(_, _, RegionTraitStore(r), _, _) => {
1013+
flags |= rflags(r);
1014+
}
1015+
_ => {}
1016+
}
10081017
}
10091018
&ty_box(ref m) | &ty_uniq(ref m) | &ty_evec(ref m, _) |
10101019
&ty_ptr(ref m) | &ty_unboxed_vec(ref m) => {
@@ -3009,6 +3018,10 @@ pub fn adjust_ty(cx: ctxt,
30093018
AutoUnsafe(m) => {
30103019
mk_ptr(cx, mt {ty: adjusted_ty, mutbl: m})
30113020
}
3021+
3022+
AutoBorrowObj(r, m) => {
3023+
borrow_obj(cx, span, r, m, adjusted_ty)
3024+
}
30123025
}
30133026
}
30143027
}
@@ -3054,6 +3067,22 @@ pub fn adjust_ty(cx: ctxt,
30543067
}
30553068
}
30563069
}
3070+
3071+
fn borrow_obj(cx: ctxt, span: span, r: Region,
3072+
m: ast::mutability, ty: ty::t) -> ty::t {
3073+
match get(ty).sty {
3074+
ty_trait(trt_did, ref trt_substs, _, _, b) => {
3075+
ty::mk_trait(cx, trt_did, trt_substs.clone(),
3076+
RegionTraitStore(r), m, b)
3077+
}
3078+
ref s => {
3079+
cx.sess.span_bug(
3080+
span,
3081+
fmt!("borrow-trait-obj associated with bad sty: %?",
3082+
s));
3083+
}
3084+
}
3085+
}
30573086
}
30583087

30593088
impl AutoRef {
@@ -3064,6 +3093,7 @@ impl AutoRef {
30643093
ty::AutoBorrowVecRef(r, m) => ty::AutoBorrowVecRef(f(r), m),
30653094
ty::AutoBorrowFn(r) => ty::AutoBorrowFn(f(r)),
30663095
ty::AutoUnsafe(m) => ty::AutoUnsafe(m),
3096+
ty::AutoBorrowObj(r, m) => ty::AutoBorrowObj(f(r), m),
30673097
}
30683098
}
30693099
}

0 commit comments

Comments
 (0)