about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2013-08-11 13:39:05 -0400
committerNiko Matsakis <niko@alum.mit.edu>2013-08-11 14:01:19 -0400
commit6f319812d602fb1d6558b583b80a9326f1cc14b3 (patch)
tree3ef4db61eeaab07b3283c4cf8b71a9787c4ce615
parent38357ebef48aba5ac134dbc32adb445a08db1e20 (diff)
downloadrust-6f319812d602fb1d6558b583b80a9326f1cc14b3.tar.gz
rust-6f319812d602fb1d6558b583b80a9326f1cc14b3.zip
ty: Add (but do not yet use) AutoBorrowObject option to adjustments
Note: some portions of this commit written by @Sodel-the-Vociferous
(Daniel Ralston)
-rw-r--r--src/librustc/middle/ty.rs34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs
index b91984f9b21..720c6ab96b6 100644
--- a/src/librustc/middle/ty.rs
+++ b/src/librustc/middle/ty.rs
@@ -226,7 +226,10 @@ pub enum AutoRef {
     AutoBorrowFn(Region),
 
     /// Convert from T to *T
-    AutoUnsafe(ast::mutability)
+    AutoUnsafe(ast::mutability),
+
+    /// Convert from @Trait/~Trait/&Trait to &Trait
+    AutoBorrowObj(Region, ast::mutability),
 }
 
 pub type ctxt = @ctxt_;
@@ -1004,7 +1007,13 @@ fn mk_t(cx: ctxt, st: sty) -> t {
       &ty_self(_) => flags |= has_self as uint,
       &ty_enum(_, ref substs) | &ty_struct(_, ref substs) |
       &ty_trait(_, ref substs, _, _, _) => {
-        flags |= sflags(substs);
+          flags |= sflags(substs);
+          match st {
+              ty_trait(_, _, RegionTraitStore(r), _, _) => {
+                    flags |= rflags(r);
+                }
+              _ => {}
+          }
       }
       &ty_box(ref m) | &ty_uniq(ref m) | &ty_evec(ref m, _) |
       &ty_ptr(ref m) | &ty_unboxed_vec(ref m) => {
@@ -3009,6 +3018,10 @@ pub fn adjust_ty(cx: ctxt,
                         AutoUnsafe(m) => {
                             mk_ptr(cx, mt {ty: adjusted_ty, mutbl: m})
                         }
+
+                        AutoBorrowObj(r, m) => {
+                            borrow_obj(cx, span, r, m, adjusted_ty)
+                        }
                     }
                 }
             }
@@ -3054,6 +3067,22 @@ pub fn adjust_ty(cx: ctxt,
             }
         }
     }
+
+    fn borrow_obj(cx: ctxt, span: span, r: Region,
+                  m: ast::mutability, ty: ty::t) -> ty::t {
+        match get(ty).sty {
+            ty_trait(trt_did, ref trt_substs, _, _, b) => {
+                ty::mk_trait(cx, trt_did, trt_substs.clone(),
+                             RegionTraitStore(r), m, b)
+            }
+            ref s => {
+                cx.sess.span_bug(
+                    span,
+                    fmt!("borrow-trait-obj associated with bad sty: %?",
+                         s));
+            }
+        }
+    }
 }
 
 impl AutoRef {
@@ -3064,6 +3093,7 @@ impl AutoRef {
             ty::AutoBorrowVecRef(r, m) => ty::AutoBorrowVecRef(f(r), m),
             ty::AutoBorrowFn(r) => ty::AutoBorrowFn(f(r)),
             ty::AutoUnsafe(m) => ty::AutoUnsafe(m),
+            ty::AutoBorrowObj(r, m) => ty::AutoBorrowObj(f(r), m),
         }
     }
 }