From c836ff46215b743c0f681d3e4d799cde1832cde3 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 13 Apr 2014 14:39:04 -0700 Subject: std: Impl Deref/DerefMut for a borrowed task --- src/libstd/io/stdio.rs | 6 ++---- src/libstd/rt/local_heap.rs | 3 +-- src/libstd/rt/local_ptr.rs | 18 ++++++++++-------- src/libstd/rt/task.rs | 10 ++++------ src/libstd/task.rs | 9 +++------ 5 files changed, 20 insertions(+), 26 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 5f47e227901..34a57884398 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -160,7 +160,7 @@ fn reset_helper(w: ~Writer:Send, { let mut t = Local::borrow(None::); // Be sure to flush any pending output from the writer - match f(t.get(), w) { + match f(&mut *t, w) { Some(mut w) => { drop(t); // FIXME: is failing right here? @@ -230,9 +230,7 @@ fn with_task_stdout(f: |&mut Writer| -> IoResult<()> ) { // To protect against this, we do a little dance in which we // temporarily take the task, swap the handles, put the task in TLS, // and only then drop the previous handle. - let mut t = Local::borrow(None::); - let prev = replace(&mut t.get().stdout, my_stdout); - drop(t); + let prev = replace(&mut Local::borrow(None::).stdout, my_stdout); drop(prev); ret } diff --git a/src/libstd/rt/local_heap.rs b/src/libstd/rt/local_heap.rs index b9d0d829374..caf0d9028c5 100644 --- a/src/libstd/rt/local_heap.rs +++ b/src/libstd/rt/local_heap.rs @@ -319,8 +319,7 @@ pub unsafe fn local_free(ptr: *u8) { } pub fn live_allocs() -> *mut Box { - let mut task = Local::borrow(None::); - task.get().heap.live_allocs + Local::borrow(None::).heap.live_allocs } #[cfg(test)] diff --git a/src/libstd/rt/local_ptr.rs b/src/libstd/rt/local_ptr.rs index e3f64f40c0d..6b61af1d9a2 100644 --- a/src/libstd/rt/local_ptr.rs +++ b/src/libstd/rt/local_ptr.rs @@ -18,7 +18,7 @@ #![allow(dead_code)] use cast; -use ops::Drop; +use ops::{Drop, Deref, DerefMut}; use ptr::RawPtr; #[cfg(windows)] // mingw-w32 doesn't like thread_local things @@ -48,13 +48,15 @@ impl Drop for Borrowed { } } -impl Borrowed { - pub fn get<'a>(&'a mut self) -> &'a mut T { - unsafe { - let val_ptr: &mut ~T = cast::transmute(&mut self.val); - let val_ptr: &'a mut T = *val_ptr; - val_ptr - } +impl Deref for Borrowed { + fn deref<'a>(&'a self) -> &'a T { + unsafe { &*(self.val as *T) } + } +} + +impl DerefMut for Borrowed { + fn deref_mut<'a>(&'a mut self) -> &'a mut T { + unsafe { &mut *(self.val as *mut T) } } } diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index a112ed77f09..a3664b45a41 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -127,8 +127,8 @@ impl Task { #[allow(unused_must_use)] fn close_outputs() { let mut task = Local::borrow(None::); - let stderr = task.get().stderr.take(); - let stdout = task.get().stdout.take(); + let stderr = task.stderr.take(); + let stdout = task.stdout.take(); drop(task); match stdout { Some(mut w) => { w.flush(); }, None => {} } match stderr { Some(mut w) => { w.flush(); }, None => {} } @@ -159,8 +159,7 @@ impl Task { // be intertwined, and miraculously work for now... let mut task = Local::borrow(None::); let storage_map = { - let task = task.get(); - let LocalStorage(ref mut optmap) = task.storage; + let &LocalStorage(ref mut optmap) = &mut task.storage; optmap.take() }; drop(task); @@ -332,8 +331,7 @@ impl BlockedTask { } /// Converts one blocked task handle to a list of many handles to the same. - pub fn make_selectable(self, num_handles: uint) -> Take - { + pub fn make_selectable(self, num_handles: uint) -> Take { let arc = match self { Owned(task) => { let flag = unsafe { AtomicUint::new(cast::transmute(task)) }; diff --git a/src/libstd/task.rs b/src/libstd/task.rs index ed10f6d15cd..df627809ea0 100644 --- a/src/libstd/task.rs +++ b/src/libstd/task.rs @@ -257,8 +257,8 @@ pub fn try(f: proc():Send -> T) -> Result { pub fn with_task_name(blk: |Option<&str>| -> U) -> U { use rt::task::Task; - let mut task = Local::borrow(None::); - match task.get().name { + let task = Local::borrow(None::); + match task.name { Some(ref name) => blk(Some(name.as_slice())), None => blk(None) } @@ -276,11 +276,8 @@ pub fn deschedule() { pub fn failing() -> bool { //! True if the running task has failed - use rt::task::Task; - - let mut local = Local::borrow(None::); - local.get().unwinder.unwinding() + Local::borrow(None::).unwinder.unwinding() } // The following 8 tests test the following 2^3 combinations: -- cgit 1.4.1-3-g733a5 From 54ec04f1c12c7fb4dbe5f01fdeb73d1079fef53d Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Mon, 14 Apr 2014 20:04:14 +1000 Subject: Use the unsigned integer types for bitwise intrinsics. Exposing ctpop, ctlz, cttz and bswap as taking signed i8/i16/... is just exposing the internal LLVM names pointlessly (LLVM doesn't have "signed integers" or "unsigned integers", it just has sized integer types with (un)signed *operations*). These operations are semantically working with raw bytes, which the unsigned types model better. --- src/libnative/io/net.rs | 4 +- src/librustc/middle/typeck/check/mod.rs | 30 ++--- src/librustc/util/sha2.rs | 10 +- src/librustuv/net.rs | 4 +- src/libserialize/ebml.rs | 4 +- src/libstd/intrinsics.rs | 60 +++++++--- src/libstd/io/extensions.rs | 14 +-- src/libstd/mem.rs | 96 ++++++++-------- src/libstd/num/i16.rs | 6 +- src/libstd/num/i32.rs | 6 +- src/libstd/num/i64.rs | 6 +- src/libstd/num/i8.rs | 6 +- src/libuuid/lib.rs | 12 +- src/test/bench/sudoku.rs | 6 +- src/test/run-pass/intrinsics-integer.rs | 193 ++++++++++++++++---------------- 15 files changed, 238 insertions(+), 219 deletions(-) (limited to 'src/libstd') diff --git a/src/libnative/io/net.rs b/src/libnative/io/net.rs index cef6a247a00..2e64b82a84a 100644 --- a/src/libnative/io/net.rs +++ b/src/libnative/io/net.rs @@ -26,10 +26,10 @@ use super::{IoResult, retry, keep_going}; #[cfg(unix)] pub type sock_t = super::file::fd_t; pub fn htons(u: u16) -> u16 { - mem::to_be16(u as i16) as u16 + mem::to_be16(u) } pub fn ntohs(u: u16) -> u16 { - mem::from_be16(u as i16) as u16 + mem::from_be16(u) } enum InAddr { diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index fee510b82b7..cff8c149bb6 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -4143,21 +4143,21 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) { "nearbyintf64" => (0, vec!( ty::mk_f64() ), ty::mk_f64()), "roundf32" => (0, vec!( ty::mk_f32() ), ty::mk_f32()), "roundf64" => (0, vec!( ty::mk_f64() ), ty::mk_f64()), - "ctpop8" => (0, vec!( ty::mk_i8() ), ty::mk_i8()), - "ctpop16" => (0, vec!( ty::mk_i16() ), ty::mk_i16()), - "ctpop32" => (0, vec!( ty::mk_i32() ), ty::mk_i32()), - "ctpop64" => (0, vec!( ty::mk_i64() ), ty::mk_i64()), - "ctlz8" => (0, vec!( ty::mk_i8() ), ty::mk_i8()), - "ctlz16" => (0, vec!( ty::mk_i16() ), ty::mk_i16()), - "ctlz32" => (0, vec!( ty::mk_i32() ), ty::mk_i32()), - "ctlz64" => (0, vec!( ty::mk_i64() ), ty::mk_i64()), - "cttz8" => (0, vec!( ty::mk_i8() ), ty::mk_i8()), - "cttz16" => (0, vec!( ty::mk_i16() ), ty::mk_i16()), - "cttz32" => (0, vec!( ty::mk_i32() ), ty::mk_i32()), - "cttz64" => (0, vec!( ty::mk_i64() ), ty::mk_i64()), - "bswap16" => (0, vec!( ty::mk_i16() ), ty::mk_i16()), - "bswap32" => (0, vec!( ty::mk_i32() ), ty::mk_i32()), - "bswap64" => (0, vec!( ty::mk_i64() ), ty::mk_i64()), + "ctpop8" => (0, vec!( ty::mk_u8() ), ty::mk_u8()), + "ctpop16" => (0, vec!( ty::mk_u16() ), ty::mk_u16()), + "ctpop32" => (0, vec!( ty::mk_u32() ), ty::mk_u32()), + "ctpop64" => (0, vec!( ty::mk_u64() ), ty::mk_u64()), + "ctlz8" => (0, vec!( ty::mk_u8() ), ty::mk_u8()), + "ctlz16" => (0, vec!( ty::mk_u16() ), ty::mk_u16()), + "ctlz32" => (0, vec!( ty::mk_u32() ), ty::mk_u32()), + "ctlz64" => (0, vec!( ty::mk_u64() ), ty::mk_u64()), + "cttz8" => (0, vec!( ty::mk_u8() ), ty::mk_u8()), + "cttz16" => (0, vec!( ty::mk_u16() ), ty::mk_u16()), + "cttz32" => (0, vec!( ty::mk_u32() ), ty::mk_u32()), + "cttz64" => (0, vec!( ty::mk_u64() ), ty::mk_u64()), + "bswap16" => (0, vec!( ty::mk_u16() ), ty::mk_u16()), + "bswap32" => (0, vec!( ty::mk_u32() ), ty::mk_u32()), + "bswap64" => (0, vec!( ty::mk_u64() ), ty::mk_u64()), "volatile_load" => (1, vec!( ty::mk_imm_ptr(tcx, param(ccx, 0)) ), param(ccx, 0)), diff --git a/src/librustc/util/sha2.rs b/src/librustc/util/sha2.rs index 17ea4d6b0b4..4571e6328cf 100644 --- a/src/librustc/util/sha2.rs +++ b/src/librustc/util/sha2.rs @@ -20,23 +20,21 @@ use serialize::hex::ToHex; /// Write a u32 into a vector, which must be 4 bytes long. The value is written in big-endian /// format. fn write_u32_be(dst: &mut[u8], input: u32) { - use std::cast::transmute; use std::mem::to_be32; assert!(dst.len() == 4); unsafe { - let x: *mut i32 = transmute(dst.unsafe_mut_ref(0)); - *x = to_be32(input as i32); + let x = dst.unsafe_mut_ref(0) as *mut _ as *mut u32; + *x = to_be32(input); } } /// Read a vector of bytes into a vector of u32s. The values are read in big-endian format. fn read_u32v_be(dst: &mut[u32], input: &[u8]) { - use std::cast::transmute; use std::mem::to_be32; assert!(dst.len() * 4 == input.len()); unsafe { - let mut x: *mut i32 = transmute(dst.unsafe_mut_ref(0)); - let mut y: *i32 = transmute(input.unsafe_ref(0)); + let mut x = dst.unsafe_mut_ref(0) as *mut _ as *mut u32; + let mut y = input.unsafe_ref(0) as *_ as *u32; for _ in range(0, dst.len()) { *x = to_be32(*y); x = x.offset(1); diff --git a/src/librustuv/net.rs b/src/librustuv/net.rs index b893f5f693f..280cd4bd592 100644 --- a/src/librustuv/net.rs +++ b/src/librustuv/net.rs @@ -32,8 +32,8 @@ use uvll; /// Generic functions related to dealing with sockaddr things //////////////////////////////////////////////////////////////////////////////// -pub fn htons(u: u16) -> u16 { mem::to_be16(u as i16) as u16 } -pub fn ntohs(u: u16) -> u16 { mem::from_be16(u as i16) as u16 } +pub fn htons(u: u16) -> u16 { mem::to_be16(u) } +pub fn ntohs(u: u16) -> u16 { mem::from_be16(u) } pub fn sockaddr_to_addr(storage: &libc::sockaddr_storage, len: uint) -> ip::SocketAddr { diff --git a/src/libserialize/ebml.rs b/src/libserialize/ebml.rs index 9b2df307b99..0efa93011fc 100644 --- a/src/libserialize/ebml.rs +++ b/src/libserialize/ebml.rs @@ -179,8 +179,8 @@ pub mod reader { ]; unsafe { - let ptr = data.as_ptr().offset(start as int) as *i32; - let val = from_be32(*ptr) as u32; + let ptr = data.as_ptr().offset(start as int) as *u32; + let val = from_be32(*ptr); let i = (val >> 28u) as uint; let (shift, mask) = SHIFT_MASK_TABLE[i]; diff --git a/src/libstd/intrinsics.rs b/src/libstd/intrinsics.rs index 896ebcd6fb5..175c7fe57b3 100644 --- a/src/libstd/intrinsics.rs +++ b/src/libstd/intrinsics.rs @@ -394,26 +394,50 @@ extern "rust-intrinsic" { pub fn roundf32(x: f32) -> f32; pub fn roundf64(x: f64) -> f64; +} +#[cfg(not(stage0))] +extern "rust-intrinsic" { + pub fn ctpop8(x: u8) -> u8; + pub fn ctpop16(x: u16) -> u16; + pub fn ctpop32(x: u32) -> u32; + pub fn ctpop64(x: u64) -> u64; + + pub fn ctlz8(x: u8) -> u8; + pub fn ctlz16(x: u16) -> u16; + pub fn ctlz32(x: u32) -> u32; + pub fn ctlz64(x: u64) -> u64; + + pub fn cttz8(x: u8) -> u8; + pub fn cttz16(x: u16) -> u16; + pub fn cttz32(x: u32) -> u32; + pub fn cttz64(x: u64) -> u64; + + pub fn bswap16(x: u16) -> u16; + pub fn bswap32(x: u32) -> u32; + pub fn bswap64(x: u64) -> u64; +} - pub fn ctpop8(x: i8) -> i8; - pub fn ctpop16(x: i16) -> i16; - pub fn ctpop32(x: i32) -> i32; - pub fn ctpop64(x: i64) -> i64; - - pub fn ctlz8(x: i8) -> i8; - pub fn ctlz16(x: i16) -> i16; - pub fn ctlz32(x: i32) -> i32; - pub fn ctlz64(x: i64) -> i64; - - pub fn cttz8(x: i8) -> i8; - pub fn cttz16(x: i16) -> i16; - pub fn cttz32(x: i32) -> i32; - pub fn cttz64(x: i64) -> i64; - - pub fn bswap16(x: i16) -> i16; - pub fn bswap32(x: i32) -> i32; - pub fn bswap64(x: i64) -> i64; +// NOTE: remove this after a snap, and merge the extern block above +macro_rules! stage0_hack { + ($( $u_ty:ty, $i_ty:ty => $($name:ident),*);*) => { + $( + $( + #[cfg(stage0)] + pub unsafe fn $name(x: $u_ty) -> $u_ty { + extern "rust-intrinsic" { fn $name(x: $i_ty) -> $i_ty; } + $name(x as $i_ty) as $u_ty + } + )*)* + } +} +stage0_hack! { + u8, i8 => ctpop8, ctlz8, cttz8; + u16, i16 => ctpop16, ctlz16, cttz16, bswap16; + u32, i32 => ctpop32, ctlz32, cttz32, bswap32; + u64, i64 => ctpop64, ctlz64, cttz64, bswap64 +} +extern "rust-intrinsic" { pub fn i8_add_with_overflow(x: i8, y: i8) -> (i8, bool); pub fn i16_add_with_overflow(x: i16, y: i16) -> (i16, bool); pub fn i32_add_with_overflow(x: i32, y: i32) -> (i32, bool); diff --git a/src/libstd/io/extensions.rs b/src/libstd/io/extensions.rs index b2202a13057..d8022b1e26c 100644 --- a/src/libstd/io/extensions.rs +++ b/src/libstd/io/extensions.rs @@ -83,9 +83,9 @@ pub fn u64_to_le_bytes(n: u64, size: uint, f: |v: &[u8]| -> T) -> T { assert!(size <= 8u); match size { 1u => f(&[n as u8]), - 2u => f(unsafe { transmute::(to_le16(n as i16)) }), - 4u => f(unsafe { transmute::(to_le32(n as i32)) }), - 8u => f(unsafe { transmute::(to_le64(n as i64)) }), + 2u => f(unsafe { transmute::<_, [u8, ..2]>(to_le16(n as u16)) }), + 4u => f(unsafe { transmute::<_, [u8, ..4]>(to_le32(n as u32)) }), + 8u => f(unsafe { transmute::<_, [u8, ..8]>(to_le64(n)) }), _ => { let mut bytes = vec!(); @@ -123,9 +123,9 @@ pub fn u64_to_be_bytes(n: u64, size: uint, f: |v: &[u8]| -> T) -> T { assert!(size <= 8u); match size { 1u => f(&[n as u8]), - 2u => f(unsafe { transmute::(to_be16(n as i16)) }), - 4u => f(unsafe { transmute::(to_be32(n as i32)) }), - 8u => f(unsafe { transmute::(to_be64(n as i64)) }), + 2u => f(unsafe { transmute::<_, [u8, ..2]>(to_be16(n as u16)) }), + 4u => f(unsafe { transmute::<_, [u8, ..4]>(to_be32(n as u32)) }), + 8u => f(unsafe { transmute::<_, [u8, ..8]>(to_be64(n)) }), _ => { let mut bytes = vec!(); let mut i = size; @@ -166,7 +166,7 @@ pub fn u64_from_be_bytes(data: &[u8], start: uint, size: uint) -> u64 { let ptr = data.as_ptr().offset(start as int); let out = buf.as_mut_ptr(); copy_nonoverlapping_memory(out.offset((8 - size) as int), ptr, size); - from_be64(*(out as *i64)) as u64 + from_be64(*(out as *u64)) } } diff --git a/src/libstd/mem.rs b/src/libstd/mem.rs index deefb3fe2ed..282cfe51782 100644 --- a/src/libstd/mem.rs +++ b/src/libstd/mem.rs @@ -99,128 +99,128 @@ pub unsafe fn move_val_init(dst: &mut T, src: T) { intrinsics::move_val_init(dst, src) } -/// Convert an i16 to little endian from the target's endianness. +/// Convert an u16 to little endian from the target's endianness. /// /// On little endian, this is a no-op. On big endian, the bytes are swapped. -#[cfg(target_endian = "little")] #[inline] pub fn to_le16(x: i16) -> i16 { x } +#[cfg(target_endian = "little")] #[inline] pub fn to_le16(x: u16) -> u16 { x } -/// Convert an i16 to little endian from the target's endianness. +/// Convert an u16 to little endian from the target's endianness. /// /// On little endian, this is a no-op. On big endian, the bytes are swapped. -#[cfg(target_endian = "big")] #[inline] pub fn to_le16(x: i16) -> i16 { unsafe { bswap16(x) } } +#[cfg(target_endian = "big")] #[inline] pub fn to_le16(x: u16) -> u16 { unsafe { bswap16(x) } } -/// Convert an i32 to little endian from the target's endianness. +/// Convert an u32 to little endian from the target's endianness. /// /// On little endian, this is a no-op. On big endian, the bytes are swapped. -#[cfg(target_endian = "little")] #[inline] pub fn to_le32(x: i32) -> i32 { x } +#[cfg(target_endian = "little")] #[inline] pub fn to_le32(x: u32) -> u32 { x } -/// Convert an i32 to little endian from the target's endianness. +/// Convert an u32 to little endian from the target's endianness. /// /// On little endian, this is a no-op. On big endian, the bytes are swapped. -#[cfg(target_endian = "big")] #[inline] pub fn to_le32(x: i32) -> i32 { unsafe { bswap32(x) } } +#[cfg(target_endian = "big")] #[inline] pub fn to_le32(x: u32) -> u32 { unsafe { bswap32(x) } } -/// Convert an i64 to little endian from the target's endianness. +/// Convert an u64 to little endian from the target's endianness. /// /// On little endian, this is a no-op. On big endian, the bytes are swapped. -#[cfg(target_endian = "little")] #[inline] pub fn to_le64(x: i64) -> i64 { x } +#[cfg(target_endian = "little")] #[inline] pub fn to_le64(x: u64) -> u64 { x } -/// Convert an i64 to little endian from the target's endianness. +/// Convert an u64 to little endian from the target's endianness. /// /// On little endian, this is a no-op. On big endian, the bytes are swapped. -#[cfg(target_endian = "big")] #[inline] pub fn to_le64(x: i64) -> i64 { unsafe { bswap64(x) } } +#[cfg(target_endian = "big")] #[inline] pub fn to_le64(x: u64) -> u64 { unsafe { bswap64(x) } } -/// Convert an i16 to big endian from the target's endianness. +/// Convert an u16 to big endian from the target's endianness. /// /// On big endian, this is a no-op. On little endian, the bytes are swapped. -#[cfg(target_endian = "little")] #[inline] pub fn to_be16(x: i16) -> i16 { unsafe { bswap16(x) } } +#[cfg(target_endian = "little")] #[inline] pub fn to_be16(x: u16) -> u16 { unsafe { bswap16(x) } } -/// Convert an i16 to big endian from the target's endianness. +/// Convert an u16 to big endian from the target's endianness. /// /// On big endian, this is a no-op. On little endian, the bytes are swapped. -#[cfg(target_endian = "big")] #[inline] pub fn to_be16(x: i16) -> i16 { x } +#[cfg(target_endian = "big")] #[inline] pub fn to_be16(x: u16) -> u16 { x } -/// Convert an i32 to big endian from the target's endianness. +/// Convert an u32 to big endian from the target's endianness. /// /// On big endian, this is a no-op. On little endian, the bytes are swapped. -#[cfg(target_endian = "little")] #[inline] pub fn to_be32(x: i32) -> i32 { unsafe { bswap32(x) } } +#[cfg(target_endian = "little")] #[inline] pub fn to_be32(x: u32) -> u32 { unsafe { bswap32(x) } } -/// Convert an i32 to big endian from the target's endianness. +/// Convert an u32 to big endian from the target's endianness. /// /// On big endian, this is a no-op. On little endian, the bytes are swapped. -#[cfg(target_endian = "big")] #[inline] pub fn to_be32(x: i32) -> i32 { x } +#[cfg(target_endian = "big")] #[inline] pub fn to_be32(x: u32) -> u32 { x } -/// Convert an i64 to big endian from the target's endianness. +/// Convert an u64 to big endian from the target's endianness. /// /// On big endian, this is a no-op. On little endian, the bytes are swapped. -#[cfg(target_endian = "little")] #[inline] pub fn to_be64(x: i64) -> i64 { unsafe { bswap64(x) } } +#[cfg(target_endian = "little")] #[inline] pub fn to_be64(x: u64) -> u64 { unsafe { bswap64(x) } } -/// Convert an i64 to big endian from the target's endianness. +/// Convert an u64 to big endian from the target's endianness. /// /// On big endian, this is a no-op. On little endian, the bytes are swapped. -#[cfg(target_endian = "big")] #[inline] pub fn to_be64(x: i64) -> i64 { x } +#[cfg(target_endian = "big")] #[inline] pub fn to_be64(x: u64) -> u64 { x } -/// Convert an i16 from little endian to the target's endianness. +/// Convert an u16 from little endian to the target's endianness. /// /// On little endian, this is a no-op. On big endian, the bytes are swapped. -#[cfg(target_endian = "little")] #[inline] pub fn from_le16(x: i16) -> i16 { x } +#[cfg(target_endian = "little")] #[inline] pub fn from_le16(x: u16) -> u16 { x } -/// Convert an i16 from little endian to the target's endianness. +/// Convert an u16 from little endian to the target's endianness. /// /// On little endian, this is a no-op. On big endian, the bytes are swapped. -#[cfg(target_endian = "big")] #[inline] pub fn from_le16(x: i16) -> i16 { unsafe { bswap16(x) } } +#[cfg(target_endian = "big")] #[inline] pub fn from_le16(x: u16) -> u16 { unsafe { bswap16(x) } } -/// Convert an i32 from little endian to the target's endianness. +/// Convert an u32 from little endian to the target's endianness. /// /// On little endian, this is a no-op. On big endian, the bytes are swapped. -#[cfg(target_endian = "little")] #[inline] pub fn from_le32(x: i32) -> i32 { x } +#[cfg(target_endian = "little")] #[inline] pub fn from_le32(x: u32) -> u32 { x } -/// Convert an i32 from little endian to the target's endianness. +/// Convert an u32 from little endian to the target's endianness. /// /// On little endian, this is a no-op. On big endian, the bytes are swapped. -#[cfg(target_endian = "big")] #[inline] pub fn from_le32(x: i32) -> i32 { unsafe { bswap32(x) } } +#[cfg(target_endian = "big")] #[inline] pub fn from_le32(x: u32) -> u32 { unsafe { bswap32(x) } } -/// Convert an i64 from little endian to the target's endianness. +/// Convert an u64 from little endian to the target's endianness. /// /// On little endian, this is a no-op. On big endian, the bytes are swapped. -#[cfg(target_endian = "little")] #[inline] pub fn from_le64(x: i64) -> i64 { x } +#[cfg(target_endian = "little")] #[inline] pub fn from_le64(x: u64) -> u64 { x } -/// Convert an i64 from little endian to the target's endianness. +/// Convert an u64 from little endian to the target's endianness. /// /// On little endian, this is a no-op. On big endian, the bytes are swapped. -#[cfg(target_endian = "big")] #[inline] pub fn from_le64(x: i64) -> i64 { unsafe { bswap64(x) } } +#[cfg(target_endian = "big")] #[inline] pub fn from_le64(x: u64) -> u64 { unsafe { bswap64(x) } } -/// Convert an i16 from big endian to the target's endianness. +/// Convert an u16 from big endian to the target's endianness. /// /// On big endian, this is a no-op. On little endian, the bytes are swapped. -#[cfg(target_endian = "little")] #[inline] pub fn from_be16(x: i16) -> i16 { unsafe { bswap16(x) } } +#[cfg(target_endian = "little")] #[inline] pub fn from_be16(x: u16) -> u16 { unsafe { bswap16(x) } } -/// Convert an i16 from big endian to the target's endianness. +/// Convert an u16 from big endian to the target's endianness. /// /// On big endian, this is a no-op. On little endian, the bytes are swapped. -#[cfg(target_endian = "big")] #[inline] pub fn from_be16(x: i16) -> i16 { x } +#[cfg(target_endian = "big")] #[inline] pub fn from_be16(x: u16) -> u16 { x } -/// Convert an i32 from big endian to the target's endianness. +/// Convert an u32 from big endian to the target's endianness. /// /// On big endian, this is a no-op. On little endian, the bytes are swapped. -#[cfg(target_endian = "little")] #[inline] pub fn from_be32(x: i32) -> i32 { unsafe { bswap32(x) } } +#[cfg(target_endian = "little")] #[inline] pub fn from_be32(x: u32) -> u32 { unsafe { bswap32(x) } } -/// Convert an i32 from big endian to the target's endianness. +/// Convert an u32 from big endian to the target's endianness. /// /// On big endian, this is a no-op. On little endian, the bytes are swapped. -#[cfg(target_endian = "big")] #[inline] pub fn from_be32(x: i32) -> i32 { x } +#[cfg(target_endian = "big")] #[inline] pub fn from_be32(x: u32) -> u32 { x } -/// Convert an i64 from big endian to the target's endianness. +/// Convert an u64 from big endian to the target's endianness. /// /// On big endian, this is a no-op. On little endian, the bytes are swapped. -#[cfg(target_endian = "little")] #[inline] pub fn from_be64(x: i64) -> i64 { unsafe { bswap64(x) } } +#[cfg(target_endian = "little")] #[inline] pub fn from_be64(x: u64) -> u64 { unsafe { bswap64(x) } } -/// Convert an i64 from big endian to the target's endianness. +/// Convert an u64 from big endian to the target's endianness. /// /// On big endian, this is a no-op. On little endian, the bytes are swapped. -#[cfg(target_endian = "big")] #[inline] pub fn from_be64(x: i64) -> i64 { x } +#[cfg(target_endian = "big")] #[inline] pub fn from_be64(x: u64) -> u64 { x } /** diff --git a/src/libstd/num/i16.rs b/src/libstd/num/i16.rs index 42710a8b459..79827421f92 100644 --- a/src/libstd/num/i16.rs +++ b/src/libstd/num/i16.rs @@ -28,17 +28,17 @@ int_module!(i16, 16) impl Bitwise for i16 { /// Returns the number of ones in the binary representation of the number. #[inline] - fn count_ones(&self) -> i16 { unsafe { intrinsics::ctpop16(*self) } } + fn count_ones(&self) -> i16 { unsafe { intrinsics::ctpop16(*self as u16) as i16 } } /// Returns the number of leading zeros in the in the binary representation /// of the number. #[inline] - fn leading_zeros(&self) -> i16 { unsafe { intrinsics::ctlz16(*self) } } + fn leading_zeros(&self) -> i16 { unsafe { intrinsics::ctlz16(*self as u16) as i16 } } /// Returns the number of trailing zeros in the in the binary representation /// of the number. #[inline] - fn trailing_zeros(&self) -> i16 { unsafe { intrinsics::cttz16(*self) } } + fn trailing_zeros(&self) -> i16 { unsafe { intrinsics::cttz16(*self as u16) as i16 } } } impl CheckedAdd for i16 { diff --git a/src/libstd/num/i32.rs b/src/libstd/num/i32.rs index 69d4b0639f7..97f03299b87 100644 --- a/src/libstd/num/i32.rs +++ b/src/libstd/num/i32.rs @@ -28,17 +28,17 @@ int_module!(i32, 32) impl Bitwise for i32 { /// Returns the number of ones in the binary representation of the number. #[inline] - fn count_ones(&self) -> i32 { unsafe { intrinsics::ctpop32(*self) } } + fn count_ones(&self) -> i32 { unsafe { intrinsics::ctpop32(*self as u32) as i32 } } /// Returns the number of leading zeros in the in the binary representation /// of the number. #[inline] - fn leading_zeros(&self) -> i32 { unsafe { intrinsics::ctlz32(*self) } } + fn leading_zeros(&self) -> i32 { unsafe { intrinsics::ctlz32(*self as u32) as i32 } } /// Returns the number of trailing zeros in the in the binary representation /// of the number. #[inline] - fn trailing_zeros(&self) -> i32 { unsafe { intrinsics::cttz32(*self) } } + fn trailing_zeros(&self) -> i32 { unsafe { intrinsics::cttz32(*self as u32) as i32 } } } impl CheckedAdd for i32 { diff --git a/src/libstd/num/i64.rs b/src/libstd/num/i64.rs index 1f7066c25db..00823aa22c2 100644 --- a/src/libstd/num/i64.rs +++ b/src/libstd/num/i64.rs @@ -30,16 +30,16 @@ int_module!(i64, 64) impl Bitwise for i64 { /// Returns the number of ones in the binary representation of the number. #[inline] - fn count_ones(&self) -> i64 { unsafe { intrinsics::ctpop64(*self) } } + fn count_ones(&self) -> i64 { unsafe { intrinsics::ctpop64(*self as u64) as i64 } } /// Returns the number of leading zeros in the in the binary representation /// of the number. #[inline] - fn leading_zeros(&self) -> i64 { unsafe { intrinsics::ctlz64(*self) } } + fn leading_zeros(&self) -> i64 { unsafe { intrinsics::ctlz64(*self as u64) as i64 } } /// Counts the number of trailing zeros. #[inline] - fn trailing_zeros(&self) -> i64 { unsafe { intrinsics::cttz64(*self) } } + fn trailing_zeros(&self) -> i64 { unsafe { intrinsics::cttz64(*self as u64) as i64 } } } impl CheckedAdd for i64 { diff --git a/src/libstd/num/i8.rs b/src/libstd/num/i8.rs index 061ffddf231..2d349fa7f4f 100644 --- a/src/libstd/num/i8.rs +++ b/src/libstd/num/i8.rs @@ -28,17 +28,17 @@ int_module!(i8, 8) impl Bitwise for i8 { /// Returns the number of ones in the binary representation of the number. #[inline] - fn count_ones(&self) -> i8 { unsafe { intrinsics::ctpop8(*self) } } + fn count_ones(&self) -> i8 { unsafe { intrinsics::ctpop8(*self as u8) as i8 } } /// Returns the number of leading zeros in the in the binary representation /// of the number. #[inline] - fn leading_zeros(&self) -> i8 { unsafe { intrinsics::ctlz8(*self) } } + fn leading_zeros(&self) -> i8 { unsafe { intrinsics::ctlz8(*self as u8) as i8 } } /// Returns the number of trailing zeros in the in the binary representation /// of the number. #[inline] - fn trailing_zeros(&self) -> i8 { unsafe { intrinsics::cttz8(*self) } } + fn trailing_zeros(&self) -> i8 { unsafe { intrinsics::cttz8(*self as u8) as i8 } } } impl CheckedAdd for i8 { diff --git a/src/libuuid/lib.rs b/src/libuuid/lib.rs index 2ac6780af4c..559edd587fd 100644 --- a/src/libuuid/lib.rs +++ b/src/libuuid/lib.rs @@ -220,9 +220,9 @@ impl Uuid { data4: [0, ..8] }; - fields.data1 = to_be32(d1 as i32) as u32; - fields.data2 = to_be16(d2 as i16) as u16; - fields.data3 = to_be16(d3 as i16) as u16; + fields.data1 = to_be32(d1); + fields.data2 = to_be16(d2); + fields.data3 = to_be16(d3); slice::bytes::copy_memory(fields.data4, d4); unsafe { @@ -343,9 +343,9 @@ impl Uuid { unsafe { uf = transmute_copy(&self.bytes); } - uf.data1 = to_be32(uf.data1 as i32) as u32; - uf.data2 = to_be16(uf.data2 as i16) as u16; - uf.data3 = to_be16(uf.data3 as i16) as u16; + uf.data1 = to_be32(uf.data1); + uf.data2 = to_be16(uf.data2); + uf.data3 = to_be16(uf.data3); let s = format!("{:08x}-{:04x}-{:04x}-{:02x}{:02x}-\ {:02x}{:02x}{:02x}{:02x}{:02x}{:02x}", uf.data1, diff --git a/src/test/bench/sudoku.rs b/src/test/bench/sudoku.rs index 80fea6d4932..f5724fc1324 100644 --- a/src/test/bench/sudoku.rs +++ b/src/test/bench/sudoku.rs @@ -16,7 +16,7 @@ use std::io; use std::io::stdio::StdReader; use std::io::BufferedReader; use std::os; -use std::intrinsics::cttz16; +use std::num::Bitwise; // Computes a single solution to a given 9x9 sudoku // @@ -187,9 +187,7 @@ impl Colors { if (0u16 == val) { return 0u8; } else { - unsafe { - return cttz16(val as i16) as u8; - } + return val.trailing_zeros() as u8 } } diff --git a/src/test/run-pass/intrinsics-integer.rs b/src/test/run-pass/intrinsics-integer.rs index 164d16fe503..e31b941f956 100644 --- a/src/test/run-pass/intrinsics-integer.rs +++ b/src/test/run-pass/intrinsics-integer.rs @@ -1,4 +1,3 @@ - // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. @@ -13,24 +12,24 @@ mod rusti { extern "rust-intrinsic" { - pub fn ctpop8(x: i8) -> i8; - pub fn ctpop16(x: i16) -> i16; - pub fn ctpop32(x: i32) -> i32; - pub fn ctpop64(x: i64) -> i64; - - pub fn ctlz8(x: i8) -> i8; - pub fn ctlz16(x: i16) -> i16; - pub fn ctlz32(x: i32) -> i32; - pub fn ctlz64(x: i64) -> i64; - - pub fn cttz8(x: i8) -> i8; - pub fn cttz16(x: i16) -> i16; - pub fn cttz32(x: i32) -> i32; - pub fn cttz64(x: i64) -> i64; - - pub fn bswap16(x: i16) -> i16; - pub fn bswap32(x: i32) -> i32; - pub fn bswap64(x: i64) -> i64; + pub fn ctpop8(x: u8) -> u8; + pub fn ctpop16(x: u16) -> u16; + pub fn ctpop32(x: u32) -> u32; + pub fn ctpop64(x: u64) -> u64; + + pub fn ctlz8(x: u8) -> u8; + pub fn ctlz16(x: u16) -> u16; + pub fn ctlz32(x: u32) -> u32; + pub fn ctlz64(x: u64) -> u64; + + pub fn cttz8(x: u8) -> u8; + pub fn cttz16(x: u16) -> u16; + pub fn cttz32(x: u32) -> u32; + pub fn cttz64(x: u64) -> u64; + + pub fn bswap16(x: u16) -> u16; + pub fn bswap32(x: u32) -> u32; + pub fn bswap64(x: u64) -> u64; } } @@ -38,83 +37,83 @@ pub fn main() { unsafe { use rusti::*; - assert_eq!(ctpop8(0i8), 0i8); - assert_eq!(ctpop16(0i16), 0i16); - assert_eq!(ctpop32(0i32), 0i32); - assert_eq!(ctpop64(0i64), 0i64); - - assert_eq!(ctpop8(1i8), 1i8); - assert_eq!(ctpop16(1i16), 1i16); - assert_eq!(ctpop32(1i32), 1i32); - assert_eq!(ctpop64(1i64), 1i64); - - assert_eq!(ctpop8(10i8), 2i8); - assert_eq!(ctpop16(10i16), 2i16); - assert_eq!(ctpop32(10i32), 2i32); - assert_eq!(ctpop64(10i64), 2i64); - - assert_eq!(ctpop8(100i8), 3i8); - assert_eq!(ctpop16(100i16), 3i16); - assert_eq!(ctpop32(100i32), 3i32); - assert_eq!(ctpop64(100i64), 3i64); - - assert_eq!(ctpop8(-1i8), 8i8); - assert_eq!(ctpop16(-1i16), 16i16); - assert_eq!(ctpop32(-1i32), 32i32); - assert_eq!(ctpop64(-1i64), 64i64); - - assert_eq!(ctlz8(0i8), 8i8); - assert_eq!(ctlz16(0i16), 16i16); - assert_eq!(ctlz32(0i32), 32i32); - assert_eq!(ctlz64(0i64), 64i64); - - assert_eq!(ctlz8(1i8), 7i8); - assert_eq!(ctlz16(1i16), 15i16); - assert_eq!(ctlz32(1i32), 31i32); - assert_eq!(ctlz64(1i64), 63i64); - - assert_eq!(ctlz8(10i8), 4i8); - assert_eq!(ctlz16(10i16), 12i16); - assert_eq!(ctlz32(10i32), 28i32); - assert_eq!(ctlz64(10i64), 60i64); - - assert_eq!(ctlz8(100i8), 1i8); - assert_eq!(ctlz16(100i16), 9i16); - assert_eq!(ctlz32(100i32), 25i32); - assert_eq!(ctlz64(100i64), 57i64); - - assert_eq!(cttz8(-1i8), 0i8); - assert_eq!(cttz16(-1i16), 0i16); - assert_eq!(cttz32(-1i32), 0i32); - assert_eq!(cttz64(-1i64), 0i64); - - assert_eq!(cttz8(0i8), 8i8); - assert_eq!(cttz16(0i16), 16i16); - assert_eq!(cttz32(0i32), 32i32); - assert_eq!(cttz64(0i64), 64i64); - - assert_eq!(cttz8(1i8), 0i8); - assert_eq!(cttz16(1i16), 0i16); - assert_eq!(cttz32(1i32), 0i32); - assert_eq!(cttz64(1i64), 0i64); - - assert_eq!(cttz8(10i8), 1i8); - assert_eq!(cttz16(10i16), 1i16); - assert_eq!(cttz32(10i32), 1i32); - assert_eq!(cttz64(10i64), 1i64); - - assert_eq!(cttz8(100i8), 2i8); - assert_eq!(cttz16(100i16), 2i16); - assert_eq!(cttz32(100i32), 2i32); - assert_eq!(cttz64(100i64), 2i64); - - assert_eq!(cttz8(-1i8), 0i8); - assert_eq!(cttz16(-1i16), 0i16); - assert_eq!(cttz32(-1i32), 0i32); - assert_eq!(cttz64(-1i64), 0i64); - - assert_eq!(bswap16(0x0A0Bi16), 0x0B0Ai16); - assert_eq!(bswap32(0x0ABBCC0Di32), 0x0DCCBB0Ai32); - assert_eq!(bswap64(0x0122334455667708i64), 0x0877665544332201i64); + assert_eq!(ctpop8(0u8), 0u8); + assert_eq!(ctpop16(0u16), 0u16); + assert_eq!(ctpop32(0u32), 0u32); + assert_eq!(ctpop64(0u64), 0u64); + + assert_eq!(ctpop8(1u8), 1u8); + assert_eq!(ctpop16(1u16), 1u16); + assert_eq!(ctpop32(1u32), 1u32); + assert_eq!(ctpop64(1u64), 1u64); + + assert_eq!(ctpop8(10u8), 2u8); + assert_eq!(ctpop16(10u16), 2u16); + assert_eq!(ctpop32(10u32), 2u32); + assert_eq!(ctpop64(10u64), 2u64); + + assert_eq!(ctpop8(100u8), 3u8); + assert_eq!(ctpop16(100u16), 3u16); + assert_eq!(ctpop32(100u32), 3u32); + assert_eq!(ctpop64(100u64), 3u64); + + assert_eq!(ctpop8(-1u8), 8u8); + assert_eq!(ctpop16(-1u16), 16u16); + assert_eq!(ctpop32(-1u32), 32u32); + assert_eq!(ctpop64(-1u64), 64u64); + + assert_eq!(ctlz8(0u8), 8u8); + assert_eq!(ctlz16(0u16), 16u16); + assert_eq!(ctlz32(0u32), 32u32); + assert_eq!(ctlz64(0u64), 64u64); + + assert_eq!(ctlz8(1u8), 7u8); + assert_eq!(ctlz16(1u16), 15u16); + assert_eq!(ctlz32(1u32), 31u32); + assert_eq!(ctlz64(1u64), 63u64); + + assert_eq!(ctlz8(10u8), 4u8); + assert_eq!(ctlz16(10u16), 12u16); + assert_eq!(ctlz32(10u32), 28u32); + assert_eq!(ctlz64(10u64), 60u64); + + assert_eq!(ctlz8(100u8), 1u8); + assert_eq!(ctlz16(100u16), 9u16); + assert_eq!(ctlz32(100u32), 25u32); + assert_eq!(ctlz64(100u64), 57u64); + + assert_eq!(cttz8(-1u8), 0u8); + assert_eq!(cttz16(-1u16), 0u16); + assert_eq!(cttz32(-1u32), 0u32); + assert_eq!(cttz64(-1u64), 0u64); + + assert_eq!(cttz8(0u8), 8u8); + assert_eq!(cttz16(0u16), 16u16); + assert_eq!(cttz32(0u32), 32u32); + assert_eq!(cttz64(0u64), 64u64); + + assert_eq!(cttz8(1u8), 0u8); + assert_eq!(cttz16(1u16), 0u16); + assert_eq!(cttz32(1u32), 0u32); + assert_eq!(cttz64(1u64), 0u64); + + assert_eq!(cttz8(10u8), 1u8); + assert_eq!(cttz16(10u16), 1u16); + assert_eq!(cttz32(10u32), 1u32); + assert_eq!(cttz64(10u64), 1u64); + + assert_eq!(cttz8(100u8), 2u8); + assert_eq!(cttz16(100u16), 2u16); + assert_eq!(cttz32(100u32), 2u32); + assert_eq!(cttz64(100u64), 2u64); + + assert_eq!(cttz8(-1u8), 0u8); + assert_eq!(cttz16(-1u16), 0u16); + assert_eq!(cttz32(-1u32), 0u32); + assert_eq!(cttz64(-1u64), 0u64); + + assert_eq!(bswap16(0x0A0Bu16), 0x0B0Au16); + assert_eq!(bswap32(0x0ABBCC0Du32), 0x0DCCBB0Au32); + assert_eq!(bswap64(0x0122334455667708u64), 0x0877665544332201u64); } } -- cgit 1.4.1-3-g733a5 From c7325bdd8e29d57e7bc971b86accfb352c4262bc Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sun, 13 Apr 2014 20:22:58 -0700 Subject: Add a default impl for Set::is_superset I also deleted a bunch of documentation that was copy/pasted from the trait definition. --- src/libcollections/hashmap.rs | 15 --------------- src/libcollections/treemap.rs | 36 ++++++++---------------------------- src/libstd/container.rs | 4 +++- 3 files changed, 11 insertions(+), 44 deletions(-) (limited to 'src/libstd') diff --git a/src/libcollections/hashmap.rs b/src/libcollections/hashmap.rs index a2413d78e5f..46b93242685 100644 --- a/src/libcollections/hashmap.rs +++ b/src/libcollections/hashmap.rs @@ -1424,43 +1424,28 @@ impl, S, H: Hasher> Eq for HashSet { } impl, S, H: Hasher> Container for HashSet { - /// Return the number of elements in the set fn len(&self) -> uint { self.map.len() } } impl, S, H: Hasher> Mutable for HashSet { - /// Clear the set, removing all values. fn clear(&mut self) { self.map.clear() } } impl, S, H: Hasher> Set for HashSet { - /// Return true if the set contains a value fn contains(&self, value: &T) -> bool { self.map.search(value).is_some() } - /// Return true if the set has no elements in common with `other`. - /// This is equivalent to checking for an empty intersection. fn is_disjoint(&self, other: &HashSet) -> bool { self.iter().all(|v| !other.contains(v)) } - /// Return true if the set is a subset of another fn is_subset(&self, other: &HashSet) -> bool { self.iter().all(|v| other.contains(v)) } - - /// Return true if the set is a superset of another - fn is_superset(&self, other: &HashSet) -> bool { - other.is_subset(self) - } } impl, S, H: Hasher> MutableSet for HashSet { - /// Add a value to the set. Return true if the value was not already - /// present in the set. fn insert(&mut self, value: T) -> bool { self.map.insert(value, ()) } - /// Remove a value from the set. Return true if the value was - /// present in the set. fn remove(&mut self, value: &T) -> bool { self.map.remove(value) } } diff --git a/src/libcollections/treemap.rs b/src/libcollections/treemap.rs index d964e73f696..b14c5fd9f29 100644 --- a/src/libcollections/treemap.rs +++ b/src/libcollections/treemap.rs @@ -573,74 +573,54 @@ impl Ord for TreeSet { } impl Container for TreeSet { - /// Return the number of elements in the set #[inline] fn len(&self) -> uint { self.map.len() } - - /// Return true if the set contains no elements - #[inline] - fn is_empty(&self) -> bool { self.map.is_empty() } } impl Mutable for TreeSet { - /// Clear the set, removing all values. #[inline] fn clear(&mut self) { self.map.clear() } } impl Set for TreeSet { - /// Return true if the set contains a value #[inline] fn contains(&self, value: &T) -> bool { self.map.contains_key(value) } - /// Return true if the set has no elements in common with `other`. - /// This is equivalent to checking for an empty intersection. fn is_disjoint(&self, other: &TreeSet) -> bool { self.intersection(other).next().is_none() } - /// Return true if the set is a subset of another - #[inline] fn is_subset(&self, other: &TreeSet) -> bool { - other.is_superset(self) - } - - /// Return true if the set is a superset of another - fn is_superset(&self, other: &TreeSet) -> bool { let mut x = self.iter(); let mut y = other.iter(); let mut a = x.next(); let mut b = y.next(); - while b.is_some() { - if a.is_none() { - return false + while a.is_some() { + if b.is_none() { + return false; } let a1 = a.unwrap(); let b1 = b.unwrap(); - match a1.cmp(b1) { - Less => (), - Greater => return false, - Equal => b = y.next(), + match b1.cmp(a1) { + Less => (), + Greater => return false, + Equal => a = x.next(), } - a = x.next(); + b = y.next(); } true } } impl MutableSet for TreeSet { - /// Add a value to the set. Return true if the value was not already - /// present in the set. #[inline] fn insert(&mut self, value: T) -> bool { self.map.insert(value, ()) } - /// Remove a value from the set. Return true if the value was - /// present in the set. #[inline] fn remove(&mut self, value: &T) -> bool { self.map.remove(value) } } diff --git a/src/libstd/container.rs b/src/libstd/container.rs index 326b9fa3d33..e8ee3792dcf 100644 --- a/src/libstd/container.rs +++ b/src/libstd/container.rs @@ -88,7 +88,9 @@ pub trait Set: Container { fn is_subset(&self, other: &Self) -> bool; /// Return true if the set is a superset of another - fn is_superset(&self, other: &Self) -> bool; + fn is_superset(&self, other: &Self) -> bool { + other.is_subset(self) + } // FIXME #8154: Add difference, sym. difference, intersection and union iterators } -- cgit 1.4.1-3-g733a5 From c8f5b701dcf0b7dc4d78ef0d29f10e4f080b2517 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 15 Apr 2014 18:18:08 -0700 Subject: std: Remove pub use globs --- src/libstd/os.rs | 32 +++++++++++++++++++++----------- src/libstd/rt/local_ptr.rs | 6 ++++-- 2 files changed, 25 insertions(+), 13 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/os.rs b/src/libstd/os.rs index a16113cb48f..25f503174bc 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -1294,37 +1294,47 @@ impl Drop for MemoryMap { /// Various useful system-specific constants. pub mod consts { #[cfg(unix)] - pub use os::consts::unix::*; + pub use os::consts::unix::FAMILY; #[cfg(windows)] - pub use os::consts::windows::*; + pub use os::consts::windows::FAMILY; #[cfg(target_os = "macos")] - pub use os::consts::macos::*; + pub use os::consts::macos::{SYSNAME, DLL_PREFIX, DLL_SUFFIX, DLL_EXTENSION}; + #[cfg(target_os = "macos")] + pub use os::consts::macos::{EXE_SUFFIX, EXE_EXTENSION}; #[cfg(target_os = "freebsd")] - pub use os::consts::freebsd::*; + pub use os::consts::freebsd::{SYSNAME, DLL_PREFIX, DLL_SUFFIX, DLL_EXTENSION}; + #[cfg(target_os = "freebsd")] + pub use os::consts::freebsd::{EXE_SUFFIX, EXE_EXTENSION}; #[cfg(target_os = "linux")] - pub use os::consts::linux::*; + pub use os::consts::linux::{SYSNAME, DLL_PREFIX, DLL_SUFFIX, DLL_EXTENSION}; + #[cfg(target_os = "linux")] + pub use os::consts::linux::{EXE_SUFFIX, EXE_EXTENSION}; #[cfg(target_os = "android")] - pub use os::consts::android::*; + pub use os::consts::android::{SYSNAME, DLL_PREFIX, DLL_SUFFIX, DLL_EXTENSION}; + #[cfg(target_os = "android")] + pub use os::consts::android::{EXE_SUFFIX, EXE_EXTENSION}; #[cfg(target_os = "win32")] - pub use os::consts::win32::*; + pub use os::consts::win32::{SYSNAME, DLL_PREFIX, DLL_SUFFIX, DLL_EXTENSION}; + #[cfg(target_os = "win32")] + pub use os::consts::win32::{EXE_SUFFIX, EXE_EXTENSION}; #[cfg(target_arch = "x86")] - pub use os::consts::x86::*; + pub use os::consts::x86::{ARCH}; #[cfg(target_arch = "x86_64")] - pub use os::consts::x86_64::*; + pub use os::consts::x86_64::{ARCH}; #[cfg(target_arch = "arm")] - pub use os::consts::arm::*; + pub use os::consts::arm::{ARCH}; #[cfg(target_arch = "mips")] - pub use os::consts::mips::*; + pub use os::consts::mips::{ARCH}; /// Constants for Unix systems. pub mod unix { diff --git a/src/libstd/rt/local_ptr.rs b/src/libstd/rt/local_ptr.rs index 6b61af1d9a2..ff82be97489 100644 --- a/src/libstd/rt/local_ptr.rs +++ b/src/libstd/rt/local_ptr.rs @@ -23,10 +23,12 @@ use ptr::RawPtr; #[cfg(windows)] // mingw-w32 doesn't like thread_local things #[cfg(target_os = "android")] // see #10686 -pub use self::native::*; +pub use self::native::{init, cleanup, put, take, try_take, unsafe_take, exists, + unsafe_borrow, try_unsafe_borrow}; #[cfg(not(windows), not(target_os = "android"))] -pub use self::compiled::*; +pub use self::compiled::{init, cleanup, put, take, try_take, unsafe_take, exists, + unsafe_borrow, try_unsafe_borrow}; /// Encapsulates a borrowed value. When this value goes out of scope, the /// pointer is returned. -- cgit 1.4.1-3-g733a5 From 55f02b2c1bdb6a8947478b1bdfd16423bfa7e2f5 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 15 Apr 2014 06:35:15 -0700 Subject: std: Un-ignore some float tests on windows These were fixed in the upgrade from mingw32 to mingw64. Closes #8663 --- src/libstd/num/f32.rs | 2 +- src/libstd/num/f64.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index 7c5fe4ff274..7cd6aaa6310 100644 --- a/src/libstd/num/f32.rs +++ b/src/libstd/num/f32.rs @@ -1037,7 +1037,7 @@ mod tests { assert_eq!(0f32.abs_sub(&INFINITY), 0f32); } - #[test] #[ignore(cfg(windows))] // FIXME #8663 + #[test] fn test_abs_sub_nowin() { assert!(NAN.abs_sub(&-1f32).is_nan()); assert!(1f32.abs_sub(&NAN).is_nan()); diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index 69328a5ecdc..8b52a6747f4 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -1041,7 +1041,7 @@ mod tests { assert_eq!(0f64.abs_sub(&INFINITY), 0f64); } - #[test] #[ignore(cfg(windows))] // FIXME #8663 + #[test] fn test_abs_sub_nowin() { assert!(NAN.abs_sub(&-1f64).is_nan()); assert!(1f64.abs_sub(&NAN).is_nan()); -- cgit 1.4.1-3-g733a5