From 449a7a817ff58288084b49665d5186674255c949 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 31 Jan 2014 16:50:45 -0800 Subject: libextra: Remove `@str` from all the libraries --- src/libstd/at_vec.rs | 1 - src/libstd/fmt/mod.rs | 1 - src/libstd/path/mod.rs | 13 ----- src/libstd/path/posix.rs | 2 - src/libstd/path/windows.rs | 2 - src/libstd/reflect.rs | 3 -- src/libstd/repr.rs | 6 +-- src/libstd/send_str.rs | 2 - src/libstd/str.rs | 130 ++++----------------------------------------- src/libstd/to_bytes.rs | 7 --- src/libstd/to_str.rs | 1 - src/libstd/unstable/raw.rs | 1 - 12 files changed, 12 insertions(+), 157 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/at_vec.rs b/src/libstd/at_vec.rs index 55e90248e1c..6a3c74482d3 100644 --- a/src/libstd/at_vec.rs +++ b/src/libstd/at_vec.rs @@ -338,7 +338,6 @@ mod test { assert_eq!(to_managed::([]), @[]); assert_eq!(to_managed([true]), @[true]); assert_eq!(to_managed([1, 2, 3, 4, 5]), @[1, 2, 3, 4, 5]); - assert_eq!(to_managed([@"abc", @"123"]), @[@"abc", @"123"]); assert_eq!(to_managed([@[42]]), @[@[42]]); } diff --git a/src/libstd/fmt/mod.rs b/src/libstd/fmt/mod.rs index 111eb70eb20..13e6d808095 100644 --- a/src/libstd/fmt/mod.rs +++ b/src/libstd/fmt/mod.rs @@ -1167,7 +1167,6 @@ delegate!( u8 to Unsigned) delegate!( u16 to Unsigned) delegate!( u32 to Unsigned) delegate!( u64 to Unsigned) -delegate!(@str to String) delegate!(~str to String) delegate!(&'a str to String) delegate!(bool to Bool) diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index 11f23b22c51..2282f97a716 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -604,19 +604,6 @@ impl BytesContainer for ~str { fn is_str(_: Option<~str>) -> bool { true } } -impl BytesContainer for @str { - #[inline] - fn container_as_bytes<'a>(&'a self) -> &'a [u8] { - self.as_bytes() - } - #[inline] - fn container_as_str<'a>(&'a self) -> Option<&'a str> { - Some(self.as_slice()) - } - #[inline] - fn is_str(_: Option<@str>) -> bool { true } -} - impl<'a> BytesContainer for &'a [u8] { #[inline] fn container_as_bytes<'a>(&'a self) -> &'a [u8] { diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 707ba18378a..b6506b51786 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -830,7 +830,6 @@ mod tests { t!(s: "a/b/c", ["d", "/e"], "/e"); t!(s: "a/b/c", ["d", "/e", "f"], "/e/f"); t!(s: "a/b/c", [~"d", ~"e"], "a/b/c/d/e"); - t!(s: "a/b/c", [@"d", @"e"], "a/b/c/d/e"); t!(v: b!("a/b/c"), [b!("d"), b!("e")], b!("a/b/c/d/e")); t!(v: b!("a/b/c"), [b!("d"), b!("/e"), b!("f")], b!("/e/f")); t!(v: b!("a/b/c"), [b!("d").to_owned(), b!("e").to_owned()], b!("a/b/c/d/e")); @@ -940,7 +939,6 @@ mod tests { t!(s: "a/b/c", ["..", "d"], "a/b/d"); t!(s: "a/b/c", ["d", "/e", "f"], "/e/f"); t!(s: "a/b/c", [~"d", ~"e"], "a/b/c/d/e"); - t!(s: "a/b/c", [@"d", @"e"], "a/b/c/d/e"); t!(v: b!("a/b/c"), [b!("d"), b!("e")], b!("a/b/c/d/e")); t!(v: b!("a/b/c"), [b!("d").to_owned(), b!("e").to_owned()], b!("a/b/c/d/e")); t!(v: b!("a/b/c"), [to_man(b!("d").to_owned()), to_man(b!("e").to_owned())], diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index a07471afc1a..2578acaf41c 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -1610,7 +1610,6 @@ mod tests { t!(s: "a\\b\\c", ["d", "\\e"], "\\e"); t!(s: "a\\b\\c", ["d", "\\e", "f"], "\\e\\f"); t!(s: "a\\b\\c", [~"d", ~"e"], "a\\b\\c\\d\\e"); - t!(s: "a\\b\\c", [@"d", @"e"], "a\\b\\c\\d\\e"); t!(v: b!("a\\b\\c"), [b!("d"), b!("e")], b!("a\\b\\c\\d\\e")); t!(v: b!("a\\b\\c"), [b!("d"), b!("\\e"), b!("f")], b!("\\e\\f")); t!(v: b!("a\\b\\c"), [b!("d").to_owned(), b!("e").to_owned()], b!("a\\b\\c\\d\\e")); @@ -1755,7 +1754,6 @@ mod tests { t!(s: "a\\b\\c", ["..", "d"], "a\\b\\d"); t!(s: "a\\b\\c", ["d", "\\e", "f"], "\\e\\f"); t!(s: "a\\b\\c", [~"d", ~"e"], "a\\b\\c\\d\\e"); - t!(s: "a\\b\\c", [@"d", @"e"], "a\\b\\c\\d\\e"); t!(v: b!("a\\b\\c"), [b!("d"), b!("e")], b!("a\\b\\c\\d\\e")); t!(v: b!("a\\b\\c"), [b!("d").to_owned(), b!("e").to_owned()], b!("a\\b\\c\\d\\e")); t!(v: b!("a\\b\\c"), [to_man(b!("d").to_owned()), to_man(b!("e").to_owned())], diff --git a/src/libstd/reflect.rs b/src/libstd/reflect.rs index 87655f5911f..d0b0f0c264d 100644 --- a/src/libstd/reflect.rs +++ b/src/libstd/reflect.rs @@ -183,9 +183,6 @@ impl TyVisitor for MovePtrAdaptor { } fn visit_estr_box(&mut self) -> bool { - self.align_to::<@str>(); - if ! self.inner.visit_estr_box() { return false; } - self.bump_past::<@str>(); true } diff --git a/src/libstd/repr.rs b/src/libstd/repr.rs index 1ecc31ec2f4..8ecb3395542 100644 --- a/src/libstd/repr.rs +++ b/src/libstd/repr.rs @@ -272,10 +272,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> { } fn visit_estr_box(&mut self) -> bool { - self.get::<@str>(|this, s| { - this.writer.write(['@' as u8]); - this.write_escaped_slice(*s); - }) + true } fn visit_estr_uniq(&mut self) -> bool { @@ -628,7 +625,6 @@ fn test_repr() { exact_test(&false, "false"); exact_test(&1.234, "1.234f64"); exact_test(&(&"hello"), "\"hello\""); - exact_test(&(@"hello"), "@\"hello\""); exact_test(&(~"he\u10f3llo"), "~\"he\\u10f3llo\""); exact_test(&(@10), "@10"); diff --git a/src/libstd/send_str.rs b/src/libstd/send_str.rs index 2599a74a748..b075b75b70a 100644 --- a/src/libstd/send_str.rs +++ b/src/libstd/send_str.rs @@ -185,7 +185,6 @@ mod tests { assert_eq!(s.len(), 5); assert_eq!(s.as_slice(), "abcde"); assert_eq!(s.to_str(), ~"abcde"); - assert!(s.equiv(&@"abcde")); assert!(s.lt(&SendStrOwned(~"bcdef"))); assert_eq!(SendStrStatic(""), Default::default()); @@ -193,7 +192,6 @@ mod tests { assert_eq!(o.len(), 5); assert_eq!(o.as_slice(), "abcde"); assert_eq!(o.to_str(), ~"abcde"); - assert!(o.equiv(&@"abcde")); assert!(o.lt(&SendStrStatic("bcdef"))); assert_eq!(SendStrOwned(~""), Default::default()); diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 3cc199ce195..5d5beb3609e 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -17,46 +17,35 @@ Unicode string manipulation (`str` type) Rust's string type is one of the core primitive types of the language. While represented by the name `str`, the name `str` is not actually a valid type in Rust. Each string must also be decorated with its ownership. This means that -there are three common kinds of strings in rust: +there are two common kinds of strings in rust: * `~str` - This is an owned string. This type obeys all of the normal semantics of the `~T` types, meaning that it has one, and only one, owner. This type cannot be implicitly copied, and is moved out of when passed to other functions. -* `@str` - This is a managed string. Similarly to `@T`, this type can be - implicitly copied, and each implicit copy will increment the - reference count to the string. This means that there is no "true - owner" of the string, and the string will be deallocated when the - reference count reaches 0. - -* `&str` - Finally, this is the borrowed string type. This type of string can - only be created from one of the other two kinds of strings. As the - name "borrowed" implies, this type of string is owned elsewhere, and - this string cannot be moved out of. +* `&str` - This is the borrowed string type. This type of string can only be + created from the other kind of string. As the name "borrowed" + implies, this type of string is owned elsewhere, and this string + cannot be moved out of. As an example, here's a few different kinds of strings. ```rust -#[feature(managed_boxes)]; - fn main() { let owned_string = ~"I am an owned string"; - let managed_string = @"This string is garbage-collected"; let borrowed_string1 = "This string is borrowed with the 'static lifetime"; let borrowed_string2: &str = owned_string; // owned strings can be borrowed - let borrowed_string3: &str = managed_string; // managed strings can also be borrowed } ``` -From the example above, you can see that rust has 3 different kinds of string -literals. The owned/managed literals correspond to the owned/managed string -types, but the "borrowed literal" is actually more akin to C's concept of a -static string. +From the example above, you can see that rust has 2 different kinds of string +literals. The owned literals correspond to the owned string types, but the +"borrowed literal" is actually more akin to C's concept of a static string. -When a string is declared without a `~` or `@` sigil, then the string is -allocated statically in the rodata of the executable/library. The string then -has the type `&'static str` meaning that the string is valid for the `'static` +When a string is declared without a `~` sigil, then the string is allocated +statically in the rodata of the executable/library. The string then has the +type `&'static str` meaning that the string is valid for the `'static` lifetime, otherwise known as the lifetime of the entire program. As can be inferred from the type, these static strings are not mutable. @@ -89,11 +78,9 @@ The actual representation of strings have direct mappings to vectors: * `~str` is the same as `~[u8]` * `&str` is the same as `&[u8]` -* `@str` is the same as `@[u8]` */ -use at_vec; use cast; use cast::transmute; use char; @@ -157,16 +144,6 @@ impl<'a> ToStr for &'a str { fn to_str(&self) -> ~str { self.to_owned() } } -impl ToStr for @str { - #[inline] - fn to_str(&self) -> ~str { self.to_owned() } -} - -impl<'a> FromStr for @str { - #[inline] - fn from_str(s: &str) -> Option<@str> { Some(s.to_managed()) } -} - /// Convert a byte to a UTF-8 string /// /// # Failure @@ -1140,11 +1117,6 @@ pub mod traits { fn cmp(&self, other: &~str) -> Ordering { self.as_slice().cmp(&other.as_slice()) } } - impl TotalOrd for @str { - #[inline] - fn cmp(&self, other: &@str) -> Ordering { self.as_slice().cmp(&other.as_slice()) } - } - impl<'a> Eq for &'a str { #[inline] fn eq(&self, other: & &'a str) -> bool { @@ -1161,13 +1133,6 @@ pub mod traits { } } - impl Eq for @str { - #[inline] - fn eq(&self, other: &@str) -> bool { - eq_slice((*self), (*other)) - } - } - impl<'a> TotalEq for &'a str { #[inline] fn equals(&self, other: & &'a str) -> bool { @@ -1182,13 +1147,6 @@ pub mod traits { } } - impl TotalEq for @str { - #[inline] - fn equals(&self, other: &@str) -> bool { - eq_slice((*self), (*other)) - } - } - impl<'a> Ord for &'a str { #[inline] fn lt(&self, other: & &'a str) -> bool { self.cmp(other) == Less } @@ -1199,21 +1157,11 @@ pub mod traits { fn lt(&self, other: &~str) -> bool { self.cmp(other) == Less } } - impl Ord for @str { - #[inline] - fn lt(&self, other: &@str) -> bool { self.cmp(other) == Less } - } - impl<'a, S: Str> Equiv for &'a str { #[inline] fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) } } - impl<'a, S: Str> Equiv for @str { - #[inline] - fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) } - } - impl<'a, S: Str> Equiv for ~str { #[inline] fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) } @@ -1250,16 +1198,6 @@ impl<'a> Str for ~str { fn into_owned(self) -> ~str { self } } -impl<'a> Str for @str { - #[inline] - fn as_slice<'a>(&'a self) -> &'a str { - let s: &'a str = *self; s - } - - #[inline] - fn into_owned(self) -> ~str { self.to_owned() } -} - impl<'a> Container for &'a str { #[inline] fn len(&self) -> uint { @@ -1272,11 +1210,6 @@ impl Container for ~str { fn len(&self) -> uint { self.as_slice().len() } } -impl Container for @str { - #[inline] - fn len(&self) -> uint { self.as_slice().len() } -} - impl Mutable for ~str { /// Remove all content, make the string empty #[inline] @@ -1734,9 +1667,6 @@ pub trait StrSlice<'a> { /// Copy a slice into a new owned str. fn to_owned(&self) -> ~str; - /// Copy a slice into a new managed str. - fn to_managed(&self) -> @str; - /// Converts to a vector of `u16` encoded as UTF-16. fn to_utf16(&self) -> ~[u16]; @@ -2246,14 +2176,6 @@ impl<'a> StrSlice<'a> for &'a str { } } - #[inline] - fn to_managed(&self) -> @str { - unsafe { - let v: *&[u8] = cast::transmute(self); - cast::transmute(at_vec::to_managed(*v)) - } - } - fn to_utf16(&self) -> ~[u16] { let mut u = ~[]; for ch in self.chars() { @@ -2682,20 +2604,6 @@ impl DeepClone for ~str { } } -impl Clone for @str { - #[inline] - fn clone(&self) -> @str { - *self - } -} - -impl DeepClone for @str { - #[inline] - fn deep_clone(&self) -> @str { - *self - } -} - impl FromIterator for ~str { #[inline] fn from_iterator>(iterator: &mut T) -> ~str { @@ -2727,10 +2635,6 @@ impl Default for ~str { fn default() -> ~str { ~"" } } -impl Default for @str { - fn default() -> @str { @"" } -} - #[cfg(test)] mod tests { use iter::AdditiveIterator; @@ -3536,12 +3440,6 @@ mod tests { assert_eq!("\U0001d4ea\r".escape_default(), ~"\\U0001d4ea\\r"); } - #[test] - fn test_to_managed() { - assert_eq!("abc".to_managed(), @"abc"); - assert_eq!("abcdef".slice(1, 5).to_managed(), @"bcde"); - } - #[test] fn test_total_ord() { "1234".cmp(& &"123") == Greater; @@ -3584,10 +3482,8 @@ mod tests { ); t!("foo", "bar", "foobar"); - t!("foo", @"bar", "foobar"); t!("foo", ~"bar", "foobar"); t!("ศไทย中", "华Việt Nam", "ศไทย中华Việt Nam"); - t!("ศไทย中", @"华Việt Nam", "ศไทย中华Việt Nam"); t!("ศไทย中", ~"华Việt Nam", "ศไทย中华Việt Nam"); } @@ -3874,7 +3770,6 @@ mod tests { } t::<&str>(); - t::<@str>(); t::<~str>(); } @@ -3886,7 +3781,6 @@ mod tests { let s = ~"01234"; assert_eq!(5, sum_len(["012", "", "34"])); - assert_eq!(5, sum_len([@"01", @"2", @"34", @""])); assert_eq!(5, sum_len([~"01", ~"2", ~"34", ~""])); assert_eq!(5, sum_len([s.as_slice()])); } @@ -3957,8 +3851,6 @@ mod tests { fn test_from_str() { let owned: Option<~str> = from_str(&"string"); assert_eq!(owned, Some(~"string")); - let managed: Option<@str> = from_str(&"string"); - assert_eq!(managed, Some(@"string")); } } diff --git a/src/libstd/to_bytes.rs b/src/libstd/to_bytes.rs index 8df028f56d5..7ca1590dad0 100644 --- a/src/libstd/to_bytes.rs +++ b/src/libstd/to_bytes.rs @@ -288,13 +288,6 @@ impl IterBytes for ~str { } } -impl IterBytes for @str { - #[inline] - fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { - self.as_slice().iter_bytes(lsb0, f) - } -} - impl IterBytes for Option { #[inline] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { diff --git a/src/libstd/to_str.rs b/src/libstd/to_str.rs index a58b09d8ecd..edbf3314417 100644 --- a/src/libstd/to_str.rs +++ b/src/libstd/to_str.rs @@ -195,7 +195,6 @@ mod tests { assert_eq!(false.to_str(), ~"false"); assert_eq!(().to_str(), ~"()"); assert_eq!((~"hi").to_str(), ~"hi"); - assert_eq!((@"hi").to_str(), ~"hi"); } #[test] diff --git a/src/libstd/unstable/raw.rs b/src/libstd/unstable/raw.rs index 8aee26c24b2..c568edd09d1 100644 --- a/src/libstd/unstable/raw.rs +++ b/src/libstd/unstable/raw.rs @@ -59,7 +59,6 @@ impl Repr<*Box> for @T {} impl Repr<*Box>> for @[T] {} impl Repr<*Vec> for ~[T] {} impl Repr<*String> for ~str {} -impl Repr<*Box> for @str {} // sure would be nice to have this // impl Repr<*Vec> for ~[T] {} -- cgit 1.4.1-3-g733a5 From c594e675eb3db25cd018d58d8fe06ef6ea2c90de Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 31 Jan 2014 18:25:08 -0800 Subject: librustc: Remove `@str` from the language --- src/librustc/middle/lint.rs | 2 +- src/librustc/middle/mem_categorization.rs | 3 +-- src/librustc/middle/trans/debuginfo.rs | 3 +-- src/librustc/middle/trans/type_of.rs | 2 +- src/librustc/middle/typeck/astconv.rs | 11 ++++++++++- src/librustdoc/clean.rs | 7 +++++-- src/libstd/str.rs | 1 - src/libsyntax/ext/expand.rs | 4 ++-- src/libsyntax/parse/obsolete.rs | 5 +++++ src/libsyntax/parse/parser.rs | 5 ++++- src/libsyntax/parse/token.rs | 9 +++++---- src/libsyntax/util/interner.rs | 2 +- src/test/compile-fail/lint-heap-memory.rs | 1 - 13 files changed, 36 insertions(+), 19 deletions(-) (limited to 'src/libstd') diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index af83bc97adc..33f97b3ba2a 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -887,7 +887,7 @@ fn check_heap_type(cx: &Context, span: Span, ty: ty::t) { let mut n_uniq = 0; ty::fold_ty(cx.tcx, ty, |t| { match ty::get(t).sty { - ty::ty_box(_) | ty::ty_str(ty::vstore_box) | + ty::ty_box(_) | ty::ty_vec(_, ty::vstore_box) | ty::ty_trait(_, _, ty::BoxTraitStore, _, _) => { n_box += 1; diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index d98cf9795b2..9bab74dc56a 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -179,8 +179,7 @@ pub fn opt_deref_kind(t: ty::t) -> Option { ty::ty_box(_) | ty::ty_vec(_, ty::vstore_box) | - ty::ty_trait(_, _, ty::BoxTraitStore, _, _) | - ty::ty_str(ty::vstore_box) => { + ty::ty_trait(_, _, ty::BoxTraitStore, _, _) => { Some(deref_ptr(gc_ptr)) } diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index 2611076f15d..b89ec9d19df 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -2094,8 +2094,7 @@ fn type_metadata(cx: &CrateContext, pointer_type_metadata(cx, t, vec_metadata) } ty::vstore_box => { - let boxed_vec_metadata = boxed_vec_metadata(cx, i8_t, usage_site_span); - pointer_type_metadata(cx, t, boxed_vec_metadata) + fail!("unexpected managed string") } ty::vstore_slice(_region) => { vec_slice_metadata(cx, t, i8_t, usage_site_span) diff --git a/src/librustc/middle/trans/type_of.rs b/src/librustc/middle/trans/type_of.rs index 86456187d1a..b440db66a12 100644 --- a/src/librustc/middle/trans/type_of.rs +++ b/src/librustc/middle/trans/type_of.rs @@ -222,7 +222,7 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type { adt::incomplete_type_of(cx, repr, name) } ty::ty_str(ty::vstore_box) => { - Type::at_box(cx, Type::vec(cx.sess.targ_cfg.arch, &Type::i8())).ptr_to() + fail!("unexpected managed string") } ty::ty_vec(ref mt, ty::vstore_box) => { let e_ty = type_of(cx, mt.ty); diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 9f44aa1a023..9f8b9140417 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -413,8 +413,17 @@ pub fn ast_ty_to_ty( // will run after this as long as the path isn't a trait. let def_map = tcx.def_map.borrow(); match def_map.get().find(&id) { - Some(&ast::DefPrimTy(ast::TyStr)) if a_seq_ty.mutbl == ast::MutImmutable => { + Some(&ast::DefPrimTy(ast::TyStr)) if + a_seq_ty.mutbl == ast::MutImmutable => { check_path_args(tcx, path, NO_TPS | NO_REGIONS); + match vst { + ty::vstore_box => { + tcx.sess.span_err(path.span, + "managed strings are not \ + supported") + } + _ => {} + } return ty::mk_str(tcx, vst); } Some(&ast::DefTrait(trait_def_id)) => { diff --git a/src/librustdoc/clean.rs b/src/librustdoc/clean.rs index 53bae09f58c..4f7e6df95e1 100644 --- a/src/librustdoc/clean.rs +++ b/src/librustdoc/clean.rs @@ -874,11 +874,14 @@ impl Clean for ast::PathSegment { } fn path_to_str(p: &ast::Path) -> ~str { - use syntax::parse::token::interner_get; + use syntax::parse::token; let mut s = ~""; let mut first = true; - for i in p.segments.iter().map(|x| interner_get(x.identifier.name)) { + for i in p.segments.iter().map(|x| { + let string = token::get_ident(x.identifier.name); + string.get().to_str() + }) { if !first || p.global { s.push_str("::"); } else { diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 5d5beb3609e..0315e560bb7 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -3477,7 +3477,6 @@ mod tests { let e = $e; assert_eq!(s1 + s2, e.to_owned()); assert_eq!(s1.to_owned() + s2, e.to_owned()); - assert_eq!(s1.to_managed() + s2, e.to_owned()); } } ); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index f7419e77ff5..d8d98b27793 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1224,7 +1224,7 @@ mod test { fn run_renaming_test(t: &RenamingTest, test_idx: uint) { let invalid_name = token::special_idents::invalid.name; let (teststr, bound_connections, bound_ident_check) = match *t { - (ref str,ref conns, bic) => (str.to_managed(), conns.clone(), bic) + (ref str,ref conns, bic) => (str.to_owned(), conns.clone(), bic) }; let cr = expand_crate_str(teststr.to_owned()); // find the bindings: @@ -1304,7 +1304,7 @@ foo_module!() let cxbinds : ~[&ast::Ident] = bindings.iter().filter(|b| { - let string = token::get_ident(b); + let string = token::get_ident(b.name); "xx" == string.get() }).collect(); let cxbind = match cxbinds { diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 04c73ce71d0..46f1f33143e 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -44,6 +44,7 @@ pub enum ObsoleteSyntax { ObsoleteMultipleImport, ObsoleteExternModAttributesInParens, ObsoleteManagedPattern, + ObsoleteManagedString, } impl to_bytes::IterBytes for ObsoleteSyntax { @@ -149,6 +150,10 @@ impl ParserObsoleteMethods for Parser { "use a nested `match` expression instead of a managed box \ pattern" ), + ObsoleteManagedString => ( + "managed string", + "use `Rc<~str>` instead of a managed string" + ), }; self.report(sp, kind, kind_str, desc); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index dc16f32b872..fb679fa0460 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2295,7 +2295,10 @@ impl Parser { ex = match e.node { ExprVec(..) | ExprRepeat(..) => ExprVstore(e, ExprVstoreBox), - ExprLit(lit) if lit_is_str(lit) => ExprVstore(e, ExprVstoreBox), + ExprLit(lit) if lit_is_str(lit) => { + self.obsolete(self.last_span, ObsoleteManagedString); + ExprVstore(e, ExprVstoreBox) + } _ => self.mk_unary(UnBox, e) }; } diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index eb2fa151f51..fa53f021cdb 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -544,8 +544,8 @@ pub fn get_ident_interner() -> @IdentInterner { /// interner lives for the life of the task, this can be safely treated as an /// immortal string, as long as it never crosses between tasks. /// -/// XXX(pcwalton): You must be careful about what you do in the destructors of -/// objects stored in TLS, because they may run after the interner is +/// FIXME(pcwalton): You must be careful about what you do in the destructors +/// of objects stored in TLS, because they may run after the interner is /// destroyed. In particular, they must not access string contents. This can /// be fixed in the future by just leaking all strings until task death /// somehow. @@ -585,8 +585,9 @@ impl InternedString { impl BytesContainer for InternedString { fn container_as_bytes<'a>(&'a self) -> &'a [u8] { - // XXX(pcwalton): This is a workaround for the incorrect signature of - // `BytesContainer`, which is itself a workaround for the lack of DST. + // FIXME(pcwalton): This is a workaround for the incorrect signature + // of `BytesContainer`, which is itself a workaround for the lack of + // DST. unsafe { let this = self.get(); cast::transmute(this.container_as_bytes()) diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index e20efda9c6e..fc3e55dcde2 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -253,7 +253,7 @@ mod tests { #[test] fn i3 () { - let i : Interner<@~str> = Interner::prefill([ + let i : Interner = Interner::prefill([ RcStr::new("Alan"), RcStr::new("Bob"), RcStr::new("Carol") diff --git a/src/test/compile-fail/lint-heap-memory.rs b/src/test/compile-fail/lint-heap-memory.rs index 0c19988bef4..5e8c83558fb 100644 --- a/src/test/compile-fail/lint-heap-memory.rs +++ b/src/test/compile-fail/lint-heap-memory.rs @@ -25,7 +25,6 @@ fn main() { @[1]; //~ ERROR type uses managed //~^ ERROR type uses managed fn f(_: @Clone) {} //~ ERROR type uses managed - //~^ ERROR type uses managed ~2; //~ ERROR type uses owned ~[1]; //~ ERROR type uses owned -- cgit 1.4.1-3-g733a5 From f502576fc7a97825ee90b01c724b63a4bd4c85aa Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Sun, 2 Feb 2014 02:19:55 +1100 Subject: Fix `@str` removal tests. --- src/librustc/driver/driver.rs | 2 +- src/libstd/gc.rs | 1 - src/libsyntax/parse/token.rs | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) (limited to 'src/libstd') diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 00b878a7bf7..b779c7e73b1 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -1213,7 +1213,7 @@ mod test { let sessopts = build_session_options(~"rustc", matches, @diagnostic::DefaultEmitter); let sess = build_session(sessopts, None, @diagnostic::DefaultEmitter); let cfg = build_configuration(sess); - let mut test_items = cfg.iter().filter(|m| "test" == m.name()); + let mut test_items = cfg.iter().filter(|m| m.name().equiv(&("test"))); assert!(test_items.next().is_some()); assert!(test_items.next().is_none()); } diff --git a/src/libstd/gc.rs b/src/libstd/gc.rs index 8ec07290a31..fa7c94ac994 100644 --- a/src/libstd/gc.rs +++ b/src/libstd/gc.rs @@ -35,7 +35,6 @@ pub struct Gc { } #[cfg(test)] -#[no_send] pub struct Gc { priv ptr: @T, priv marker: marker::NoSend, diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index fa53f021cdb..c0abbb9222b 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -549,7 +549,6 @@ pub fn get_ident_interner() -> @IdentInterner { /// destroyed. In particular, they must not access string contents. This can /// be fixed in the future by just leaking all strings until task death /// somehow. -#[no_send] #[deriving(Clone, Eq, IterBytes, Ord, TotalEq, TotalOrd)] pub struct InternedString { priv string: RcStr, -- cgit 1.4.1-3-g733a5 From 2ed980fe253d0b7103ff0b16ce2aeecb03f09203 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Sat, 1 Feb 2014 15:57:17 +1100 Subject: std,extra: remove use of & support for @[]. --- src/libextra/num/bigint.rs | 2 +- src/libextra/serialize.rs | 21 --- src/libstd/at_vec.rs | 423 -------------------------------------------- src/libstd/lib.rs | 1 - src/libstd/path/mod.rs | 7 - src/libstd/path/posix.rs | 8 - src/libstd/path/windows.rs | 8 - src/libstd/reflect.rs | 3 - src/libstd/repr.rs | 6 - src/libstd/rt/local_heap.rs | 2 +- src/libstd/to_bytes.rs | 7 - src/libstd/to_str.rs | 19 -- src/libstd/unstable/raw.rs | 1 - src/libstd/vec.rs | 60 ------- 14 files changed, 2 insertions(+), 566 deletions(-) delete mode 100644 src/libstd/at_vec.rs (limited to 'src/libstd') diff --git a/src/libextra/num/bigint.rs b/src/libextra/num/bigint.rs index c1959843d59..cea899b18c0 100644 --- a/src/libextra/num/bigint.rs +++ b/src/libextra/num/bigint.rs @@ -80,7 +80,7 @@ pub mod BigDigit { /** A big unsigned integer type. -A `BigUint`-typed value `BigUint { data: @[a, b, c] }` represents a number +A `BigUint`-typed value `BigUint { data: ~[a, b, c] }` represents a number `(a + b * BigDigit::base + c * BigDigit::base^2)`. */ #[deriving(Clone)] diff --git a/src/libextra/serialize.rs b/src/libextra/serialize.rs index fa2737ce75f..9b1b1e0548e 100644 --- a/src/libextra/serialize.rs +++ b/src/libextra/serialize.rs @@ -18,7 +18,6 @@ Core encoding and decoding interfaces. #[forbid(non_camel_case_types)]; -use std::at_vec; use std::hashmap::{HashMap, HashSet}; use std::rc::Rc; use std::trie::{TrieMap, TrieSet}; @@ -444,26 +443,6 @@ impl> Decodable for ~[T] { } } -impl> Encodable for @[T] { - fn encode(&self, s: &mut S) { - s.emit_seq(self.len(), |s| { - for (i, e) in self.iter().enumerate() { - s.emit_seq_elt(i, |s| e.encode(s)) - } - }) - } -} - -impl> Decodable for @[T] { - fn decode(d: &mut D) -> @[T] { - d.read_seq(|d, len| { - at_vec::from_fn(len, |i| { - d.read_seq_elt(i, |d| Decodable::decode(d)) - }) - }) - } -} - impl> Encodable for Option { fn encode(&self, s: &mut S) { s.emit_option(|s| { diff --git a/src/libstd/at_vec.rs b/src/libstd/at_vec.rs deleted file mode 100644 index 6a3c74482d3..00000000000 --- a/src/libstd/at_vec.rs +++ /dev/null @@ -1,423 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Operations on managed vectors (`@[T]` type) - -use clone::Clone; -use container::Container; -use iter::{Iterator, FromIterator}; -use option::{Option, Some, None}; -use mem; -use unstable::raw::Repr; -use vec::{ImmutableVector, OwnedVector}; - -/// Code for dealing with @-vectors. This is pretty incomplete, and -/// contains a bunch of duplication from the code for ~-vectors. - -/// Returns the number of elements the vector can hold without reallocating -#[inline] -pub fn capacity(v: @[T]) -> uint { - unsafe { - let managed_box = v.repr(); - (*managed_box).data.alloc / mem::size_of::() - } -} - -/** - * Builds a vector by calling a provided function with an argument - * function that pushes an element to the back of a vector. - * The initial size for the vector may optionally be specified - * - * # Arguments - * - * * size - An option, maybe containing initial size of the vector to reserve - * * builder - A function that will construct the vector. It receives - * as an argument a function that will push an element - * onto the vector being constructed. - */ -#[inline] -pub fn build(size: Option, builder: |push: |v: A||) -> @[A] { - let mut vec = @[]; - unsafe { raw::reserve(&mut vec, size.unwrap_or(4)); } - builder(|x| unsafe { raw::push(&mut vec, x) }); - vec -} - -// Appending - -/// Iterates over the `rhs` vector, copying each element and appending it to the -/// `lhs`. Afterwards, the `lhs` is then returned for use again. -#[inline] -pub fn append(lhs: @[T], rhs: &[T]) -> @[T] { - build(Some(lhs.len() + rhs.len()), |push| { - for x in lhs.iter() { - push((*x).clone()); - } - for elt in rhs.iter() { - push(elt.clone()); - } - }) -} - - -/// Apply a function to each element of a vector and return the results -#[inline] -pub fn map(v: &[T], f: |x: &T| -> U) -> @[U] { - build(Some(v.len()), |push| { - for elem in v.iter() { - push(f(elem)); - } - }) -} - -/** - * Creates and initializes an immutable vector. - * - * Creates an immutable vector of size `n_elts` and initializes the elements - * to the value returned by the function `op`. - */ -#[inline] -pub fn from_fn(n_elts: uint, op: |uint| -> T) -> @[T] { - build(Some(n_elts), |push| { - let mut i: uint = 0u; - while i < n_elts { push(op(i)); i += 1u; } - }) -} - -/** - * Creates and initializes an immutable vector. - * - * Creates an immutable vector of size `n_elts` and initializes the elements - * to the value `t`. - */ -#[inline] -pub fn from_elem(n_elts: uint, t: T) -> @[T] { - build(Some(n_elts), |push| { - let mut i: uint = 0u; - while i < n_elts { - push(t.clone()); - i += 1u; - } - }) -} - -/** - * Creates and initializes an immutable managed vector by moving all the - * elements from an owned vector. - */ -#[inline] -pub fn to_managed_move(v: ~[T]) -> @[T] { - let mut av = @[]; - unsafe { - raw::reserve(&mut av, v.len()); - for x in v.move_iter() { - raw::push(&mut av, x); - } - av - } -} - -/** - * Creates and initializes an immutable managed vector by copying all the - * elements of a slice. - */ -#[inline] -pub fn to_managed(v: &[T]) -> @[T] { - from_fn(v.len(), |i| v[i].clone()) -} - -impl Clone for @[T] { - fn clone(&self) -> @[T] { - *self - } -} - -impl FromIterator for @[A] { - #[inline] - fn from_iterator>(iterator: &mut T) -> @[A] { - let (lower, _) = iterator.size_hint(); - build(Some(lower), |push| { - for x in *iterator { - push(x); - } - }) - } -} - -#[cfg(not(test))] -#[allow(missing_doc)] -pub mod traits { - use at_vec::append; - use clone::Clone; - use ops::Add; - use vec::Vector; - - impl<'a,T:Clone, V: Vector> Add for @[T] { - #[inline] - fn add(&self, rhs: &V) -> @[T] { - append(*self, rhs.as_slice()) - } - } -} - -#[cfg(test)] -pub mod traits {} - -#[allow(missing_doc)] -pub mod raw { - use at_vec::capacity; - use cast; - use cast::{transmute, transmute_copy}; - use container::Container; - use option::None; - use mem; - use num::next_power_of_two; - use ptr; - use unstable::intrinsics::{move_val_init, TyDesc}; - use unstable::intrinsics; - use unstable::raw::{Box, Vec}; - - /** - * Sets the length of a vector - * - * This will explicitly set the size of the vector, without actually - * modifying its buffers, so it is up to the caller to ensure that - * the vector is actually the specified size. - */ - #[inline] - pub unsafe fn set_len(v: &mut @[T], new_len: uint) { - let repr: *mut Box> = cast::transmute_copy(v); - (*repr).data.fill = new_len * mem::size_of::(); - } - - /** - * Pushes a new value onto this vector. - */ - #[inline] - pub unsafe fn push(v: &mut @[T], initval: T) { - let full = { - let repr: *Box> = cast::transmute_copy(v); - (*repr).data.alloc > (*repr).data.fill - }; - if full { - push_fast(v, initval); - } else { - push_slow(v, initval); - } - } - - #[inline] // really pretty please - unsafe fn push_fast(v: &mut @[T], initval: T) { - let repr: *mut Box> = cast::transmute_copy(v); - let amt = v.len(); - (*repr).data.fill += mem::size_of::(); - let p = ptr::offset(&(*repr).data.data as *T, amt as int) as *mut T; - move_val_init(&mut(*p), initval); - } - - #[inline] - unsafe fn push_slow(v: &mut @[T], initval: T) { - reserve_at_least(v, v.len() + 1u); - push_fast(v, initval); - } - - /** - * Reserves capacity for exactly `n` elements in the given vector. - * - * If the capacity for `v` is already equal to or greater than the - * requested capacity, then no action is taken. - * - * # Arguments - * - * * v - A vector - * * n - The number of elements to reserve space for - */ - #[inline] - pub unsafe fn reserve(v: &mut @[T], n: uint) { - // Only make the (slow) call into the runtime if we have to - if capacity(*v) < n { - let ptr: *mut *mut Box> = transmute(v); - let ty = intrinsics::get_tydesc::(); - return reserve_raw(ty, ptr, n); - } - } - - // Implementation detail. Shouldn't be public - #[allow(missing_doc)] - #[inline] - pub fn reserve_raw(ty: *TyDesc, ptr: *mut *mut Box>, n: uint) { - // check for `uint` overflow - unsafe { - if n > (**ptr).data.alloc / (*ty).size { - let alloc = n * (*ty).size; - let total_size = alloc + mem::size_of::>(); - if alloc / (*ty).size != n || total_size < alloc { - fail!("vector size is too large: {}", n); - } - (*ptr) = local_realloc(*ptr as *(), total_size) as *mut Box>; - (**ptr).data.alloc = alloc; - } - } - - #[inline] - fn local_realloc(ptr: *(), size: uint) -> *() { - use rt::local::Local; - use rt::task::Task; - - let mut task = Local::borrow(None::); - task.get().heap.realloc(ptr as *mut Box<()>, size) as *() - } - } - - /** - * Reserves capacity for at least `n` elements in the given vector. - * - * This function will over-allocate in order to amortize the - * allocation costs in scenarios where the caller may need to - * repeatedly reserve additional space. - * - * If the capacity for `v` is already equal to or greater than the - * requested capacity, then no action is taken. - * - * # Arguments - * - * * v - A vector - * * n - The number of elements to reserve space for - */ - #[inline] - pub unsafe fn reserve_at_least(v: &mut @[T], n: uint) { - reserve(v, next_power_of_two(n)); - } -} - -#[cfg(test)] -mod test { - use super::*; - use prelude::*; - use bh = extra::test::BenchHarness; - - #[test] - fn test() { - // Some code that could use that, then: - fn seq_range(lo: uint, hi: uint) -> @[uint] { - build(None, |push| { - for i in range(lo, hi) { - push(i); - } - }) - } - - assert_eq!(seq_range(10, 15), @[10, 11, 12, 13, 14]); - assert_eq!(from_fn(5, |x| x+1), @[1, 2, 3, 4, 5]); - assert_eq!(from_elem(5, 3.14), @[3.14, 3.14, 3.14, 3.14, 3.14]); - } - - #[test] - fn append_test() { - assert_eq!(@[1,2,3] + &[4,5,6], @[1,2,3,4,5,6]); - } - - #[test] - fn test_to_managed_move() { - assert_eq!(to_managed_move::(~[]), @[]); - assert_eq!(to_managed_move(~[true]), @[true]); - assert_eq!(to_managed_move(~[1, 2, 3, 4, 5]), @[1, 2, 3, 4, 5]); - assert_eq!(to_managed_move(~[~"abc", ~"123"]), @[~"abc", ~"123"]); - assert_eq!(to_managed_move(~[~[42]]), @[~[42]]); - } - - #[test] - fn test_to_managed() { - assert_eq!(to_managed::([]), @[]); - assert_eq!(to_managed([true]), @[true]); - assert_eq!(to_managed([1, 2, 3, 4, 5]), @[1, 2, 3, 4, 5]); - assert_eq!(to_managed([@[42]]), @[@[42]]); - } - - #[bench] - fn bench_capacity(b: &mut bh) { - let x = @[1, 2, 3]; - b.iter(|| { - let _ = capacity(x); - }); - } - - #[bench] - fn bench_build_sized(b: &mut bh) { - let len = 64; - b.iter(|| { - build(Some(len), |push| for i in range(0, 1024) { push(i) }); - }); - } - - #[bench] - fn bench_build(b: &mut bh) { - b.iter(|| { - for i in range(0, 95) { - build(None, |push| push(i)); - } - }); - } - - #[bench] - fn bench_append(b: &mut bh) { - let lhs = @[7, ..128]; - let rhs = range(0, 256).to_owned_vec(); - b.iter(|| { - let _ = append(lhs, rhs); - }) - } - - #[bench] - fn bench_map(b: &mut bh) { - let elts = range(0, 256).to_owned_vec(); - b.iter(|| { - let _ = map(elts, |x| x*2); - }) - } - - #[bench] - fn bench_from_fn(b: &mut bh) { - b.iter(|| { - let _ = from_fn(1024, |x| x); - }); - } - - #[bench] - fn bench_from_elem(b: &mut bh) { - b.iter(|| { - let _ = from_elem(1024, 0u64); - }); - } - - #[bench] - fn bench_to_managed_move(b: &mut bh) { - b.iter(|| { - let elts = range(0, 1024).to_owned_vec(); // yikes! can't move out of capture, though - to_managed_move(elts); - }) - } - - #[bench] - fn bench_to_managed(b: &mut bh) { - let elts = range(0, 1024).to_owned_vec(); - b.iter(|| { - let _ = to_managed(elts); - }); - } - - #[bench] - fn bench_clone(b: &mut bh) { - let elts = to_managed(range(0, 1024).to_owned_vec()); - b.iter(|| { - let _ = elts.clone(); - }); - } -} diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index d7a7011319a..adce11fed2d 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -114,7 +114,6 @@ pub mod tuple; pub mod vec; pub mod vec_ng; -pub mod at_vec; pub mod str; pub mod ascii; diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index 2282f97a716..c5482811a94 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -622,13 +622,6 @@ impl BytesContainer for ~[u8] { } } -impl BytesContainer for @[u8] { - #[inline] - fn container_as_bytes<'a>(&'a self) -> &'a [u8] { - self.as_slice() - } -} - impl BytesContainer for CString { #[inline] fn container_as_bytes<'a>(&'a self) -> &'a [u8] { diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index b6506b51786..ba0cd0bb521 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -807,8 +807,6 @@ mod tests { #[test] fn test_push_many() { - use to_man = at_vec::to_managed_move; - macro_rules! t( (s: $path:expr, $push:expr, $exp:expr) => ( { @@ -833,8 +831,6 @@ mod tests { t!(v: b!("a/b/c"), [b!("d"), b!("e")], b!("a/b/c/d/e")); t!(v: b!("a/b/c"), [b!("d"), b!("/e"), b!("f")], b!("/e/f")); t!(v: b!("a/b/c"), [b!("d").to_owned(), b!("e").to_owned()], b!("a/b/c/d/e")); - t!(v: b!("a/b/c"), [to_man(b!("d").to_owned()), to_man(b!("e").to_owned())], - b!("a/b/c/d/e")); } #[test] @@ -916,8 +912,6 @@ mod tests { #[test] fn test_join_many() { - use to_man = at_vec::to_managed_move; - macro_rules! t( (s: $path:expr, $join:expr, $exp:expr) => ( { @@ -941,8 +935,6 @@ mod tests { t!(s: "a/b/c", [~"d", ~"e"], "a/b/c/d/e"); t!(v: b!("a/b/c"), [b!("d"), b!("e")], b!("a/b/c/d/e")); t!(v: b!("a/b/c"), [b!("d").to_owned(), b!("e").to_owned()], b!("a/b/c/d/e")); - t!(v: b!("a/b/c"), [to_man(b!("d").to_owned()), to_man(b!("e").to_owned())], - b!("a/b/c/d/e")); } #[test] diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 2578acaf41c..eec6f37b627 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -1587,8 +1587,6 @@ mod tests { #[test] fn test_push_many() { - use to_man = at_vec::to_managed_move; - macro_rules! t( (s: $path:expr, $push:expr, $exp:expr) => ( { @@ -1613,8 +1611,6 @@ mod tests { t!(v: b!("a\\b\\c"), [b!("d"), b!("e")], b!("a\\b\\c\\d\\e")); t!(v: b!("a\\b\\c"), [b!("d"), b!("\\e"), b!("f")], b!("\\e\\f")); t!(v: b!("a\\b\\c"), [b!("d").to_owned(), b!("e").to_owned()], b!("a\\b\\c\\d\\e")); - t!(v: b!("a\\b\\c"), [to_man(b!("d").to_owned()), to_man(b!("e").to_owned())], - b!("a\\b\\c\\d\\e")); } #[test] @@ -1731,8 +1727,6 @@ mod tests { #[test] fn test_join_many() { - use to_man = at_vec::to_managed_move; - macro_rules! t( (s: $path:expr, $join:expr, $exp:expr) => ( { @@ -1756,8 +1750,6 @@ mod tests { t!(s: "a\\b\\c", [~"d", ~"e"], "a\\b\\c\\d\\e"); t!(v: b!("a\\b\\c"), [b!("d"), b!("e")], b!("a\\b\\c\\d\\e")); t!(v: b!("a\\b\\c"), [b!("d").to_owned(), b!("e").to_owned()], b!("a\\b\\c\\d\\e")); - t!(v: b!("a\\b\\c"), [to_man(b!("d").to_owned()), to_man(b!("e").to_owned())], - b!("a\\b\\c\\d\\e")); } #[test] diff --git a/src/libstd/reflect.rs b/src/libstd/reflect.rs index d0b0f0c264d..a7cea1c7e4a 100644 --- a/src/libstd/reflect.rs +++ b/src/libstd/reflect.rs @@ -251,9 +251,6 @@ impl TyVisitor for MovePtrAdaptor { } fn visit_evec_box(&mut self, mtbl: uint, inner: *TyDesc) -> bool { - self.align_to::<@[u8]>(); - if ! self.inner.visit_evec_box(mtbl, inner) { return false; } - self.bump_past::<@[u8]>(); true } diff --git a/src/libstd/repr.rs b/src/libstd/repr.rs index 8ecb3395542..41ddf027787 100644 --- a/src/libstd/repr.rs +++ b/src/libstd/repr.rs @@ -637,12 +637,6 @@ fn test_repr() { exact_test(&(0 as *mut ()), "(0x0 as *mut ())"); exact_test(&(1,), "(1,)"); - exact_test(&(@[1,2,3,4,5,6,7,8]), - "@[1, 2, 3, 4, 5, 6, 7, 8]"); - exact_test(&(@[1u8,2u8,3u8,4u8]), - "@[1u8, 2u8, 3u8, 4u8]"); - exact_test(&(@["hi", "there"]), - "@[\"hi\", \"there\"]"); exact_test(&(~["hi", "there"]), "~[\"hi\", \"there\"]"); exact_test(&(&["hi", "there"]), diff --git a/src/libstd/rt/local_heap.rs b/src/libstd/rt/local_heap.rs index 42a7e7867f9..79936b4afad 100644 --- a/src/libstd/rt/local_heap.rs +++ b/src/libstd/rt/local_heap.rs @@ -332,6 +332,6 @@ mod bench { #[bench] fn alloc_managed_big(bh: &mut BenchHarness) { - bh.iter(|| { @[10, ..1000]; }); + bh.iter(|| { @([10, ..1000]); }); } } diff --git a/src/libstd/to_bytes.rs b/src/libstd/to_bytes.rs index 7ca1590dad0..4c545de73b4 100644 --- a/src/libstd/to_bytes.rs +++ b/src/libstd/to_bytes.rs @@ -266,13 +266,6 @@ impl IterBytes for ~[A] { } } -impl IterBytes for @[A] { - #[inline] - fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { - self.as_slice().iter_bytes(lsb0, f) - } -} - impl<'a> IterBytes for &'a str { #[inline] fn iter_bytes(&self, _lsb0: bool, f: Cb) -> bool { diff --git a/src/libstd/to_str.rs b/src/libstd/to_str.rs index edbf3314417..87d59f09791 100644 --- a/src/libstd/to_str.rs +++ b/src/libstd/to_str.rs @@ -159,25 +159,6 @@ impl ToStr for ~[A] { } } -impl ToStr for @[A] { - #[inline] - fn to_str(&self) -> ~str { - let mut acc = ~"["; - let mut first = true; - for elt in self.iter() { - if first { - first = false; - } - else { - acc.push_str(", "); - } - acc.push_str(elt.to_str()); - } - acc.push_char(']'); - acc - } -} - #[cfg(test)] mod tests { use hashmap::HashMap; diff --git a/src/libstd/unstable/raw.rs b/src/libstd/unstable/raw.rs index c568edd09d1..63208b3f2d7 100644 --- a/src/libstd/unstable/raw.rs +++ b/src/libstd/unstable/raw.rs @@ -56,7 +56,6 @@ pub trait Repr { impl<'a, T> Repr> for &'a [T] {} impl<'a> Repr> for &'a str {} impl Repr<*Box> for @T {} -impl Repr<*Box>> for @[T] {} impl Repr<*Vec> for ~[T] {} impl Repr<*String> for ~str {} diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 15cd5ce3343..2679ef0d46e 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -646,13 +646,6 @@ pub mod traits { fn ne(&self, other: &~[T]) -> bool { !self.eq(other) } } - impl Eq for @[T] { - #[inline] - fn eq(&self, other: &@[T]) -> bool { self.as_slice() == *other } - #[inline] - fn ne(&self, other: &@[T]) -> bool { !self.eq(other) } - } - impl<'a,T:TotalEq> TotalEq for &'a [T] { fn equals(&self, other: & &'a [T]) -> bool { self.len() == other.len() && @@ -665,11 +658,6 @@ pub mod traits { fn equals(&self, other: &~[T]) -> bool { self.as_slice().equals(&other.as_slice()) } } - impl TotalEq for @[T] { - #[inline] - fn equals(&self, other: &@[T]) -> bool { self.as_slice().equals(&other.as_slice()) } - } - impl<'a,T:Eq, V: Vector> Equiv for &'a [T] { #[inline] fn equiv(&self, other: &V) -> bool { self.as_slice() == other.as_slice() } @@ -680,11 +668,6 @@ pub mod traits { fn equiv(&self, other: &V) -> bool { self.as_slice() == other.as_slice() } } - impl<'a,T:Eq, V: Vector> Equiv for @[T] { - #[inline] - fn equiv(&self, other: &V) -> bool { self.as_slice() == other.as_slice() } - } - impl<'a,T:TotalOrd> TotalOrd for &'a [T] { fn cmp(&self, other: & &'a [T]) -> Ordering { order::cmp(self.iter(), other.iter()) @@ -696,11 +679,6 @@ pub mod traits { fn cmp(&self, other: &~[T]) -> Ordering { self.as_slice().cmp(&other.as_slice()) } } - impl TotalOrd for @[T] { - #[inline] - fn cmp(&self, other: &@[T]) -> Ordering { self.as_slice().cmp(&other.as_slice()) } - } - impl<'a, T: Eq + Ord> Ord for &'a [T] { fn lt(&self, other: & &'a [T]) -> bool { order::lt(self.iter(), other.iter()) @@ -730,17 +708,6 @@ pub mod traits { fn gt(&self, other: &~[T]) -> bool { self.as_slice() > other.as_slice() } } - impl Ord for @[T] { - #[inline] - fn lt(&self, other: &@[T]) -> bool { self.as_slice() < other.as_slice() } - #[inline] - fn le(&self, other: &@[T]) -> bool { self.as_slice() <= other.as_slice() } - #[inline] - fn ge(&self, other: &@[T]) -> bool { self.as_slice() >= other.as_slice() } - #[inline] - fn gt(&self, other: &@[T]) -> bool { self.as_slice() > other.as_slice() } - } - impl<'a,T:Clone, V: Vector> Add for &'a [T] { #[inline] fn add(&self, rhs: &V) -> ~[T] { @@ -778,11 +745,6 @@ impl Vector for ~[T] { fn as_slice<'a>(&'a self) -> &'a [T] { let v: &'a [T] = *self; v } } -impl Vector for @[T] { - #[inline(always)] - fn as_slice<'a>(&'a self) -> &'a [T] { let v: &'a [T] = *self; v } -} - impl<'a, T> Container for &'a [T] { /// Returns the length of a vector #[inline] @@ -833,15 +795,6 @@ impl CloneableVector for ~[T] { fn into_owned(self) -> ~[T] { self } } -/// Extension methods for managed vectors -impl CloneableVector for @[T] { - #[inline] - fn to_owned(&self) -> ~[T] { self.as_slice().to_owned() } - - #[inline(always)] - fn into_owned(self) -> ~[T] { self.to_owned() } -} - /// Extension methods for vectors pub trait ImmutableVector<'a, T> { /** @@ -2629,10 +2582,6 @@ impl Default for ~[A] { fn default() -> ~[A] { ~[] } } -impl Default for @[A] { - fn default() -> @[A] { @[] } -} - macro_rules! iterator { (struct $name:ident -> $ptr:ty, $elem:ty) => { /// An iterator for iterating over a vector. @@ -3109,14 +3058,6 @@ mod tests { assert_eq!(v_b[0], 2); assert_eq!(v_b[1], 3); - // Test on managed heap. - let vec_managed = @[1, 2, 3, 4, 5]; - let v_c = vec_managed.slice(0u, 3u).to_owned(); - assert_eq!(v_c.len(), 3u); - assert_eq!(v_c[0], 1); - assert_eq!(v_c[1], 2); - assert_eq!(v_c[2], 3); - // Test on exchange heap. let vec_unique = ~[1, 2, 3, 4, 5, 6]; let v_d = vec_unique.slice(1u, 6u).to_owned(); @@ -4052,7 +3993,6 @@ mod tests { ); t!(&[int]); - t!(@[int]); t!(~[int]); } -- cgit 1.4.1-3-g733a5 From f8734df51500bdc924f2b504e0d7ecbe1d01bfc0 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Sat, 1 Feb 2014 15:57:59 +1100 Subject: rustc: remove use of @[]. --- src/librustc/metadata/csearch.rs | 5 +- src/librustc/metadata/decoder.rs | 18 +++--- src/librustc/metadata/encoder.rs | 16 ++--- src/librustc/middle/astencode.rs | 20 +++--- src/librustc/middle/borrowck/check_loans.rs | 3 +- .../middle/borrowck/gather_loans/gather_moves.rs | 2 +- src/librustc/middle/const_eval.rs | 5 +- src/librustc/middle/kind.rs | 7 ++- src/librustc/middle/liveness.rs | 2 +- src/librustc/middle/moves.rs | 25 ++++---- src/librustc/middle/subst.rs | 10 +-- src/librustc/middle/trans/callee.rs | 2 +- src/librustc/middle/trans/closure.rs | 4 +- src/librustc/middle/trans/inline.rs | 2 +- src/librustc/middle/trans/meth.rs | 4 +- src/librustc/middle/ty.rs | 29 +++++---- src/librustc/middle/typeck/astconv.rs | 8 +-- src/librustc/middle/typeck/check/_match.rs | 7 +-- src/librustc/middle/typeck/check/method.rs | 2 +- src/librustc/middle/typeck/check/mod.rs | 64 +++++++++---------- src/librustc/middle/typeck/check/vtable.rs | 18 +++--- src/librustc/middle/typeck/coherence.rs | 26 ++++---- src/librustc/middle/typeck/collect.rs | 71 +++++++++++----------- src/librustc/middle/typeck/mod.rs | 5 +- src/librustc/middle/typeck/variance.rs | 4 +- src/librustc/util/ppaux.rs | 8 +-- src/libstd/reflect.rs | 2 +- 27 files changed, 189 insertions(+), 180 deletions(-) (limited to 'src/libstd') diff --git a/src/librustc/metadata/csearch.rs b/src/librustc/metadata/csearch.rs index 8d5be0cfb82..1a65b326bbd 100644 --- a/src/librustc/metadata/csearch.rs +++ b/src/librustc/metadata/csearch.rs @@ -18,6 +18,7 @@ use middle::ty; use middle::typeck; use std::vec; +use std::rc::Rc; use reader = extra::ebml::reader; use syntax::ast; use syntax::ast_map; @@ -221,8 +222,8 @@ pub fn get_field_type(tcx: ty::ctxt, class_id: ast::DefId, class_id, def) ); let ty = decoder::item_type(def, the_field, tcx, cdata); ty::ty_param_bounds_and_ty { - generics: ty::Generics {type_param_defs: @~[], - region_param_defs: @[]}, + generics: ty::Generics {type_param_defs: Rc::new(~[]), + region_param_defs: Rc::new(~[])}, ty: ty } } diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index 7e866b32631..8514025f9dd 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -25,11 +25,11 @@ use middle::ty; use middle::typeck; use middle::astencode::vtable_decoder_helpers; -use std::at_vec; use std::u64; use std::io; use std::io::extensions::u64_from_be_bytes; use std::option; +use std::rc::Rc; use std::vec; use extra::ebml::reader; use extra::ebml; @@ -246,7 +246,7 @@ fn item_ty_param_defs(item: ebml::Doc, tcx: ty::ctxt, cdata: Cmd, tag: uint) - -> @~[ty::TypeParameterDef] { + -> Rc<~[ty::TypeParameterDef]> { let mut bounds = ~[]; reader::tagged_docs(item, tag, |p| { let bd = parse_type_param_def_data( @@ -255,15 +255,15 @@ fn item_ty_param_defs(item: ebml::Doc, bounds.push(bd); true }); - @bounds + Rc::new(bounds) } fn item_region_param_defs(item_doc: ebml::Doc, tcx: ty::ctxt, cdata: Cmd) - -> @[ty::RegionParameterDef] { - at_vec::build(None, |push| { - reader::tagged_docs(item_doc, tag_region_param_def, |rp_doc| { + -> Rc<~[ty::RegionParameterDef]> { + let mut v = ~[]; + reader::tagged_docs(item_doc, tag_region_param_def, |rp_doc| { let ident_str_doc = reader::get_doc(rp_doc, tag_region_param_def_ident); let ident = item_name(tcx.sess.intr(), ident_str_doc); @@ -271,11 +271,11 @@ fn item_region_param_defs(item_doc: ebml::Doc, tag_region_param_def_def_id); let def_id = reader::with_doc_data(def_id_doc, parse_def_id); let def_id = translate_def_id(cdata, def_id); - push(ty::RegionParameterDef { ident: ident, - def_id: def_id }); + v.push(ty::RegionParameterDef { ident: ident, + def_id: def_id }); true }); - }) + Rc::new(v) } fn item_ty_param_count(item: ebml::Doc) -> uint { diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index c7ba3ab01e9..4170d572f20 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -171,7 +171,7 @@ pub fn def_to_str(did: DefId) -> ~str { fn encode_ty_type_param_defs(ebml_w: &mut writer::Encoder, ecx: &EncodeContext, - params: @~[ty::TypeParameterDef], + params: &[ty::TypeParameterDef], tag: uint) { let ty_str_ctxt = @tyencode::ctxt { diag: ecx.diag, @@ -188,7 +188,7 @@ fn encode_ty_type_param_defs(ebml_w: &mut writer::Encoder, fn encode_region_param_defs(ebml_w: &mut writer::Encoder, ecx: &EncodeContext, - params: @[ty::RegionParameterDef]) { + params: &[ty::RegionParameterDef]) { for param in params.iter() { ebml_w.start_tag(tag_region_param_def); @@ -215,9 +215,9 @@ fn encode_item_variances(ebml_w: &mut writer::Encoder, fn encode_bounds_and_type(ebml_w: &mut writer::Encoder, ecx: &EncodeContext, tpt: &ty::ty_param_bounds_and_ty) { - encode_ty_type_param_defs(ebml_w, ecx, tpt.generics.type_param_defs, + encode_ty_type_param_defs(ebml_w, ecx, tpt.generics.type_param_defs(), tag_items_data_item_ty_param_bounds); - encode_region_param_defs(ebml_w, ecx, tpt.generics.region_param_defs); + encode_region_param_defs(ebml_w, ecx, tpt.generics.region_param_defs()); encode_type(ecx, ebml_w, tpt.ty); } @@ -786,7 +786,7 @@ fn encode_method_ty_fields(ecx: &EncodeContext, encode_def_id(ebml_w, method_ty.def_id); encode_name(ecx, ebml_w, method_ty.ident); encode_ty_type_param_defs(ebml_w, ecx, - method_ty.generics.type_param_defs, + method_ty.generics.type_param_defs(), tag_item_method_tps); encode_method_fty(ecx, ebml_w, &method_ty.fty); encode_visibility(ebml_w, method_ty.vis); @@ -827,7 +827,7 @@ fn encode_info_for_method(ecx: &EncodeContext, } for &ast_method in ast_method_opt.iter() { - let num_params = tpt.generics.type_param_defs.len(); + let num_params = tpt.generics.type_param_defs().len(); if num_params > 0u || is_default_impl || should_inline(ast_method.attrs) { (ecx.encode_inlined_item)( @@ -1171,10 +1171,10 @@ fn encode_info_for_item(ecx: &EncodeContext, encode_item_variances(ebml_w, ecx, item.id); let trait_def = ty::lookup_trait_def(tcx, def_id); encode_ty_type_param_defs(ebml_w, ecx, - trait_def.generics.type_param_defs, + trait_def.generics.type_param_defs(), tag_items_data_item_ty_param_bounds); encode_region_param_defs(ebml_w, ecx, - trait_def.generics.region_param_defs); + trait_def.generics.region_param_defs()); encode_trait_ref(ebml_w, ecx, trait_def.trait_ref, tag_item_trait_ref); encode_name(ecx, ebml_w, item.ident); encode_attributes(ebml_w, item.attrs); diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index a601b624c19..29ea3475d34 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -32,10 +32,10 @@ use syntax::fold::Folder; use syntax::parse::token; use syntax; -use std::at_vec; use std::libc; use std::cast; use std::io::Seek; +use std::rc::Rc; use extra::ebml::reader; use extra::ebml; @@ -812,13 +812,13 @@ impl<'a> ebml_writer_helpers for writer::Encoder<'a> { this.emit_struct_field("generics", 0, |this| { this.emit_struct("Generics", 2, |this| { this.emit_struct_field("type_param_defs", 0, |this| { - this.emit_from_vec(*tpbt.generics.type_param_defs, + this.emit_from_vec(tpbt.generics.type_param_defs(), |this, type_param_def| { this.emit_type_param_def(ecx, type_param_def); }) }); this.emit_struct_field("region_param_defs", 1, |this| { - tpbt.generics.region_param_defs.encode(this); + tpbt.generics.region_param_defs().encode(this); }) }) }); @@ -997,7 +997,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, ebml_w.tag(c::tag_table_tcache, |ebml_w| { ebml_w.id(id); ebml_w.tag(c::tag_table_val, |ebml_w| { - ebml_w.emit_tpbt(ecx, *tpbt); + ebml_w.emit_tpbt(ecx, tpbt.clone()); }) }) } @@ -1064,7 +1064,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, ebml_w.tag(c::tag_table_capture_map, |ebml_w| { ebml_w.id(id); ebml_w.tag(c::tag_table_val, |ebml_w| { - ebml_w.emit_from_vec(*cap_vars, |ebml_w, cap_var| { + ebml_w.emit_from_vec(*cap_vars.borrow(), |ebml_w, cap_var| { cap_var.encode(ebml_w); }) }) @@ -1183,8 +1183,8 @@ impl<'a> ebml_decoder_decoder_helpers for reader::Decoder<'a> { this.read_struct_field("type_param_defs", 0, |this| { - @this.read_to_vec(|this| - this.read_type_param_def(xcx)) + Rc::new(this.read_to_vec(|this| + this.read_type_param_def(xcx))) }), region_param_defs: this.read_struct_field("region_param_defs", @@ -1382,13 +1382,11 @@ fn decode_side_tables(xcx: @ExtendedDecodeContext, } c::tag_table_capture_map => { let cvars = - at_vec::to_managed_move( - val_dsr.read_to_vec( - |val_dsr| val_dsr.read_capture_var(xcx))); + val_dsr.read_to_vec(|val_dsr| val_dsr.read_capture_var(xcx)); let mut capture_map = dcx.maps .capture_map .borrow_mut(); - capture_map.get().insert(id, cvars); + capture_map.get().insert(id, Rc::new(cvars)); } _ => { xcx.dcx.tcx.sess.bug( diff --git a/src/librustc/middle/borrowck/check_loans.rs b/src/librustc/middle/borrowck/check_loans.rs index 59310d722e4..b280da31c45 100644 --- a/src/librustc/middle/borrowck/check_loans.rs +++ b/src/librustc/middle/borrowck/check_loans.rs @@ -733,7 +733,7 @@ fn check_loans_in_fn<'a>(this: &mut CheckLoanCtxt<'a>, span: Span) { let capture_map = this.bccx.capture_map.borrow(); let cap_vars = capture_map.get().get(&closure_id); - for cap_var in cap_vars.iter() { + for cap_var in cap_vars.borrow().iter() { let var_id = ast_util::def_id_of_def(cap_var.def).node; let var_path = @LpVar(var_id); this.check_if_path_is_moved(closure_id, span, @@ -839,4 +839,3 @@ fn check_loans_in_block<'a>(this: &mut CheckLoanCtxt<'a>, visit::walk_block(this, blk, ()); this.check_for_conflicting_loans(blk.id); } - diff --git a/src/librustc/middle/borrowck/gather_loans/gather_moves.rs b/src/librustc/middle/borrowck/gather_loans/gather_moves.rs index 78350a993b4..0d9b4b0b171 100644 --- a/src/librustc/middle/borrowck/gather_loans/gather_moves.rs +++ b/src/librustc/middle/borrowck/gather_loans/gather_moves.rs @@ -69,7 +69,7 @@ pub fn gather_captures(bccx: &BorrowckCtxt, closure_expr: &ast::Expr) { let capture_map = bccx.capture_map.borrow(); let captured_vars = capture_map.get().get(&closure_expr.id); - for captured_var in captured_vars.iter() { + for captured_var in captured_vars.borrow().iter() { match captured_var.mode { moves::CapMove => { let fvar_id = ast_util::def_id_of_def(captured_var.def).node; diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index 51410068378..d0ca53116b8 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -24,6 +24,7 @@ use syntax::{ast, ast_map, ast_util}; use std::cell::RefCell; use std::hashmap::HashMap; +use std::rc::Rc; // // This pass classifies expressions by their constant-ness. @@ -321,7 +322,7 @@ pub enum const_val { const_int(i64), const_uint(u64), const_str(InternedString), - const_binary(@[u8]), + const_binary(Rc<~[u8]>), const_bool(bool) } @@ -510,7 +511,7 @@ pub fn eval_const_expr_partial(tcx: &T, e: &Expr) pub fn lit_to_const(lit: &Lit) -> const_val { match lit.node { LitStr(ref s, _) => const_str((*s).clone()), - LitBinary(data) => const_binary(data), + LitBinary(ref data) => const_binary(data.clone()), LitChar(n) => const_uint(n as u64), LitInt(n, _) => const_int(n), LitUint(n, _) => const_uint(n), diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index c05ca3e8769..0d6dc6572c3 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -277,7 +277,7 @@ pub fn check_expr(cx: &mut Context, e: &Expr) { ExprPath(_) => { let did = ast_util::def_id_of_def(def_map.get() .get_copy(&e.id)); - ty::lookup_item_type(cx.tcx, did).generics.type_param_defs + ty::lookup_item_type(cx.tcx, did).generics.type_param_defs.clone() } _ => { // Type substitutions should only occur on paths and @@ -289,6 +289,7 @@ pub fn check_expr(cx: &mut Context, e: &Expr) { "non path/method call expr has type substs??") } }; + let type_param_defs = type_param_defs.borrow(); if ts.len() != type_param_defs.len() { // Fail earlier to make debugging easier fail!("internal error: in kind::check_expr, length \ @@ -362,8 +363,8 @@ fn check_ty(cx: &mut Context, aty: &Ty) { for ts in r.iter() { let def_map = cx.tcx.def_map.borrow(); let did = ast_util::def_id_of_def(def_map.get().get_copy(&id)); - let type_param_defs = - ty::lookup_item_type(cx.tcx, did).generics.type_param_defs; + let generics = ty::lookup_item_type(cx.tcx, did).generics; + let type_param_defs = generics.type_param_defs(); for (&ty, type_param_def) in ts.iter().zip(type_param_defs.iter()) { check_typaram_bounds(cx, aty.id, aty.span, ty, type_param_def) } diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index ed583f919ca..fb5e548e12f 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -502,7 +502,7 @@ fn visit_expr(v: &mut LivenessVisitor, expr: &Expr, this: @IrMaps) { let capture_map = this.capture_map.borrow(); let cvs = capture_map.get().get(&expr.id); let mut call_caps = ~[]; - for cv in cvs.iter() { + for cv in cvs.borrow().iter() { match moves::moved_variable_node_id_from_def(cv.def) { Some(rv) => { let cv_ln = this.add_live_node(FreeVarNode(cv.span)); diff --git a/src/librustc/middle/moves.rs b/src/librustc/middle/moves.rs index b0171eafeb3..d73d7f3d6f1 100644 --- a/src/librustc/middle/moves.rs +++ b/src/librustc/middle/moves.rs @@ -136,9 +136,9 @@ use util::ppaux::Repr; use util::common::indenter; use util::ppaux::UserString; -use std::at_vec; use std::cell::RefCell; use std::hashmap::{HashSet, HashMap}; +use std::rc::Rc; use syntax::ast::*; use syntax::ast_util; use syntax::visit; @@ -159,7 +159,7 @@ pub struct CaptureVar { mode: CaptureMode // How variable is being accessed } -pub type CaptureMap = @RefCell>; +pub type CaptureMap = @RefCell>>; pub type MovesMap = @RefCell>; @@ -681,23 +681,22 @@ impl VisitContext { self.consume_expr(arg_expr) } - pub fn compute_captures(&mut self, fn_expr_id: NodeId) -> @[CaptureVar] { + pub fn compute_captures(&mut self, fn_expr_id: NodeId) -> Rc<~[CaptureVar]> { debug!("compute_capture_vars(fn_expr_id={:?})", fn_expr_id); let _indenter = indenter(); let fn_ty = ty::node_id_to_type(self.tcx, fn_expr_id); let sigil = ty::ty_closure_sigil(fn_ty); let freevars = freevars::get_freevars(self.tcx, fn_expr_id); - if sigil == BorrowedSigil { + let v = if sigil == BorrowedSigil { // || captures everything by ref - at_vec::from_fn(freevars.len(), |i| { - let fvar = &freevars[i]; - CaptureVar {def: fvar.def, span: fvar.span, mode: CapRef} - }) + freevars.iter() + .map(|fvar| CaptureVar {def: fvar.def, span: fvar.span, mode: CapRef}) + .collect() } else { // @fn() and ~fn() capture by copy or by move depending on type - at_vec::from_fn(freevars.len(), |i| { - let fvar = &freevars[i]; + freevars.iter() + .map(|fvar| { let fvar_def_id = ast_util::def_id_of_def(fvar.def).node; let fvar_ty = ty::node_id_to_type(self.tcx, fvar_def_id); debug!("fvar_def_id={:?} fvar_ty={}", @@ -708,7 +707,9 @@ impl VisitContext { CapCopy }; CaptureVar {def: fvar.def, span: fvar.span, mode:mode} - }) - } + + }).collect() + }; + Rc::new(v) } } diff --git a/src/librustc/middle/subst.rs b/src/librustc/middle/subst.rs index 067082992c6..c4a30171687 100644 --- a/src/librustc/middle/subst.rs +++ b/src/librustc/middle/subst.rs @@ -13,8 +13,9 @@ use middle::ty; use middle::ty_fold; use middle::ty_fold::TypeFolder; + +use std::rc::Rc; use syntax::opt_vec::OptVec; -use std::at_vec; /////////////////////////////////////////////////////////////////////////// // Public trait `Subst` @@ -84,10 +85,9 @@ impl Subst for ~[T] { self.map(|t| t.subst(tcx, substs)) } } - -impl Subst for @[T] { - fn subst(&self, tcx: ty::ctxt, substs: &ty::substs) -> @[T] { - at_vec::map(*self, |t| t.subst(tcx, substs)) +impl Subst for Rc { + fn subst(&self, tcx: ty::ctxt, substs: &ty::substs) -> Rc { + Rc::new(self.borrow().subst(tcx, substs)) } } diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index e10c7af7f31..80d92d85686 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -220,7 +220,7 @@ fn resolve_default_method_vtables(bcx: &Block, bcx.tcx(), param_substs, impl_res.trait_vtables); // Now we pull any vtables for parameters on the actual method. - let num_method_vtables = method.generics.type_param_defs.len(); + let num_method_vtables = method.generics.type_param_defs().len(); let method_vtables = match impl_vtables { Some(vtables) => { let num_impl_type_parameters = diff --git a/src/librustc/middle/trans/closure.rs b/src/librustc/middle/trans/closure.rs index d1979c3fee7..c9631a72ee7 100644 --- a/src/librustc/middle/trans/closure.rs +++ b/src/librustc/middle/trans/closure.rs @@ -403,11 +403,11 @@ pub fn trans_expr_fn<'a>( let capture_map = ccx.maps.capture_map.borrow(); capture_map.get().get_copy(&user_id) }; - let ClosureResult {llbox, cdata_ty, bcx} = build_closure(bcx, cap_vars, sigil); + let ClosureResult {llbox, cdata_ty, bcx} = build_closure(bcx, *cap_vars.borrow(), sigil); trans_closure(ccx, sub_path, decl, body, llfn, bcx.fcx.param_substs, user_id, [], ty::ty_fn_ret(fty), - |bcx| load_environment(bcx, cdata_ty, cap_vars, sigil)); + |bcx| load_environment(bcx, cdata_ty, *cap_vars.borrow(), sigil)); fill_fn_pair(bcx, dest_addr, llfn, llbox); bcx diff --git a/src/librustc/middle/trans/inline.rs b/src/librustc/middle/trans/inline.rs index 3a0b97813df..c60199b3c0d 100644 --- a/src/librustc/middle/trans/inline.rs +++ b/src/librustc/middle/trans/inline.rs @@ -152,7 +152,7 @@ pub fn maybe_instantiate_inline(ccx: @CrateContext, fn_id: ast::DefId) let impl_tpt = ty::lookup_item_type(ccx.tcx, impl_did); let num_type_params = - impl_tpt.generics.type_param_defs.len() + + impl_tpt.generics.type_param_defs().len() + mth.generics.ty_params.len(); if num_type_params == 0 { diff --git a/src/librustc/middle/trans/meth.rs b/src/librustc/middle/trans/meth.rs index 09bfa36ddc1..b13a8800cee 100644 --- a/src/librustc/middle/trans/meth.rs +++ b/src/librustc/middle/trans/meth.rs @@ -182,7 +182,7 @@ pub fn trans_static_method_callee(bcx: &Block, // out which impl the `Trait` bound on the type `self` was // bound to. let bound_index = ty::lookup_trait_def(bcx.tcx(), trait_id). - generics.type_param_defs.len(); + generics.type_param_defs().len(); let mname = if method_id.crate == ast::LOCAL_CRATE { { @@ -318,7 +318,7 @@ pub fn combine_impl_and_methods_tps(bcx: &Block, let ccx = bcx.ccx(); let method = ty::method(ccx.tcx, mth_did); - let n_m_tps = method.generics.type_param_defs.len(); + let n_m_tps = method.generics.type_param_defs().len(); let node_substs = node_id_type_params(bcx, callee_id); debug!("rcvr_substs={:?}", rcvr_substs.repr(ccx.tcx)); let ty_substs diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 066be142f24..dd7c0803333 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -34,6 +34,7 @@ use std::cmp; use std::hashmap::{HashMap, HashSet}; use std::ops; use std::ptr::to_unsafe_ptr; +use std::rc::Rc; use std::to_bytes; use std::to_str::ToStr; use std::vec; @@ -870,15 +871,21 @@ pub struct RegionParameterDef { #[deriving(Clone)] pub struct Generics { /// List of type parameters declared on the item. - type_param_defs: @~[TypeParameterDef], + type_param_defs: Rc<~[TypeParameterDef]>, /// List of region parameters declared on the item. - region_param_defs: @[RegionParameterDef], + region_param_defs: Rc<~[RegionParameterDef]>, } impl Generics { pub fn has_type_params(&self) -> bool { - !self.type_param_defs.is_empty() + !self.type_param_defs.borrow().is_empty() + } + pub fn type_param_defs<'a>(&'a self) -> &'a [TypeParameterDef] { + self.type_param_defs.borrow().as_slice() + } + pub fn region_param_defs<'a>(&'a self) -> &'a [RegionParameterDef] { + self.region_param_defs.borrow().as_slice() } } @@ -3105,7 +3112,7 @@ pub fn expr_has_ty_params(cx: ctxt, expr: &ast::Expr) -> bool { pub fn method_call_type_param_defs(tcx: ctxt, method_map: typeck::method_map, id: ast::NodeId) - -> Option<@~[TypeParameterDef]> { + -> Option> { let method_map = method_map.borrow(); method_map.get().find(&id).map(|method| { match method.origin { @@ -3125,12 +3132,12 @@ pub fn method_call_type_param_defs(tcx: ctxt, // method bounds, so we must preprend the tps from the // trait itself. This ought to be harmonized. let trait_type_param_defs = - lookup_trait_def(tcx, trt_id).generics.type_param_defs; - @vec::append( - (*trait_type_param_defs).clone(), - *ty::trait_method(tcx, - trt_id, - n_mth).generics.type_param_defs) + lookup_trait_def(tcx, trt_id).generics.type_param_defs(); + Rc::new(vec::append( + trait_type_param_defs.to_owned(), + ty::trait_method(tcx, + trt_id, + n_mth).generics.type_param_defs())) } } }) @@ -4212,7 +4219,7 @@ pub fn lookup_field_type(tcx: ctxt, Some(&ty_param_bounds_and_ty {ty, ..}) => ty, None => { let tpt = csearch::get_field_type(tcx, struct_id, id); - tcache.get().insert(id, tpt); + tcache.get().insert(id, tpt.clone()); tpt.ty } } diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 9f8b9140417..0cc646aa5c3 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -170,7 +170,7 @@ fn ast_path_substs( // If the type is parameterized by the this region, then replace this // region with the current anon region binding (in other words, // whatever & would get replaced with). - let expected_num_region_params = decl_generics.region_param_defs.len(); + let expected_num_region_params = decl_generics.region_param_defs().len(); let supplied_num_region_params = path.segments.last().unwrap().lifetimes.len(); let regions = if expected_num_region_params == supplied_num_region_params { path.segments.last().unwrap().lifetimes.map( @@ -197,8 +197,8 @@ fn ast_path_substs( // Convert the type parameters supplied by the user. let supplied_ty_param_count = path.segments.iter().flat_map(|s| s.types.iter()).len(); - let formal_ty_param_count = decl_generics.type_param_defs.len(); - let required_ty_param_count = decl_generics.type_param_defs.iter() + let formal_ty_param_count = decl_generics.type_param_defs().len(); + let required_ty_param_count = decl_generics.type_param_defs().iter() .take_while(|x| x.default.is_none()) .len(); if supplied_ty_param_count < required_ty_param_count { @@ -228,7 +228,7 @@ fn ast_path_substs( ~"provided type arguments with defaults"); } - let defaults = decl_generics.type_param_defs.slice_from(supplied_ty_param_count) + let defaults = decl_generics.type_param_defs().slice_from(supplied_ty_param_count) .iter().map(|&x| x.default.unwrap()); let tps = path.segments.iter().flat_map(|s| s.types.iter()) .map(|&a_t| ast_ty_to_ty(this, rscope, a_t)) diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index 37862943dd7..e57e3ff4712 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -147,7 +147,7 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: &ast::Pat, path: &ast::Path, ty::enum_variant_with_id(tcx, enm, var); let var_tpt = ty::lookup_item_type(tcx, var); vinfo.args.map(|t| { - if var_tpt.generics.type_param_defs.len() == + if var_tpt.generics.type_param_defs().len() == expected_substs.tps.len() { ty::subst(tcx, expected_substs, *t) @@ -172,7 +172,7 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: &ast::Pat, path: &ast::Path, None); fcx.write_error(pat.id); kind_name = "[error]"; - arg_types = (*subpats).clone() + arg_types = subpats.clone() .unwrap_or_default() .map(|_| ty::mk_err()); } @@ -221,7 +221,7 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: &ast::Pat, path: &ast::Path, None); fcx.write_error(pat.id); kind_name = "[error]"; - arg_types = (*subpats).clone() + arg_types = subpats.clone() .unwrap_or_default() .map(|_| ty::mk_err()); } @@ -699,4 +699,3 @@ pub fn check_pointer_pat(pcx: &pat_ctxt, #[deriving(Eq)] enum PointerKind { Send, Borrowed } - diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index 09d04753def..e7e4f61741f 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -954,7 +954,7 @@ impl<'a> LookupContext<'a> { // If they were not explicitly supplied, just construct fresh // type variables. let num_supplied_tps = self.supplied_tps.len(); - let num_method_tps = candidate.method_ty.generics.type_param_defs.len(); + let num_method_tps = candidate.method_ty.generics.type_param_defs().len(); let m_substs = { if num_supplied_tps == 0u { self.fcx.infcx().next_ty_vars(num_method_tps) diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 121b0486fb1..f446326eb16 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -564,7 +564,7 @@ pub fn check_item(ccx: @CrateCtxt, it: &ast::Item) { let param_env = ty::construct_parameter_environment( ccx.tcx, None, - *fn_tpt.generics.type_param_defs, + fn_tpt.generics.type_param_defs(), [], [], body.id); @@ -674,9 +674,9 @@ fn check_method_body(ccx: @CrateCtxt, ty::construct_parameter_environment( ccx.tcx, self_bound, - *item_generics.type_param_defs, - *method_generics.type_param_defs, - item_generics.region_param_defs, + item_generics.type_param_defs(), + method_generics.type_param_defs(), + item_generics.region_param_defs(), method.body.id); // Compute the fty from point of view of inside fn @@ -776,7 +776,7 @@ fn compare_impl_method(tcx: ty::ctxt, debug!("compare_impl_method()"); let infcx = infer::new_infer_ctxt(tcx); - let impl_tps = impl_generics.type_param_defs.len(); + let impl_tps = impl_generics.type_param_defs().len(); // Try to give more informative error messages about self typing // mismatches. Note that any mismatch will also be detected @@ -812,8 +812,8 @@ fn compare_impl_method(tcx: ty::ctxt, } } - let num_impl_m_type_params = impl_m.generics.type_param_defs.len(); - let num_trait_m_type_params = trait_m.generics.type_param_defs.len(); + let num_impl_m_type_params = impl_m.generics.type_param_defs().len(); + let num_trait_m_type_params = trait_m.generics.type_param_defs().len(); if num_impl_m_type_params != num_trait_m_type_params { tcx.sess.span_err( impl_m_span, @@ -838,10 +838,10 @@ fn compare_impl_method(tcx: ty::ctxt, return; } - for (i, trait_param_def) in trait_m.generics.type_param_defs.iter().enumerate() { - // For each of the corresponding impl ty param's bounds... - let impl_param_def = &impl_m.generics.type_param_defs[i]; + let it = trait_m.generics.type_param_defs().iter() + .zip(impl_m.generics.type_param_defs().iter()); + for (i, (trait_param_def, impl_param_def)) in it.enumerate() { // Check that the impl does not require any builtin-bounds // that the trait does not guarantee: let extra_bounds = @@ -886,15 +886,15 @@ fn compare_impl_method(tcx: ty::ctxt, // impl type is "&'a str", then this would replace the self // type with a free region `self`. let dummy_impl_tps: ~[ty::t] = - impl_generics.type_param_defs.iter().enumerate(). + impl_generics.type_param_defs().iter().enumerate(). map(|(i,t)| ty::mk_param(tcx, i, t.def_id)). collect(); let dummy_method_tps: ~[ty::t] = - impl_m.generics.type_param_defs.iter().enumerate(). + impl_m.generics.type_param_defs().iter().enumerate(). map(|(i,t)| ty::mk_param(tcx, i + impl_tps, t.def_id)). collect(); let dummy_impl_regions: OptVec = - impl_generics.region_param_defs.iter(). + impl_generics.region_param_defs().iter(). map(|l| ty::ReFree(ty::FreeRegion { scope_id: impl_m_body_id, bound_region: ty::BrNamed(l.def_id, l.ident)})). @@ -1374,8 +1374,8 @@ pub fn impl_self_ty(vcx: &VtableContext, let (n_tps, n_rps, raw_ty) = { let ity = ty::lookup_item_type(tcx, did); - (ity.generics.type_param_defs.len(), - ity.generics.region_param_defs.len(), + (ity.generics.type_param_defs().len(), + ity.generics.region_param_defs().len(), ity.ty) }; @@ -1419,10 +1419,10 @@ fn generics_of_static_method_container(type_context: ty::ctxt, -> ty::Generics { match provenance { ast::FromTrait(trait_def_id) => { - ty::lookup_trait_def(type_context, trait_def_id).generics + ty::lookup_trait_def(type_context, trait_def_id).generics.clone() } ast::FromImpl(impl_def_id) => { - ty::lookup_item_type(type_context, impl_def_id).generics + ty::lookup_item_type(type_context, impl_def_id).generics.clone() } } } @@ -1485,7 +1485,7 @@ fn check_type_parameter_positions_in_path(function_context: @FnCtxt, // Make sure lifetime parameterization agrees with the trait or // implementation type. - let trait_region_parameter_count = generics.region_param_defs.len(); + let trait_region_parameter_count = generics.region_param_defs().len(); let supplied_region_parameter_count = trait_segment.lifetimes.len(); if trait_region_parameter_count != supplied_region_parameter_count && supplied_region_parameter_count != 0 { @@ -1501,8 +1501,8 @@ fn check_type_parameter_positions_in_path(function_context: @FnCtxt, // Make sure the number of type parameters supplied on the trait // or implementation segment equals the number of type parameters // on the trait or implementation definition. - let formal_ty_param_count = generics.type_param_defs.len(); - let required_ty_param_count = generics.type_param_defs.iter() + let formal_ty_param_count = generics.type_param_defs().len(); + let required_ty_param_count = generics.type_param_defs().iter() .take_while(|x| x.default.is_none()) .len(); let supplied_ty_param_count = trait_segment.types.len(); @@ -1517,7 +1517,7 @@ fn check_type_parameter_positions_in_path(function_context: @FnCtxt, } else { "s" }; - let needs = if required_ty_param_count < generics.type_param_defs.len() { + let needs = if required_ty_param_count < generics.type_param_defs().len() { "needs at least" } else { "needs" @@ -1539,7 +1539,7 @@ fn check_type_parameter_positions_in_path(function_context: @FnCtxt, } else { "s" }; - let needs = if required_ty_param_count < generics.type_param_defs.len() { + let needs = if required_ty_param_count < generics.type_param_defs().len() { "needs at most" } else { "needs" @@ -2465,8 +2465,8 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt, // Look up the number of type parameters and the raw type, and // determine whether the class is region-parameterized. let item_type = ty::lookup_item_type(tcx, class_id); - let type_parameter_count = item_type.generics.type_param_defs.len(); - let region_parameter_count = item_type.generics.region_param_defs.len(); + let type_parameter_count = item_type.generics.type_param_defs().len(); + let region_parameter_count = item_type.generics.region_param_defs().len(); let raw_type = item_type.ty; // Generate the struct type. @@ -2523,8 +2523,8 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt, // Look up the number of type parameters and the raw type, and // determine whether the enum is region-parameterized. let item_type = ty::lookup_item_type(tcx, enum_id); - let type_parameter_count = item_type.generics.type_param_defs.len(); - let region_parameter_count = item_type.generics.region_param_defs.len(); + let type_parameter_count = item_type.generics.type_param_defs().len(); + let region_parameter_count = item_type.generics.region_param_defs().len(); let raw_type = item_type.ty; // Generate the enum type. @@ -3710,8 +3710,8 @@ pub fn instantiate_path(fcx: @FnCtxt, node_id: ast::NodeId) { debug!(">>> instantiate_path"); - let ty_param_count = tpt.generics.type_param_defs.len(); - let ty_param_req = tpt.generics.type_param_defs.iter() + let ty_param_count = tpt.generics.type_param_defs().len(); + let ty_param_req = tpt.generics.type_param_defs().iter() .take_while(|x| x.default.is_none()) .len(); let mut ty_substs_len = 0; @@ -3726,7 +3726,7 @@ pub fn instantiate_path(fcx: @FnCtxt, // determine the region parameters, using the value given by the user // (if any) and otherwise using a fresh region variable - let num_expected_regions = tpt.generics.region_param_defs.len(); + let num_expected_regions = tpt.generics.region_param_defs().len(); let num_supplied_regions = pth.segments.last().unwrap().lifetimes.len(); let regions = if num_expected_regions == num_supplied_regions { pth.segments.last().unwrap().lifetimes.map( @@ -3755,7 +3755,7 @@ pub fn instantiate_path(fcx: @FnCtxt, ast::DefStaticMethod(_, provenance @ ast::FromTrait(_), _) => { let generics = generics_of_static_method_container(fcx.ccx.tcx, provenance); - (ty_param_count - 1, ty_param_req - 1, Some(generics.type_param_defs.len())) + (ty_param_count - 1, ty_param_req - 1, Some(generics.type_param_defs().len())) } _ => (ty_param_count, ty_param_req, None), }; @@ -3800,7 +3800,7 @@ pub fn instantiate_path(fcx: @FnCtxt, // at the appropriate position. let mut result = ~[]; let mut pushed = false; - let defaults = tpt.generics.type_param_defs.iter() + let defaults = tpt.generics.type_param_defs().iter() .enumerate().filter_map(|(i, x)| { match self_parameter_index { Some(index) if index == i => None, @@ -4305,7 +4305,7 @@ pub fn check_intrinsic_type(ccx: @CrateCtxt, it: &ast::ForeignItem) { variadic: false} }); let i_ty = ty::lookup_item_type(ccx.tcx, local_def(it.id)); - let i_n_tps = i_ty.generics.type_param_defs.len(); + let i_n_tps = i_ty.generics.type_param_defs().len(); if i_n_tps != n_tps { tcx.sess.span_err(it.span, format!("intrinsic has wrong number \ of type parameters: found {}, \ diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index 0a231be5d45..4db43b2c913 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -423,7 +423,7 @@ fn search_for_vtable(vcx: &VtableContext, let im_generics = ty::lookup_item_type(tcx, im.did).generics; let subres = lookup_vtables(vcx, location_info, - *im_generics.type_param_defs, &substs, + im_generics.type_param_defs(), &substs, is_early); @@ -688,12 +688,12 @@ pub fn early_resolve_expr(ex: &ast::Expr, fcx: @FnCtxt, is_early: bool) { let item_ty = ty::lookup_item_type(cx.tcx, did); debug!("early resolve expr: def {:?} {:?}, {:?}, {}", ex.id, did, def, fcx.infcx().ty_to_str(item_ty.ty)); - if has_trait_bounds(*item_ty.generics.type_param_defs) { + if has_trait_bounds(item_ty.generics.type_param_defs()) { debug!("early_resolve_expr: looking up vtables for type params {}", - item_ty.generics.type_param_defs.repr(fcx.tcx())); + item_ty.generics.type_param_defs().repr(fcx.tcx())); let vcx = fcx.vtable_context(); let vtbls = lookup_vtables(&vcx, &location_info_for_expr(ex), - *item_ty.generics.type_param_defs, + item_ty.generics.type_param_defs(), substs, is_early); if !is_early { insert_vtables(fcx, ex.id, vtbls); @@ -717,11 +717,11 @@ pub fn early_resolve_expr(ex: &ast::Expr, fcx: @FnCtxt, is_early: bool) { Some(type_param_defs) => { debug!("vtable resolution on parameter bounds for method call {}", ex.repr(fcx.tcx())); - if has_trait_bounds(*type_param_defs) { + if has_trait_bounds(*type_param_defs.borrow()) { let substs = fcx.node_ty_substs(callee_id); let vcx = fcx.vtable_context(); let vtbls = lookup_vtables(&vcx, &location_info_for_expr(ex), - *type_param_defs, &substs, is_early); + *type_param_defs.borrow(), &substs, is_early); if !is_early { insert_vtables(fcx, callee_id, vtbls); } @@ -784,9 +784,9 @@ pub fn resolve_impl(ccx: @CrateCtxt, let param_env = ty::construct_parameter_environment( ccx.tcx, None, - *impl_generics.type_param_defs, + impl_generics.type_param_defs(), [], - impl_generics.region_param_defs, + impl_generics.region_param_defs(), impl_item.id); let impl_trait_ref = @impl_trait_ref.subst(ccx.tcx, ¶m_env.free_substs); @@ -800,7 +800,7 @@ pub fn resolve_impl(ccx: @CrateCtxt, let trait_def = ty::lookup_trait_def(ccx.tcx, impl_trait_ref.def_id); let vtbls = lookup_vtables(&vcx, &loc_info, - *trait_def.generics.type_param_defs, + trait_def.generics.type_param_defs(), &impl_trait_ref.substs, false); diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index 0dcb3c7329b..5ca879fea4a 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -47,13 +47,13 @@ use syntax::visit; use std::cell::RefCell; use std::hashmap::HashSet; -use std::result::Ok; +use std::rc::Rc; use std::vec; pub struct UniversalQuantificationResult { monotype: t, type_variables: ~[ty::t], - type_param_defs: @~[ty::TypeParameterDef] + type_param_defs: Rc<~[ty::TypeParameterDef]> } pub fn get_base_type(inference_context: @InferCtxt, @@ -356,11 +356,11 @@ impl CoherenceChecker { // construct the polytype for the method based on the method_ty let new_generics = ty::Generics { type_param_defs: - @vec::append( - (*impl_poly_type.generics.type_param_defs).clone(), - *new_method_ty.generics.type_param_defs), + Rc::new(vec::append( + impl_poly_type.generics.type_param_defs().to_owned(), + new_method_ty.generics.type_param_defs())), region_param_defs: - impl_poly_type.generics.region_param_defs + impl_poly_type.generics.region_param_defs.clone() }; let new_polytype = ty::ty_param_bounds_and_ty { generics: new_generics, @@ -449,7 +449,7 @@ impl CoherenceChecker { let polytype_b = self.get_self_type_for_implementation( implementation_b); - if self.polytypes_unify(polytype_a, polytype_b) { + if self.polytypes_unify(polytype_a.clone(), polytype_b) { let session = self.crate_context.tcx.sess; session.span_err( self.span_of_impl(implementation_b), @@ -497,13 +497,13 @@ impl CoherenceChecker { pub fn universally_quantify_polytype(&self, polytype: ty_param_bounds_and_ty) -> UniversalQuantificationResult { - let region_parameter_count = polytype.generics.region_param_defs.len(); + let region_parameter_count = polytype.generics.region_param_defs().len(); let region_parameters = self.inference_context.next_region_vars( infer::BoundRegionInCoherence, region_parameter_count); - let bounds_count = polytype.generics.type_param_defs.len(); + let bounds_count = polytype.generics.type_param_defs().len(); let type_parameters = self.inference_context.next_ty_vars(bounds_count); let substitutions = substs { @@ -518,7 +518,7 @@ impl CoherenceChecker { UniversalQuantificationResult { monotype: monotype, type_variables: substitutions.tps, - type_param_defs: polytype.generics.type_param_defs + type_param_defs: polytype.generics.type_param_defs.clone() } } @@ -770,7 +770,7 @@ pub fn make_substs_for_receiver_types(tcx: ty::ctxt, // determine how many type parameters were declared on the impl let num_impl_type_parameters = { let impl_polytype = ty::lookup_item_type(tcx, impl_id); - impl_polytype.generics.type_param_defs.len() + impl_polytype.generics.type_param_defs().len() }; // determine how many type parameters appear on the trait @@ -778,7 +778,7 @@ pub fn make_substs_for_receiver_types(tcx: ty::ctxt, // the current method type has the type parameters from the trait + method let num_method_type_parameters = - num_trait_type_parameters + method.generics.type_param_defs.len(); + num_trait_type_parameters + method.generics.type_param_defs().len(); // the new method type will have the type parameters from the impl + method let combined_tps = vec::from_fn(num_method_type_parameters, |i| { @@ -789,7 +789,7 @@ pub fn make_substs_for_receiver_types(tcx: ty::ctxt, // replace type parameters that belong to method with another // type parameter, this time with the index adjusted let method_index = i - num_trait_type_parameters; - let type_param_def = &method.generics.type_param_defs[method_index]; + let type_param_def = &method.generics.type_param_defs()[method_index]; let new_index = num_impl_type_parameters + method_index; ty::mk_param(tcx, new_index, type_param_def.def_id) } diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index d9a9d9f8fe1..c1a6e53069e 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -44,6 +44,7 @@ use middle::typeck::{CrateCtxt, lookup_def_tcx, no_params, write_ty_to_tcx}; use util::ppaux; use util::ppaux::Repr; +use std::rc::Rc; use std::vec; use syntax::abi::AbiSet; use syntax::ast::{RegionTyParamBound, TraitTyParamBound}; @@ -285,9 +286,9 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt, trait_id: ast::NodeId) { let dummy_defid = ast::DefId {crate: 0, node: 0}; // Represents [A',B',C'] - let num_trait_bounds = trait_ty_generics.type_param_defs.len(); + let num_trait_bounds = trait_ty_generics.type_param_defs().len(); let non_shifted_trait_tps = vec::from_fn(num_trait_bounds, |i| { - ty::mk_param(tcx, i, trait_ty_generics.type_param_defs[i].def_id) + ty::mk_param(tcx, i, trait_ty_generics.type_param_defs()[i].def_id) }); // Represents [D'] @@ -295,18 +296,18 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt, trait_id: ast::NodeId) { dummy_defid); // Represents [E',F',G'] - let num_method_bounds = m.generics.type_param_defs.len(); + let num_method_bounds = m.generics.type_param_defs().len(); let shifted_method_tps = vec::from_fn(num_method_bounds, |i| { ty::mk_param(tcx, i + num_trait_bounds + 1, - m.generics.type_param_defs[i].def_id) + m.generics.type_param_defs()[i].def_id) }); // Convert the regions 'a, 'b, 'c defined on the trait into // bound regions on the fn. Note that because these appear in the // bound for `Self` they must be early bound. - let new_early_region_param_defs = trait_ty_generics.region_param_defs; + let new_early_region_param_defs = trait_ty_generics.region_param_defs.clone(); let rps_from_trait = - trait_ty_generics.region_param_defs.iter(). + trait_ty_generics.region_param_defs().iter(). enumerate(). map(|(index,d)| ty::ReEarlyBound(d.def_id.node, index, d.ident)). collect(); @@ -334,7 +335,7 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt, trait_id: ast::NodeId) { let mut new_type_param_defs = ~[]; let substd_type_param_defs = trait_ty_generics.type_param_defs.subst(tcx, &substs); - new_type_param_defs.push_all(*substd_type_param_defs); + new_type_param_defs.push_all(*substd_type_param_defs.borrow()); // add in the "self" type parameter let self_trait_def = get_trait_def(ccx, local_def(trait_id)); @@ -351,7 +352,7 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt, trait_id: ast::NodeId) { // add in the type parameters from the method let substd_type_param_defs = m.generics.type_param_defs.subst(tcx, &substs); - new_type_param_defs.push_all(*substd_type_param_defs); + new_type_param_defs.push_all(*substd_type_param_defs.borrow()); debug!("static method {} type_param_defs={} ty={}, substs={}", m.def_id.repr(tcx), @@ -363,7 +364,7 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt, trait_id: ast::NodeId) { tcache.get().insert(m.def_id, ty_param_bounds_and_ty { generics: ty::Generics { - type_param_defs: @new_type_param_defs, + type_param_defs: Rc::new(new_type_param_defs), region_param_defs: new_early_region_param_defs }, ty: ty @@ -383,7 +384,7 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt, trait_id: ast::NodeId) { let trait_self_ty = ty::mk_self(this.tcx, local_def(trait_id)); let fty = astconv::ty_of_method(this, *m_id, *m_purity, trait_self_ty, *m_explicit_self, m_decl); - let num_trait_type_params = trait_generics.type_param_defs.len(); + let num_trait_type_params = trait_generics.type_param_defs().len(); ty::Method::new( *m_ident, // FIXME(#5121) -- distinguish early vs late lifetime params @@ -466,7 +467,7 @@ fn convert_methods(ccx: &CrateCtxt, { let tcx = ccx.tcx; for m in ms.iter() { - let num_rcvr_ty_params = rcvr_ty_generics.type_param_defs.len(); + let num_rcvr_ty_params = rcvr_ty_generics.type_param_defs().len(); let m_ty_generics = ty_generics(ccx, &m.generics, num_rcvr_ty_params); let mty = @ty_of_method(ccx, container, @@ -489,10 +490,10 @@ fn convert_methods(ccx: &CrateCtxt, // itself ty_param_bounds_and_ty { generics: ty::Generics { - type_param_defs: @vec::append( - (*rcvr_ty_generics.type_param_defs).clone(), - *m_ty_generics.type_param_defs), - region_param_defs: rcvr_ty_generics.region_param_defs, + type_param_defs: Rc::new(vec::append( + rcvr_ty_generics.type_param_defs().to_owned(), + m_ty_generics.type_param_defs())), + region_param_defs: rcvr_ty_generics.region_param_defs.clone(), }, ty: fty }); @@ -574,7 +575,7 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::Item) { let mut tcache = tcx.tcache.borrow_mut(); tcache.get().insert(local_def(it.id), ty_param_bounds_and_ty { - generics: i_ty_generics, + generics: i_ty_generics.clone(), ty: selfty}); } @@ -637,7 +638,7 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::Item) { { let mut tcache = tcx.tcache.borrow_mut(); - tcache.get().insert(local_def(it.id), tpt); + tcache.get().insert(local_def(it.id), tpt.clone()); } convert_struct(ccx, struct_def, tpt, it.id); @@ -816,7 +817,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item) { let tcache = tcx.tcache.borrow(); match tcache.get().find(&def_id) { - Some(&tpt) => return tpt, + Some(tpt) => return tpt.clone(), _ => {} } } @@ -826,7 +827,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item) let tpt = no_params(typ); let mut tcache = tcx.tcache.borrow_mut(); - tcache.get().insert(local_def(it.id), tpt); + tcache.get().insert(local_def(it.id), tpt.clone()); return tpt; } ast::ItemFn(decl, purity, abi, ref generics, _) => { @@ -838,8 +839,8 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item) decl); let tpt = ty_param_bounds_and_ty { generics: ty::Generics { - type_param_defs: ty_generics.type_param_defs, - region_param_defs: @[], + type_param_defs: ty_generics.type_param_defs.clone(), + region_param_defs: Rc::new(~[]), }, ty: ty::mk_bare_fn(ccx.tcx, tofd) }; @@ -849,14 +850,14 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item) ppaux::ty_to_str(tcx, tpt.ty)); let mut tcache = ccx.tcx.tcache.borrow_mut(); - tcache.get().insert(local_def(it.id), tpt); + tcache.get().insert(local_def(it.id), tpt.clone()); return tpt; } ast::ItemTy(t, ref generics) => { { let mut tcache = tcx.tcache.borrow_mut(); match tcache.get().find(&local_def(it.id)) { - Some(&tpt) => return tpt, + Some(tpt) => return tpt.clone(), None => { } } } @@ -870,7 +871,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item) }; let mut tcache = tcx.tcache.borrow_mut(); - tcache.get().insert(local_def(it.id), tpt); + tcache.get().insert(local_def(it.id), tpt.clone()); return tpt; } ast::ItemEnum(_, ref generics) => { @@ -884,7 +885,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item) }; let mut tcache = tcx.tcache.borrow_mut(); - tcache.get().insert(local_def(it.id), tpt); + tcache.get().insert(local_def(it.id), tpt.clone()); return tpt; } ast::ItemTrait(..) => { @@ -902,7 +903,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item) }; let mut tcache = tcx.tcache.borrow_mut(); - tcache.get().insert(local_def(it.id), tpt); + tcache.get().insert(local_def(it.id), tpt.clone()); return tpt; } ast::ItemImpl(..) | ast::ItemMod(_) | @@ -925,8 +926,8 @@ pub fn ty_of_foreign_item(ccx: &CrateCtxt, ast::ForeignItemStatic(t, _) => { ty::ty_param_bounds_and_ty { generics: ty::Generics { - type_param_defs: @~[], - region_param_defs: @[], + type_param_defs: Rc::new(~[]), + region_param_defs: Rc::new(~[]), }, ty: ast_ty_to_ty(ccx, &ExplicitRscope, t) } @@ -938,11 +939,11 @@ pub fn ty_generics(ccx: &CrateCtxt, generics: &ast::Generics, base_index: uint) -> ty::Generics { return ty::Generics { - region_param_defs: generics.lifetimes.iter().map(|l| { + region_param_defs: Rc::new(generics.lifetimes.iter().map(|l| { ty::RegionParameterDef { ident: l.ident, def_id: local_def(l.id) } - }).collect(), - type_param_defs: @generics.ty_params.mapi_to_vec(|offset, param| { + }).collect()), + type_param_defs: Rc::new(generics.ty_params.mapi_to_vec(|offset, param| { let existing_def_opt = { let ty_param_defs = ccx.tcx.ty_param_defs.borrow(); ty_param_defs.get().find(¶m.id).map(|def| *def) @@ -969,7 +970,7 @@ pub fn ty_generics(ccx: &CrateCtxt, def } } - }) + })) }; fn compute_bounds( @@ -1040,7 +1041,7 @@ pub fn ty_of_foreign_fn_decl(ccx: &CrateCtxt, }; let mut tcache = ccx.tcx.tcache.borrow_mut(); - tcache.get().insert(def_id, tpt); + tcache.get().insert(def_id, tpt.clone()); return tpt; } @@ -1049,11 +1050,11 @@ pub fn mk_item_substs(ccx: &CrateCtxt, self_ty: Option) -> ty::substs { let params: ~[ty::t] = - ty_generics.type_param_defs.iter().enumerate().map( + ty_generics.type_param_defs().iter().enumerate().map( |(i, t)| ty::mk_param(ccx.tcx, i, t.def_id)).collect(); let regions: OptVec = - ty_generics.region_param_defs.iter().enumerate().map( + ty_generics.region_param_defs().iter().enumerate().map( |(i, l)| ty::ReEarlyBound(l.def_id.node, i, l.ident)).collect(); substs {regions: ty::NonerasedRegions(regions), diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index 8837a978f43..a6fc91899f0 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -70,6 +70,7 @@ use util::ppaux; use std::cell::RefCell; use std::hashmap::HashMap; +use std::rc::Rc; use std::result; use extra::list::List; use extra::list; @@ -271,8 +272,8 @@ pub fn lookup_def_ccx(ccx: &CrateCtxt, sp: Span, id: ast::NodeId) pub fn no_params(t: ty::t) -> ty::ty_param_bounds_and_ty { ty::ty_param_bounds_and_ty { - generics: ty::Generics {type_param_defs: @~[], - region_param_defs: @[]}, + generics: ty::Generics {type_param_defs: Rc::new(~[]), + region_param_defs: Rc::new(~[])}, ty: t } } diff --git a/src/librustc/middle/typeck/variance.rs b/src/librustc/middle/typeck/variance.rs index 83be5fd2a30..cd4abd70ecd 100644 --- a/src/librustc/middle/typeck/variance.rs +++ b/src/librustc/middle/typeck/variance.rs @@ -750,7 +750,7 @@ impl<'a> ConstraintContext<'a> { variance: VarianceTermPtr<'a>) { debug!("add_constraints_from_substs(def_id={:?})", def_id); - for (i, p) in generics.type_param_defs.iter().enumerate() { + for (i, p) in generics.type_param_defs().iter().enumerate() { let variance_decl = self.declared_variance(p.def_id, def_id, TypeParam, i); let variance_i = self.xform(variance, variance_decl); @@ -760,7 +760,7 @@ impl<'a> ConstraintContext<'a> { match substs.regions { ty::ErasedRegions => {} ty::NonerasedRegions(ref rps) => { - for (i, p) in generics.region_param_defs.iter().enumerate() { + for (i, p) in generics.region_param_defs().iter().enumerate() { let variance_decl = self.declared_variance(p.def_id, def_id, RegionParam, i); let variance_i = self.xform(variance, variance_decl); diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 8b6cfe88f41..27d15d73825 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -522,11 +522,11 @@ pub fn parameterized(cx: ctxt, } let generics = if is_trait { - ty::lookup_trait_def(cx, did).generics + ty::lookup_trait_def(cx, did).generics.clone() } else { ty::lookup_item_type(cx, did).generics }; - let ty_params = generics.type_param_defs.iter(); + let ty_params = generics.type_param_defs().iter(); let num_defaults = ty_params.zip(tps.iter()).rev().take_while(|&(def, &actual)| { match def.default { Some(default) => default == actual, @@ -789,8 +789,8 @@ impl Repr for ty::ty_param_bounds_and_ty { impl Repr for ty::Generics { fn repr(&self, tcx: ctxt) -> ~str { format!("Generics(type_param_defs: {}, region_param_defs: {})", - self.type_param_defs.repr(tcx), - self.region_param_defs.repr(tcx)) + self.type_param_defs().repr(tcx), + self.region_param_defs().repr(tcx)) } } diff --git a/src/libstd/reflect.rs b/src/libstd/reflect.rs index a7cea1c7e4a..d6b4d3f5656 100644 --- a/src/libstd/reflect.rs +++ b/src/libstd/reflect.rs @@ -250,7 +250,7 @@ impl TyVisitor for MovePtrAdaptor { true } - fn visit_evec_box(&mut self, mtbl: uint, inner: *TyDesc) -> bool { + fn visit_evec_box(&mut self, _mtbl: uint, _inner: *TyDesc) -> bool { true } -- cgit 1.4.1-3-g733a5