From 382f1bceb4e2a0496171f52d114a98ff8a86f9b7 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Wed, 1 Oct 2014 00:08:07 +0300 Subject: core: remove raw::GcBox. --- src/libcore/raw.rs | 9 --------- 1 file changed, 9 deletions(-) (limited to 'src/libcore') diff --git a/src/libcore/raw.rs b/src/libcore/raw.rs index 86b96ff15f1..a62e2ecdca0 100644 --- a/src/libcore/raw.rs +++ b/src/libcore/raw.rs @@ -20,15 +20,6 @@ use mem; -/// The representation of `std::gc::Gc`. -pub struct GcBox { - pub ref_count: uint, - pub drop_glue: fn(ptr: *mut u8), - pub prev: *mut GcBox, - pub next: *mut GcBox, - pub data: T, -} - /// The representation of a Rust slice pub struct Slice { pub data: *const T, -- cgit 1.4.1-3-g733a5 From db55e70c977f9e2a70e62ea819755ef02009db8e Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Thu, 2 Oct 2014 00:19:55 +0300 Subject: syntax: mark the managed_boxes feature as Removed. --- src/libcollections/lib.rs | 2 +- src/libcore/lib.rs | 2 +- src/libdebug/lib.rs | 2 +- src/libfourcc/lib.rs | 2 +- src/libhexfloat/lib.rs | 2 +- src/libregex_macros/lib.rs | 2 +- src/librustdoc/lib.rs | 2 +- src/librustrt/lib.rs | 2 +- src/libserialize/lib.rs | 2 +- src/libstd/lib.rs | 2 +- src/libsyntax/feature_gate.rs | 2 +- src/test/auxiliary/issue_16723_multiple_items_syntax_ext.rs | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/libcore') diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index 4d0aaf83907..b74324c85c0 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -20,7 +20,7 @@ html_playground_url = "http://play.rust-lang.org/")] #![allow(unknown_features)] -#![feature(macro_rules, managed_boxes, default_type_params, phase, globs)] +#![feature(macro_rules, default_type_params, phase, globs)] #![feature(unsafe_destructor, import_shadowing, slicing_syntax)] #![no_std] diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 4890dc2bb73..584d09c75c8 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -58,7 +58,7 @@ #![no_std] #![allow(unknown_features)] -#![feature(globs, intrinsics, lang_items, macro_rules, managed_boxes, phase)] +#![feature(globs, intrinsics, lang_items, macro_rules, phase)] #![feature(simd, unsafe_destructor, slicing_syntax)] #![deny(missing_doc)] diff --git a/src/libdebug/lib.rs b/src/libdebug/lib.rs index 6341a380563..21abfae8be9 100644 --- a/src/libdebug/lib.rs +++ b/src/libdebug/lib.rs @@ -25,7 +25,7 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/master/")] #![experimental] -#![feature(managed_boxes, macro_rules)] +#![feature(macro_rules)] #![allow(experimental)] pub mod fmt; diff --git a/src/libfourcc/lib.rs b/src/libfourcc/lib.rs index 3aa40058792..388373807d8 100644 --- a/src/libfourcc/lib.rs +++ b/src/libfourcc/lib.rs @@ -50,7 +50,7 @@ fn main() { html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/master/")] -#![feature(plugin_registrar, managed_boxes)] +#![feature(plugin_registrar)] extern crate syntax; extern crate rustc; diff --git a/src/libhexfloat/lib.rs b/src/libhexfloat/lib.rs index ae7a3e66dfd..2fcc3b9691a 100644 --- a/src/libhexfloat/lib.rs +++ b/src/libhexfloat/lib.rs @@ -46,7 +46,7 @@ fn main() { #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/master/")] -#![feature(plugin_registrar, managed_boxes)] +#![feature(plugin_registrar)] extern crate syntax; extern crate rustc; diff --git a/src/libregex_macros/lib.rs b/src/libregex_macros/lib.rs index 3535038b6a5..67018769fb3 100644 --- a/src/libregex_macros/lib.rs +++ b/src/libregex_macros/lib.rs @@ -19,7 +19,7 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/master/")] -#![feature(plugin_registrar, managed_boxes, quote)] +#![feature(plugin_registrar, quote)] extern crate regex; extern crate syntax; diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index b46d8727b69..77d63224fcd 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -16,7 +16,7 @@ #![crate_type = "rlib"] #![allow(unknown_features)] -#![feature(globs, struct_variant, managed_boxes, macro_rules, phase, slicing_syntax)] +#![feature(globs, struct_variant, macro_rules, phase, slicing_syntax)] extern crate arena; extern crate debug; diff --git a/src/librustrt/lib.rs b/src/librustrt/lib.rs index ad1eac41e4d..d3ea07291a4 100644 --- a/src/librustrt/lib.rs +++ b/src/librustrt/lib.rs @@ -17,7 +17,7 @@ html_root_url = "http://doc.rust-lang.org/master/")] #![allow(unknown_features)] -#![feature(macro_rules, phase, globs, thread_local, managed_boxes, asm)] +#![feature(macro_rules, phase, globs, thread_local, asm)] #![feature(linkage, lang_items, unsafe_destructor, default_type_params)] #![feature(import_shadowing, slicing_syntax)] #![no_std] diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs index 8c2f3235322..6de8ca19844 100644 --- a/src/libserialize/lib.rs +++ b/src/libserialize/lib.rs @@ -24,7 +24,7 @@ Core encoding and decoding interfaces. html_root_url = "http://doc.rust-lang.org/master/", html_playground_url = "http://play.rust-lang.org/")] #![allow(unknown_features)] -#![feature(macro_rules, managed_boxes, default_type_params, phase, slicing_syntax)] +#![feature(macro_rules, default_type_params, phase, slicing_syntax)] // test harness access #[cfg(test)] diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index f6c37b6cfc3..19b4d430562 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -106,7 +106,7 @@ html_playground_url = "http://play.rust-lang.org/")] #![allow(unknown_features)] -#![feature(macro_rules, globs, managed_boxes, linkage)] +#![feature(macro_rules, globs, linkage)] #![feature(default_type_params, phase, lang_items, unsafe_destructor)] #![feature(import_shadowing, slicing_syntax)] diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 8565bebe269..7dcc039a83f 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -40,7 +40,7 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[ ("struct_variant", Active), ("once_fns", Active), ("asm", Active), - ("managed_boxes", Active), + ("managed_boxes", Removed), ("non_ascii_idents", Active), ("thread_local", Active), ("link_args", Active), diff --git a/src/test/auxiliary/issue_16723_multiple_items_syntax_ext.rs b/src/test/auxiliary/issue_16723_multiple_items_syntax_ext.rs index ee5bc55b3fd..bb57b4a98bb 100644 --- a/src/test/auxiliary/issue_16723_multiple_items_syntax_ext.rs +++ b/src/test/auxiliary/issue_16723_multiple_items_syntax_ext.rs @@ -11,7 +11,7 @@ // ignore-stage1 // force-host -#![feature(plugin_registrar, managed_boxes, quote)] +#![feature(plugin_registrar, quote)] #![crate_type = "dylib"] extern crate syntax; -- cgit 1.4.1-3-g733a5 From 4184396f28d5612520f7b30718df9fff6918d239 Mon Sep 17 00:00:00 2001 From: Dan Schatzberg Date: Thu, 4 Sep 2014 15:25:23 -0400 Subject: Add lifetime bounds on Items and MutItems. This also requires a fix for Vec's MoveItems. This resolves issue #16941 --- src/libcollections/vec.rs | 56 +++++++++++++++++++++++++++++++++++------------ src/libcore/slice.rs | 4 ++-- 2 files changed, 44 insertions(+), 16 deletions(-) (limited to 'src/libcore') diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 9dc122cfc7d..6fdf2fce0a2 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -845,11 +845,12 @@ impl Vec { #[inline] pub fn into_iter(self) -> MoveItems { unsafe { - let iter = mem::transmute(self.as_slice().iter()); let ptr = self.ptr; let cap = self.cap; + let begin = self.ptr as *const T; + let end = (self.ptr as uint + self.len()) as *const T; mem::forget(self); - MoveItems { allocation: ptr, cap: cap, iter: iter } + MoveItems { allocation: ptr, cap: cap, ptr: begin, end: end } } } @@ -1773,7 +1774,8 @@ impl MutableSeq for Vec { pub struct MoveItems { allocation: *mut T, // the block of memory allocated for the vector cap: uint, // the capacity of the vector - iter: Items<'static, T> + ptr: *const T, + end: *const T } impl MoveItems { @@ -1793,17 +1795,33 @@ impl Iterator for MoveItems { #[inline] fn next<'a>(&'a mut self) -> Option { unsafe { - // Unsafely transmute from Items<'static, T> to Items<'a, - // T> because otherwise the type checker requires that T - // be bounded by 'static. - let iter: &mut Items<'a, T> = mem::transmute(&mut self.iter); - iter.next().map(|x| ptr::read(x)) + if self.ptr == self.end { + None + } else { + if mem::size_of::() == 0 { + // purposefully don't use 'ptr.offset' because for + // vectors with 0-size elements this would return the + // same pointer. + self.ptr = mem::transmute(self.ptr as uint + 1); + + // Use a non-null pointer value + Some(ptr::read(mem::transmute(1u))) + } else { + let old = self.ptr; + self.ptr = self.ptr.offset(1); + + Some(ptr::read(old)) + } + } } } #[inline] fn size_hint(&self) -> (uint, Option) { - self.iter.size_hint() + let diff = (self.end as uint) - (self.ptr as uint); + let size = mem::size_of::(); + let exact = diff / (if size == 0 {1} else {size}); + (exact, Some(exact)) } } @@ -1811,11 +1829,21 @@ impl DoubleEndedIterator for MoveItems { #[inline] fn next_back<'a>(&'a mut self) -> Option { unsafe { - // Unsafely transmute from Items<'static, T> to Items<'a, - // T> because otherwise the type checker requires that T - // be bounded by 'static. - let iter: &mut Items<'a, T> = mem::transmute(&mut self.iter); - iter.next_back().map(|x| ptr::read(x)) + if self.end == self.ptr { + None + } else { + if mem::size_of::() == 0 { + // See above for why 'ptr.offset' isn't used + self.end = mem::transmute(self.end as uint - 1); + + // Use a non-null pointer value + Some(ptr::read(mem::transmute(1u))) + } else { + self.end = self.end.offset(-1); + + Some(ptr::read(mem::transmute(self.end))) + } + } } } } diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index a8becb315b2..6a8bea001bf 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -1163,7 +1163,7 @@ macro_rules! iterator { /// Immutable slice iterator #[experimental = "needs review"] -pub struct Items<'a, T> { +pub struct Items<'a, T: 'a> { ptr: *const T, end: *const T, marker: marker::ContravariantLifetime<'a> @@ -1206,7 +1206,7 @@ impl<'a, T> RandomAccessIterator<&'a T> for Items<'a, T> { /// Mutable slice iterator. #[experimental = "needs review"] -pub struct MutItems<'a, T> { +pub struct MutItems<'a, T: 'a> { ptr: *mut T, end: *mut T, marker: marker::ContravariantLifetime<'a>, -- cgit 1.4.1-3-g733a5