]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/middle/ty.rs
rustc: Remove `&str` indexing from the language.
[rust.git] / src / librustc / middle / ty.rs
index 8d84d089c01b2adff75514cf313a74df9196d7b6..04aa7ac8bfd745632ba0ddd40330b60925166ee6 100644 (file)
@@ -2551,6 +2551,21 @@ pub fn deref(t: t, explicit: bool) -> Option<mt> {
 
 // Returns the type of t[i]
 pub fn index(t: t) -> Option<mt> {
+    match get(t).sty {
+        ty_vec(mt, Some(_)) => Some(mt),
+        ty_ptr(mt{ty: t, ..}) | ty_rptr(_, mt{ty: t, ..}) |
+        ty_box(t) | ty_uniq(t) => match get(t).sty {
+            ty_vec(mt, None) => Some(mt),
+            _ => None,
+        },
+        _ => None
+    }
+}
+
+// Returns the type of elements contained within an 'array-like' type.
+// This is exactly the same as the above, except it supports strings,
+// which can't actually be indexed.
+pub fn array_element_ty(t: t) -> Option<mt> {
     match get(t).sty {
         ty_vec(mt, Some(_)) => Some(mt),
         ty_ptr(mt{ty: t, ..}) | ty_rptr(_, mt{ty: t, ..}) |