diff options
| author | bors <bors@rust-lang.org> | 2014-01-17 07:56:45 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-01-17 07:56:45 -0800 |
| commit | 4098327b1fe1112ddf661b587be9eeec1d80adde (patch) | |
| tree | 3d1a8d2613c1101d46657fd5de25d32403e9626b /src/libstd | |
| parent | 1e1871f35eb83ae6a63952a145e5132deffded2c (diff) | |
| parent | b520c2f28002db0e4120797d823380914871bac4 (diff) | |
| download | rust-4098327b1fe1112ddf661b587be9eeec1d80adde.tar.gz rust-4098327b1fe1112ddf661b587be9eeec1d80adde.zip | |
auto merge of #11585 : nikomatsakis/rust/issue-3511-rvalue-lifetimes, r=pcwalton
Major changes: - Define temporary scopes in a syntax-based way that basically defaults to the innermost statement or conditional block, except for in a `let` initializer, where we default to the innermost block. Rules are documented in the code, but not in the manual (yet). See new test run-pass/cleanup-value-scopes.rs for examples. - Refactors Datum to better define cleanup roles. - Refactor cleanup scopes to not be tied to basic blocks, permitting us to have a very large number of scopes (one per AST node). - Introduce nascent documentation in trans/doc.rs covering datums and cleanup in a more comprehensive way. r? @pcwalton
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/ascii.rs | 13 | ||||
| -rw-r--r-- | src/libstd/comm/mod.rs | 2 | ||||
| -rw-r--r-- | src/libstd/io/mem.rs | 6 | ||||
| -rw-r--r-- | src/libstd/io/process.rs | 14 | ||||
| -rw-r--r-- | src/libstd/option.rs | 19 | ||||
| -rw-r--r-- | src/libstd/path/posix.rs | 13 | ||||
| -rw-r--r-- | src/libstd/path/windows.rs | 14 | ||||
| -rw-r--r-- | src/libstd/rt/crate_map.rs | 18 | ||||
| -rw-r--r-- | src/libstd/unstable/intrinsics.rs | 6 | ||||
| -rw-r--r-- | src/libstd/vec.rs | 29 |
10 files changed, 98 insertions, 36 deletions
diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index c52ff2d088d..546f5550387 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -521,7 +521,8 @@ mod tests { #[test] fn test_ascii_vec() { - assert_eq!((&[40u8, 32u8, 59u8]).to_ascii(), v2ascii!([40, 32, 59])); + let test = &[40u8, 32u8, 59u8]; + assert_eq!(test.to_ascii(), v2ascii!([40, 32, 59])); assert_eq!("( ;".to_ascii(), v2ascii!([40, 32, 59])); // FIXME: #5475 borrowchk error, owned vectors do not live long enough // if chained-from directly @@ -587,14 +588,18 @@ mod tests { assert_eq!("zoä华".to_ascii_opt(), None); - assert_eq!((&[127u8, 128u8, 255u8]).to_ascii_opt(), None); + let test1 = &[127u8, 128u8, 255u8]; + assert_eq!((test1).to_ascii_opt(), None); let v = [40u8, 32u8, 59u8]; - assert_eq!(v.to_ascii_opt(), Some(v2ascii!(&[40, 32, 59]))); + let v2 = v2ascii!(&[40, 32, 59]); + assert_eq!(v.to_ascii_opt(), Some(v2)); let v = [127u8, 128u8, 255u8]; assert_eq!(v.to_ascii_opt(), None); - assert_eq!("( ;".to_ascii_opt(), Some(v2ascii!(&[40, 32, 59]))); + let v = "( ;"; + let v2 = v2ascii!(&[40, 32, 59]); + assert_eq!(v.to_ascii_opt(), Some(v2)); assert_eq!("zoä华".to_ascii_opt(), None); assert_eq!((~[40u8, 32u8, 59u8]).into_ascii_opt(), Some(v2ascii!(~[40, 32, 59]))); diff --git a/src/libstd/comm/mod.rs b/src/libstd/comm/mod.rs index bf9e28f3e97..985a387ee2b 100644 --- a/src/libstd/comm/mod.rs +++ b/src/libstd/comm/mod.rs @@ -1202,7 +1202,7 @@ mod test { }) test!(fn oneshot_single_thread_peek_open() { - let (port, _) = Chan::<int>::new(); + let (port, _chan) = Chan::<int>::new(); assert_eq!(port.try_recv(), Empty); }) diff --git a/src/libstd/io/mem.rs b/src/libstd/io/mem.rs index f036131d211..a6caa1bfc29 100644 --- a/src/libstd/io/mem.rs +++ b/src/libstd/io/mem.rs @@ -406,7 +406,8 @@ mod test { #[test] fn test_read_char() { - let mut r = BufReader::new(bytes!("Việt")); + let b = bytes!("Việt"); + let mut r = BufReader::new(b); assert_eq!(r.read_char(), Some('V')); assert_eq!(r.read_char(), Some('i')); assert_eq!(r.read_char(), Some('ệ')); @@ -416,7 +417,8 @@ mod test { #[test] fn test_read_bad_char() { - let mut r = BufReader::new(bytes!(0x80)); + let b = bytes!(0x80); + let mut r = BufReader::new(b); assert_eq!(r.read_char(), None); } diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index a8b7e8e00ea..4c8a640a849 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -181,7 +181,7 @@ mod tests { let io = ~[]; let args = ProcessConfig { program: "/bin/sh", - args: [~"-c", ~"true"], + args: &[~"-c", ~"true"], env: None, cwd: None, io: io, @@ -198,7 +198,7 @@ mod tests { let io = ~[]; let args = ProcessConfig { program: "if-this-is-a-binary-then-the-world-has-ended", - args: [], + args: &[], env: None, cwd: None, io: io, @@ -215,7 +215,7 @@ mod tests { let io = ~[]; let args = ProcessConfig { program: "/bin/sh", - args: [~"-c", ~"exit 1"], + args: &[~"-c", ~"exit 1"], env: None, cwd: None, io: io, @@ -231,7 +231,7 @@ mod tests { let io = ~[]; let args = ProcessConfig { program: "/bin/sh", - args: [~"-c", ~"kill -1 $$"], + args: &[~"-c", ~"kill -1 $$"], env: None, cwd: None, io: io, @@ -274,7 +274,7 @@ mod tests { let io = ~[Ignored, CreatePipe(false, true)]; let args = ProcessConfig { program: "/bin/sh", - args: [~"-c", ~"echo foobar"], + args: &[~"-c", ~"echo foobar"], env: None, cwd: None, io: io, @@ -289,7 +289,7 @@ mod tests { let cwd = Some("/"); let args = ProcessConfig { program: "/bin/sh", - args: [~"-c", ~"pwd"], + args: &[~"-c", ~"pwd"], env: None, cwd: cwd, io: io, @@ -304,7 +304,7 @@ mod tests { CreatePipe(false, true)]; let args = ProcessConfig { program: "/bin/sh", - args: [~"-c", ~"read line; echo $line"], + args: &[~"-c", ~"read line; echo $line"], env: None, cwd: None, io: io, diff --git a/src/libstd/option.rs b/src/libstd/option.rs index bdec67e5d9f..aab98f19e15 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -48,6 +48,7 @@ use kinds::Send; use str::OwnedStr; use to_str::ToStr; use util; +use vec; /// The option type #[deriving(Clone, DeepClone, Eq, Ord, TotalEq, TotalOrd, ToStr)] @@ -98,6 +99,24 @@ impl<T> Option<T> { match *self { Some(ref mut x) => Some(x), None => None } } + /// Convert from `Option<T>` to `&[T]` (without copying) + #[inline] + pub fn as_slice<'r>(&'r self) -> &'r [T] { + match *self { + Some(ref x) => vec::ref_slice(x), + None => &[] + } + } + + /// Convert from `Option<T>` to `&[T]` (without copying) + #[inline] + pub fn as_mut_slice<'r>(&'r mut self) -> &'r mut [T] { + match *self { + Some(ref mut x) => vec::mut_ref_slice(x), + None => &mut [] + } + } + ///////////////////////////////////////////////////////////////////////// // Getting to contained values ///////////////////////////////////////////////////////////////////////// diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 7b94de6c094..e2ddabc1714 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -237,7 +237,10 @@ impl GenericPath for Path { let mut ita = self.components(); let mut itb = other.components(); if bytes!(".") == self.repr { - return itb.next() != Some(bytes!("..")); + return match itb.next() { + None => true, + Some(b) => b != bytes!("..") + }; } loop { match (ita.next(), itb.next()) { @@ -463,7 +466,10 @@ mod tests { macro_rules! b( ($($arg:expr),+) => ( - bytes!($($arg),+) + { + static the_bytes: &'static [u8] = bytes!($($arg),+); + the_bytes + } ) ) @@ -689,7 +695,8 @@ mod tests { ); (v: $path:expr, $op:ident, $exp:expr) => ( { - let path = Path::new($path); + let arg = $path; + let path = Path::new(arg); assert_eq!(path.$op(), $exp); } ); diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index f8d80599151..a42fdabef88 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -1079,7 +1079,10 @@ mod tests { macro_rules! b( ($($arg:expr),+) => ( - bytes!($($arg),+) + { + static the_bytes: &'static [u8] = bytes!($($arg),+); + the_bytes + } ) ) @@ -1377,20 +1380,23 @@ mod tests { macro_rules! t( (s: $path:expr, $op:ident, $exp:expr) => ( { - let path = Path::new($path); + let path = $path; + let path = Path::new(path); assert_eq!(path.$op(), Some($exp)); } ); (s: $path:expr, $op:ident, $exp:expr, opt) => ( { - let path = Path::new($path); + let path = $path; + let path = Path::new(path); let left = path.$op(); assert_eq!(left, $exp); } ); (v: $path:expr, $op:ident, $exp:expr) => ( { - let path = Path::new($path); + let path = $path; + let path = Path::new(path); assert_eq!(path.$op(), $exp); } ) diff --git a/src/libstd/rt/crate_map.rs b/src/libstd/rt/crate_map.rs index 16c1ad25448..6ea12659e77 100644 --- a/src/libstd/rt/crate_map.rs +++ b/src/libstd/rt/crate_map.rs @@ -130,14 +130,14 @@ mod tests { let child_crate = CrateMap { version: 2, entries: entries, - children: [], + children: &[], event_loop_factory: None, }; let root_crate = CrateMap { version: 2, - entries: [], - children: [&child_crate, &child_crate], + entries: &[], + children: &[&child_crate, &child_crate], event_loop_factory: None, }; @@ -157,29 +157,29 @@ mod tests { let mut level3: u32 = 3; let child_crate2 = CrateMap { version: 2, - entries: [ + entries: &[ ModEntry { name: "c::m1", log_level: &mut level2}, ModEntry { name: "c::m2", log_level: &mut level3}, ], - children: [], + children: &[], event_loop_factory: None, }; let child_crate1 = CrateMap { version: 2, - entries: [ + entries: &[ ModEntry { name: "t::f1", log_level: &mut 1}, ], - children: [&child_crate2], + children: &[&child_crate2], event_loop_factory: None, }; let root_crate = CrateMap { version: 2, - entries: [ + entries: &[ ModEntry { name: "t::f2", log_level: &mut 0}, ], - children: [&child_crate1], + children: &[&child_crate1], event_loop_factory: None, }; diff --git a/src/libstd/unstable/intrinsics.rs b/src/libstd/unstable/intrinsics.rs index 2649ca897e5..198df3090ee 100644 --- a/src/libstd/unstable/intrinsics.rs +++ b/src/libstd/unstable/intrinsics.rs @@ -292,12 +292,6 @@ extern "rust-intrinsic" { /// elements. pub fn size_of<T>() -> uint; - /// Move a value to a memory location containing a value. - /// - /// Drop glue is run on the destination, which must contain a - /// valid Rust value. - pub fn move_val<T>(dst: &mut T, src: T); - /// Move a value to an uninitialized memory location. /// /// Drop glue is not run on the destination. diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 20684bf4c49..a7310bc75f1 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -209,6 +209,25 @@ pub fn build<A>(size: Option<uint>, builder: |push: |v: A||) -> ~[A] { vec } +/** + * Converts a pointer to A into a slice of length 1 (without copying). + */ +pub fn ref_slice<'a, A>(s: &'a A) -> &'a [A] { + unsafe { + cast::transmute(Slice { data: s, len: 1 }) + } +} + +/** + * Converts a pointer to A into a slice of length 1 (without copying). + */ +pub fn mut_ref_slice<'a, A>(s: &'a mut A) -> &'a mut [A] { + unsafe { + let ptr: *A = cast::transmute(s); + cast::transmute(Slice { data: ptr, len: 1 }) + } +} + /// An iterator over the slices of a vector separated by elements that /// match a predicate function. pub struct SplitIterator<'a, T> { @@ -2048,6 +2067,9 @@ pub trait MutableVector<'a, T> { /// Returns an iterator that allows modifying each value fn mut_iter(self) -> VecMutIterator<'a, T>; + /// Returns a mutable pointer to the last item in the vector. + fn mut_last(self) -> &'a mut T; + /// Returns a reversed iterator that allows modifying each value fn mut_rev_iter(self) -> MutRevIterator<'a, T>; @@ -2311,6 +2333,13 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] { } #[inline] + fn mut_last(self) -> &'a mut T { + let len = self.len(); + if len == 0 { fail!("mut_last: empty vector") } + &mut self[len - 1] + } + + #[inline] fn mut_rev_iter(self) -> MutRevIterator<'a, T> { self.mut_iter().invert() } |
