diff options
| author | bors <bors@rust-lang.org> | 2014-05-30 21:21:39 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-05-30 21:21:39 -0700 |
| commit | 60a43f9bc5d24b47aae9681fc7ef47d517329e59 (patch) | |
| tree | c0e46f35c6d6482996e6b10eaf635201b51e82d4 /src/libstd | |
| parent | cc4513202d6f9c6896054ebaa1d99230b06e9f10 (diff) | |
| parent | bb96ee6123082908dba86cb22344f0c23915bf06 (diff) | |
| download | rust-60a43f9bc5d24b47aae9681fc7ef47d517329e59.tar.gz rust-60a43f9bc5d24b47aae9681fc7ef47d517329e59.zip | |
auto merge of #14534 : alexcrichton/rust/snapshots, r=sfackler
This is part 2 of the saga of renaming the Partial/Total equality and comparison traits.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/ascii.rs | 2 | ||||
| -rw-r--r-- | src/libstd/bitflags.rs | 4 | ||||
| -rw-r--r-- | src/libstd/c_str.rs | 4 | ||||
| -rw-r--r-- | src/libstd/comm/mod.rs | 4 | ||||
| -rw-r--r-- | src/libstd/fmt.rs | 40 | ||||
| -rw-r--r-- | src/libstd/io/buffered.rs | 2 | ||||
| -rw-r--r-- | src/libstd/io/mod.rs | 8 | ||||
| -rw-r--r-- | src/libstd/io/net/ip.rs | 4 | ||||
| -rw-r--r-- | src/libstd/io/process.rs | 4 | ||||
| -rw-r--r-- | src/libstd/io/signal.rs | 2 | ||||
| -rw-r--r-- | src/libstd/lib.rs | 7 | ||||
| -rw-r--r-- | src/libstd/num/mod.rs | 2 | ||||
| -rw-r--r-- | src/libstd/num/strconv.rs | 10 | ||||
| -rw-r--r-- | src/libstd/path/posix.rs | 4 | ||||
| -rw-r--r-- | src/libstd/path/windows.rs | 6 | ||||
| -rw-r--r-- | src/libstd/prelude.rs | 2 | ||||
| -rw-r--r-- | src/libstd/reflect.rs | 439 | ||||
| -rw-r--r-- | src/libstd/repr.rs | 663 | ||||
| -rw-r--r-- | src/libstd/rt/stack.rs | 31 | ||||
| -rw-r--r-- | src/libstd/rt/unwind.rs | 41 | ||||
| -rw-r--r-- | src/libstd/slice.rs | 2 | ||||
| -rw-r--r-- | src/libstd/str.rs | 6 | ||||
| -rw-r--r-- | src/libstd/string.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sync/deque.rs | 2 | ||||
| -rw-r--r-- | src/libstd/vec.rs | 10 |
25 files changed, 42 insertions, 1259 deletions
diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index 75b31f9c354..222297aaf0e 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -23,7 +23,7 @@ use to_str::{IntoStr}; use vec::Vec; /// Datatype to hold one ascii character. It wraps a `u8`, with the highest bit always zero. -#[deriving(Clone, Eq, Ord, TotalOrd, TotalEq, Hash)] +#[deriving(Clone, PartialEq, PartialOrd, TotalOrd, TotalEq, Hash)] pub struct Ascii { chr: u8 } impl Ascii { diff --git a/src/libstd/bitflags.rs b/src/libstd/bitflags.rs index 6b393987281..eb8c7e7d283 100644 --- a/src/libstd/bitflags.rs +++ b/src/libstd/bitflags.rs @@ -78,7 +78,7 @@ //! //! # Derived traits //! -//! The `Eq` and `Clone` traits are automatically derived for the `struct` using +//! The `PartialEq` and `Clone` traits are automatically derived for the `struct` using //! the `deriving` attribute. Additional traits can be derived by providing an //! explicit `deriving` attribute on `flags`. //! @@ -112,7 +112,7 @@ macro_rules! bitflags( ($(#[$attr:meta])* flags $BitFlags:ident: $T:ty { $($(#[$Flag_attr:meta])* static $Flag:ident = $value:expr),+ }) => ( - #[deriving(Eq, TotalEq, Clone)] + #[deriving(PartialEq, TotalEq, Clone)] $(#[$attr])* pub struct $BitFlags { bits: $T, diff --git a/src/libstd/c_str.rs b/src/libstd/c_str.rs index 983d76a0844..4e39518deb4 100644 --- a/src/libstd/c_str.rs +++ b/src/libstd/c_str.rs @@ -66,7 +66,7 @@ fn main() { */ use clone::Clone; -use cmp::Eq; +use cmp::PartialEq; use container::Container; use iter::{Iterator, range}; use kinds::marker; @@ -109,7 +109,7 @@ impl Clone for CString { } } -impl Eq for CString { +impl PartialEq for CString { fn eq(&self, other: &CString) -> bool { if self.buf as uint == other.buf as uint { true diff --git a/src/libstd/comm/mod.rs b/src/libstd/comm/mod.rs index 18857e221fa..170618e276b 100644 --- a/src/libstd/comm/mod.rs +++ b/src/libstd/comm/mod.rs @@ -360,7 +360,7 @@ pub struct SyncSender<T> { /// This enumeration is the list of the possible reasons that try_recv could not /// return data when called. -#[deriving(Eq, Clone, Show)] +#[deriving(PartialEq, Clone, Show)] pub enum TryRecvError { /// This channel is currently empty, but the sender(s) have not yet /// disconnected, so data may yet become available. @@ -372,7 +372,7 @@ pub enum TryRecvError { /// This enumeration is the list of the possible error outcomes for the /// `SyncSender::try_send` method. -#[deriving(Eq, Clone, Show)] +#[deriving(PartialEq, Clone, Show)] pub enum TrySendError<T> { /// The data could not be sent on the channel because it would require that /// the callee block to send the data. diff --git a/src/libstd/fmt.rs b/src/libstd/fmt.rs index 9bca2f4248c..8dc2dd4bdb6 100644 --- a/src/libstd/fmt.rs +++ b/src/libstd/fmt.rs @@ -492,10 +492,6 @@ will look like `"\\{"`. use io::Writer; use io; -#[cfg(stage0)] -use option::None; -#[cfg(stage0)] -use repr; use result::{Ok, Err}; use str::{Str, StrAllocating}; use str; @@ -524,21 +520,6 @@ pub use core::fmt::{secret_float, secret_upper_exp, secret_lower_exp}; #[doc(hidden)] pub use core::fmt::{secret_pointer}; -#[doc(hidden)] -#[cfg(stage0)] -pub fn secret_poly<T: Poly>(x: &T, fmt: &mut Formatter) -> Result { - // FIXME #11938 - UFCS would make us able call the this method - // directly Poly::fmt(x, fmt). - x.fmt(fmt) -} - -/// Format trait for the `?` character -#[cfg(stage0)] -pub trait Poly { - /// Formats the value using the given formatter. - fn fmt(&self, &mut Formatter) -> Result; -} - /// The format function takes a precompiled format string and a list of /// arguments, to return the resulting formatted string. /// @@ -562,27 +543,6 @@ pub fn format(args: &Arguments) -> string::String{ str::from_utf8(output.unwrap().as_slice()).unwrap().into_string() } -#[cfg(stage0)] -impl<T> Poly for T { - fn fmt(&self, f: &mut Formatter) -> Result { - match (f.width, f.precision) { - (None, None) => { - match repr::write_repr(f, self) { - Ok(()) => Ok(()), - Err(..) => Err(WriteError), - } - } - - // If we have a specified width for formatting, then we have to make - // this allocation of a new string - _ => { - let s = repr::repr_to_str(self); - f.pad(s.as_slice()) - } - } - } -} - impl<'a> Writer for Formatter<'a> { fn write(&mut self, b: &[u8]) -> io::IoResult<()> { match (*self).write(b) { diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 643bc166c27..0d421760162 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -378,7 +378,7 @@ mod test { /// A type, free to create, primarily intended for benchmarking creation of /// wrappers that, just for construction, don't need a Reader/Writer that /// does anything useful. Is equivalent to `/dev/null` in semantics. - #[deriving(Clone,Eq,Ord)] + #[deriving(Clone,PartialEq,PartialOrd)] pub struct NullStream; impl Reader for NullStream { diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 4d02a470f30..78700d353af 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -285,7 +285,7 @@ pub type IoResult<T> = Result<T, IoError>; /// # FIXME /// /// Is something like this sufficient? It's kind of archaic -#[deriving(Eq, Clone)] +#[deriving(PartialEq, Clone)] pub struct IoError { /// An enumeration which can be matched against for determining the flavor /// of error. @@ -395,7 +395,7 @@ impl fmt::Show for IoError { } /// A list specifying general categories of I/O error. -#[deriving(Eq, Clone, Show)] +#[deriving(PartialEq, Clone, Show)] pub enum IoErrorKind { /// Any I/O error not part of this list. OtherIoError, @@ -1582,7 +1582,7 @@ pub enum FileAccess { } /// Different kinds of files which can be identified by a call to stat -#[deriving(Eq, Show, Hash)] +#[deriving(PartialEq, Show, Hash)] pub enum FileType { /// This is a normal file, corresponding to `S_IFREG` TypeFile, @@ -1726,7 +1726,7 @@ mod tests { use prelude::*; use uint; - #[deriving(Clone, Eq, Show)] + #[deriving(Clone, PartialEq, Show)] enum BadReaderBehavior { GoodBehavior(uint), BadBehavior(uint) diff --git a/src/libstd/io/net/ip.rs b/src/libstd/io/net/ip.rs index 5004e8a5a07..4d0e5e7f72d 100644 --- a/src/libstd/io/net/ip.rs +++ b/src/libstd/io/net/ip.rs @@ -25,7 +25,7 @@ use slice::{MutableCloneableVector, ImmutableVector, MutableVector}; pub type Port = u16; -#[deriving(Eq, TotalEq, Clone, Hash)] +#[deriving(PartialEq, TotalEq, Clone, Hash)] pub enum IpAddr { Ipv4Addr(u8, u8, u8, u8), Ipv6Addr(u16, u16, u16, u16, u16, u16, u16, u16) @@ -56,7 +56,7 @@ impl fmt::Show for IpAddr { } } -#[deriving(Eq, TotalEq, Clone, Hash)] +#[deriving(PartialEq, TotalEq, Clone, Hash)] pub struct SocketAddr { pub ip: IpAddr, pub port: Port, diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index 20d20a14f9a..8325ee4ccd9 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -317,7 +317,7 @@ impl fmt::Show for Command { } /// The output of a finished process. -#[deriving(Eq, TotalEq, Clone)] +#[deriving(PartialEq, TotalEq, Clone)] pub struct ProcessOutput { /// The status (exit code) of the process. pub status: ProcessExit, @@ -348,7 +348,7 @@ pub enum StdioContainer { /// Describes the result of a process after it has terminated. /// Note that Windows have no signals, so the result is usually ExitStatus. -#[deriving(Eq, TotalEq, Clone)] +#[deriving(PartialEq, TotalEq, Clone)] pub enum ProcessExit { /// Normal termination with an exit status. ExitStatus(int), diff --git a/src/libstd/io/signal.rs b/src/libstd/io/signal.rs index 4d294e84070..05392baff04 100644 --- a/src/libstd/io/signal.rs +++ b/src/libstd/io/signal.rs @@ -34,7 +34,7 @@ use vec::Vec; /// Signals that can be sent and received #[repr(int)] -#[deriving(Eq, Hash, Show)] +#[deriving(PartialEq, Hash, Show)] pub enum Signum { /// Equivalent to SIGBREAK, delivered when the user presses Ctrl-Break. Break = 21i, diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index b63ccbef55f..a67ed1c0b79 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -241,13 +241,6 @@ pub mod path; pub mod fmt; pub mod cleanup; -/* Unsupported interfaces */ - -#[unstable] -pub mod repr; -#[unstable] -pub mod reflect; - // Private APIs #[unstable] pub mod unstable; diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index 9700f8c9970..602a2240f39 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -702,7 +702,7 @@ mod tests { test_checked_next_power_of_two!(test_checked_next_power_of_two_u64, u64) test_checked_next_power_of_two!(test_checked_next_power_of_two_uint, uint) - #[deriving(Eq, Show)] + #[deriving(PartialEq, Show)] struct Value { x: int } impl ToPrimitive for Value { diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index 20f5927c9bd..54ca5797804 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -20,7 +20,7 @@ use num; use ops::{Add, Sub, Mul, Div, Rem, Neg}; use option::{None, Option, Some}; use slice::{ImmutableVector, MutableVector}; -use std::cmp::{Ord, Eq}; +use std::cmp::{PartialOrd, PartialEq}; use str::StrSlice; use string::String; use vec::Vec; @@ -259,7 +259,7 @@ pub fn int_to_str_bytes_common<T: Int>(num: T, radix: uint, sign: SignFormat, f: * between digit and exponent sign `'p'`. */ #[allow(deprecated)] -pub fn float_to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Float+ +pub fn float_to_str_bytes_common<T:NumCast+Zero+One+PartialEq+PartialOrd+Float+ Div<T,T>+Neg<T>+Rem<T,T>+Mul<T,T>>( num: T, radix: uint, negative_zero: bool, sign: SignFormat, digits: SignificantDigits, exp_format: ExponentFormat, exp_upper: bool @@ -492,7 +492,7 @@ pub fn float_to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Float+ * `to_str_bytes_common()`, for details see there. */ #[inline] -pub fn float_to_str_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Float+ +pub fn float_to_str_common<T:NumCast+Zero+One+PartialEq+PartialOrd+NumStrConv+Float+ Div<T,T>+Neg<T>+Rem<T,T>+Mul<T,T>>( num: T, radix: uint, negative_zero: bool, sign: SignFormat, digits: SignificantDigits, exp_format: ExponentFormat, exp_capital: bool @@ -547,7 +547,7 @@ static DIGIT_E_RADIX: uint = ('e' as uint) - ('a' as uint) + 11u; * - Fails if `radix` > 18 and `special == true` due to conflict * between digit and lowest first character in `inf` and `NaN`, the `'i'`. */ -pub fn from_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Div<T,T>+ +pub fn from_str_bytes_common<T:NumCast+Zero+One+PartialEq+PartialOrd+Div<T,T>+ Mul<T,T>+Sub<T,T>+Neg<T>+Add<T,T>+ NumStrConv+Clone>( buf: &[u8], radix: uint, negative: bool, fractional: bool, @@ -754,7 +754,7 @@ pub fn from_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Div<T,T>+ * `from_str_bytes_common()`, for details see there. */ #[inline] -pub fn from_str_common<T:NumCast+Zero+One+Eq+Ord+Div<T,T>+Mul<T,T>+ +pub fn from_str_common<T:NumCast+Zero+One+PartialEq+PartialOrd+Div<T,T>+Mul<T,T>+ Sub<T,T>+Neg<T>+Add<T,T>+NumStrConv+Clone>( buf: &str, radix: uint, negative: bool, fractional: bool, special: bool, exponent: ExponentFormat, empty_zero: bool, diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index c0c7a042f11..fbecbd7665b 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -13,7 +13,7 @@ use container::Container; use c_str::{CString, ToCStr}; use clone::Clone; -use cmp::{Eq, TotalEq}; +use cmp::{PartialEq, TotalEq}; use from_str::FromStr; use io::Writer; use iter::{DoubleEndedIterator, AdditiveIterator, Extendable, Iterator, Map}; @@ -58,7 +58,7 @@ pub fn is_sep(c: char) -> bool { c == SEP } -impl Eq for Path { +impl PartialEq for Path { #[inline] fn eq(&self, other: &Path) -> bool { self.repr == other.repr diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 88c3e9def8c..d46a373de4d 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -13,7 +13,7 @@ use ascii::AsciiCast; use c_str::{CString, ToCStr}; use clone::Clone; -use cmp::{Eq, TotalEq}; +use cmp::{PartialEq, TotalEq}; use container::Container; use from_str::FromStr; use io::Writer; @@ -79,7 +79,7 @@ pub struct Path { sepidx: Option<uint> // index of the final separator in the non-prefix portion of repr } -impl Eq for Path { +impl PartialEq for Path { #[inline] fn eq(&self, other: &Path) -> bool { self.repr == other.repr @@ -956,7 +956,7 @@ pub fn is_sep_byte_verbatim(u: &u8) -> bool { } /// Prefix types for Path -#[deriving(Eq, Clone)] +#[deriving(PartialEq, Clone)] pub enum PathPrefix { /// Prefix `\\?\`, uint is the length of the following component VerbatimPrefix(uint), diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index 07aaeac64be..ac1aaa2c6ca 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -58,7 +58,7 @@ #[doc(no_inline)] pub use c_str::ToCStr; #[doc(no_inline)] pub use char::Char; #[doc(no_inline)] pub use clone::Clone; -#[doc(no_inline)] pub use cmp::{Eq, Ord, TotalEq, TotalOrd}; +#[doc(no_inline)] pub use cmp::{PartialEq, PartialOrd, TotalEq, TotalOrd}; #[doc(no_inline)] pub use cmp::{Ordering, Less, Equal, Greater, Equiv}; #[doc(no_inline)] pub use container::{Container, Mutable, Map, MutableMap}; #[doc(no_inline)] pub use container::{Set, MutableSet}; diff --git a/src/libstd/reflect.rs b/src/libstd/reflect.rs deleted file mode 100644 index f21dcdf2a46..00000000000 --- a/src/libstd/reflect.rs +++ /dev/null @@ -1,439 +0,0 @@ -// 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. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -/*! - -Runtime type reflection - -*/ - -#![allow(missing_doc)] - -use intrinsics::{Disr, Opaque, TyDesc, TyVisitor}; -use mem; -use owned::Box; - -/** - * Trait for visitor that wishes to reflect on data. To use this, create a - * struct that encapsulates the set of pointers you wish to walk through a - * data structure, and implement both `MovePtr` for it as well as `TyVisitor`; - * then build a MovePtrAdaptor wrapped around your struct. - */ -pub trait MovePtr { - fn move_ptr(&mut self, adjustment: |*u8| -> *u8); - fn push_ptr(&mut self); - fn pop_ptr(&mut self); -} - -/// Helper function for alignment calculation. -#[inline] -pub fn align(size: uint, align: uint) -> uint { - ((size + align) - 1u) & !(align - 1u) -} - -/// Adaptor to wrap around visitors implementing MovePtr. -pub struct MovePtrAdaptor<V> { - inner: V -} - -impl<V:TyVisitor + MovePtr> MovePtrAdaptor<V> { - pub fn new(v: V) -> MovePtrAdaptor<V> { - MovePtrAdaptor { inner: v } - } - - #[inline] - pub fn bump(&mut self, sz: uint) { - self.inner.move_ptr(|p| ((p as uint) + sz) as *u8) - } - - #[inline] - pub fn align(&mut self, a: uint) { - self.inner.move_ptr(|p| align(p as uint, a) as *u8) - } - - #[inline] - pub fn align_to<T>(&mut self) { - self.align(mem::min_align_of::<T>()); - } - - #[inline] - pub fn bump_past<T>(&mut self) { - self.bump(mem::size_of::<T>()); - } - - pub fn unwrap(self) -> V { self.inner } -} - -/// Abstract type-directed pointer-movement using the MovePtr trait -impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> { - fn visit_bot(&mut self) -> bool { - self.align_to::<()>(); - if ! self.inner.visit_bot() { return false; } - self.bump_past::<()>(); - true - } - - fn visit_nil(&mut self) -> bool { - self.align_to::<()>(); - if ! self.inner.visit_nil() { return false; } - self.bump_past::<()>(); - true - } - - fn visit_bool(&mut self) -> bool { - self.align_to::<bool>(); - if ! self.inner.visit_bool() { return false; } - self.bump_past::<bool>(); - true - } - - fn visit_int(&mut self) -> bool { - self.align_to::<int>(); - if ! self.inner.visit_int() { return false; } - self.bump_past::<int>(); - true - } - - fn visit_i8(&mut self) -> bool { - self.align_to::<i8>(); - if ! self.inner.visit_i8() { return false; } - self.bump_past::<i8>(); - true - } - - fn visit_i16(&mut self) -> bool { - self.align_to::<i16>(); - if ! self.inner.visit_i16() { return false; } - self.bump_past::<i16>(); - true - } - - fn visit_i32(&mut self) -> bool { - self.align_to::<i32>(); - if ! self.inner.visit_i32() { return false; } - self.bump_past::<i32>(); - true - } - - fn visit_i64(&mut self) -> bool { - self.align_to::<i64>(); - if ! self.inner.visit_i64() { return false; } - self.bump_past::<i64>(); - true - } - - fn visit_uint(&mut self) -> bool { - self.align_to::<uint>(); - if ! self.inner.visit_uint() { return false; } - self.bump_past::<uint>(); - true - } - - fn visit_u8(&mut self) -> bool { - self.align_to::<u8>(); - if ! self.inner.visit_u8() { return false; } - self.bump_past::<u8>(); - true - } - - fn visit_u16(&mut self) -> bool { - self.align_to::<u16>(); - if ! self.inner.visit_u16() { return false; } - self.bump_past::<u16>(); - true - } - - fn visit_u32(&mut self) -> bool { - self.align_to::<u32>(); - if ! self.inner.visit_u32() { return false; } - self.bump_past::<u32>(); - true - } - - fn visit_u64(&mut self) -> bool { - self.align_to::<u64>(); - if ! self.inner.visit_u64() { return false; } - self.bump_past::<u64>(); - true - } - - fn visit_f32(&mut self) -> bool { - self.align_to::<f32>(); - if ! self.inner.visit_f32() { return false; } - self.bump_past::<f32>(); - true - } - - fn visit_f64(&mut self) -> bool { - self.align_to::<f64>(); - if ! self.inner.visit_f64() { return false; } - self.bump_past::<f64>(); - true - } - - fn visit_f128(&mut self) -> bool { - self.align_to::<f128>(); - if ! self.inner.visit_f128() { return false; } - self.bump_past::<f128>(); - true - } - - fn visit_char(&mut self) -> bool { - self.align_to::<char>(); - if ! self.inner.visit_char() { return false; } - self.bump_past::<char>(); - true - } - - fn visit_estr_box(&mut self) -> bool { - true - } - - fn visit_estr_uniq(&mut self) -> bool { - self.align_to::<~str>(); - if ! self.inner.visit_estr_uniq() { return false; } - self.bump_past::<~str>(); - true - } - - fn visit_estr_slice(&mut self) -> bool { - self.align_to::<&'static str>(); - if ! self.inner.visit_estr_slice() { return false; } - self.bump_past::<&'static str>(); - true - } - - fn visit_estr_fixed(&mut self, n: uint, - sz: uint, - align: uint) -> bool { - self.align(align); - if ! self.inner.visit_estr_fixed(n, sz, align) { return false; } - self.bump(sz); - true - } - - fn visit_box(&mut self, mtbl: uint, inner: *TyDesc) -> bool { - self.align_to::<@u8>(); - if ! self.inner.visit_box(mtbl, inner) { return false; } - self.bump_past::<@u8>(); - true - } - - fn visit_uniq(&mut self, mtbl: uint, inner: *TyDesc) -> bool { - self.align_to::<Box<u8>>(); - if ! self.inner.visit_uniq(mtbl, inner) { return false; } - self.bump_past::<Box<u8>>(); - true - } - - fn visit_ptr(&mut self, mtbl: uint, inner: *TyDesc) -> bool { - self.align_to::<*u8>(); - if ! self.inner.visit_ptr(mtbl, inner) { return false; } - self.bump_past::<*u8>(); - true - } - - fn visit_rptr(&mut self, mtbl: uint, inner: *TyDesc) -> bool { - self.align_to::<&'static u8>(); - if ! self.inner.visit_rptr(mtbl, inner) { return false; } - self.bump_past::<&'static u8>(); - true - } - - fn visit_evec_box(&mut self, _mtbl: uint, _inner: *TyDesc) -> bool { - true - } - - fn visit_evec_uniq(&mut self, mtbl: uint, inner: *TyDesc) -> bool { - self.align_to::<~[u8]>(); - if ! self.inner.visit_evec_uniq(mtbl, inner) { return false; } - self.bump_past::<~[u8]>(); - true - } - - fn visit_evec_slice(&mut self, mtbl: uint, inner: *TyDesc) -> bool { - self.align_to::<&'static [u8]>(); - if ! self.inner.visit_evec_slice(mtbl, inner) { return false; } - self.bump_past::<&'static [u8]>(); - true - } - - fn visit_evec_fixed(&mut self, n: uint, sz: uint, align: uint, - mtbl: uint, inner: *TyDesc) -> bool { - self.align(align); - if ! self.inner.visit_evec_fixed(n, sz, align, mtbl, inner) { - return false; - } - self.bump(sz); - true - } - - fn visit_enter_rec(&mut self, n_fields: uint, sz: uint, align: uint) -> bool { - self.align(align); - if ! self.inner.visit_enter_rec(n_fields, sz, align) { return false; } - true - } - - fn visit_rec_field(&mut self, i: uint, name: &str, - mtbl: uint, inner: *TyDesc) -> bool { - unsafe { self.align((*inner).align); } - if ! self.inner.visit_rec_field(i, name, mtbl, inner) { - return false; - } - unsafe { self.bump((*inner).size); } - true - } - - fn visit_leave_rec(&mut self, n_fields: uint, sz: uint, align: uint) -> bool { - if ! self.inner.visit_leave_rec(n_fields, sz, align) { return false; } - true - } - - fn visit_enter_class(&mut self, name: &str, named_fields: bool, n_fields: uint, sz: uint, - align: uint) -> bool { - self.align(align); - if ! self.inner.visit_enter_class(name, named_fields, n_fields, sz, align) { - return false; - } - true - } - - fn visit_class_field(&mut self, i: uint, name: &str, named: bool, mtbl: uint, - inner: *TyDesc) -> bool { - unsafe { self.align((*inner).align); } - if ! self.inner.visit_class_field(i, name, named, mtbl, inner) { - return false; - } - unsafe { self.bump((*inner).size); } - true - } - - fn visit_leave_class(&mut self, name: &str, named_fields: bool, n_fields: uint, sz: uint, - align: uint) -> bool { - if ! self.inner.visit_leave_class(name, named_fields, n_fields, sz, align) { - return false; - } - true - } - - fn visit_enter_tup(&mut self, n_fields: uint, sz: uint, align: uint) -> bool { - self.align(align); - if ! self.inner.visit_enter_tup(n_fields, sz, align) { return false; } - true - } - - fn visit_tup_field(&mut self, i: uint, inner: *TyDesc) -> bool { - unsafe { self.align((*inner).align); } - if ! self.inner.visit_tup_field(i, inner) { return false; } - unsafe { self.bump((*inner).size); } - true - } - - fn visit_leave_tup(&mut self, n_fields: uint, sz: uint, align: uint) -> bool { - if ! self.inner.visit_leave_tup(n_fields, sz, align) { return false; } - true - } - - fn visit_enter_fn(&mut self, purity: uint, proto: uint, - n_inputs: uint, retstyle: uint) -> bool { - if ! self.inner.visit_enter_fn(purity, proto, n_inputs, retstyle) { - return false - } - true - } - - fn visit_fn_input(&mut self, i: uint, mode: uint, inner: *TyDesc) -> bool { - if ! self.inner.visit_fn_input(i, mode, inner) { return false; } - true - } - - fn visit_fn_output(&mut self, retstyle: uint, variadic: bool, inner: *TyDesc) -> bool { - if ! self.inner.visit_fn_output(retstyle, variadic, inner) { return false; } - true - } - - fn visit_leave_fn(&mut self, purity: uint, proto: uint, - n_inputs: uint, retstyle: uint) -> bool { - if ! self.inner.visit_leave_fn(purity, proto, n_inputs, retstyle) { - return false; - } - true - } - - fn visit_enter_enum(&mut self, n_variants: uint, - get_disr: unsafe extern fn(ptr: *Opaque) -> Disr, - sz: uint, align: uint) - -> bool { - self.align(align); - if ! self.inner.visit_enter_enum(n_variants, get_disr, sz, align) { - return false; - } - true - } - - fn visit_enter_enum_variant(&mut self, variant: uint, - disr_val: Disr, - n_fields: uint, - name: &str) -> bool { - if ! self.inner.visit_enter_enum_variant(variant, disr_val, - n_fields, name) { - return false; - } - true - } - - fn visit_enum_variant_field(&mut self, i: uint, offset: uint, inner: *TyDesc) -> bool { - self.inner.push_ptr(); - self.bump(offset); - if ! self.inner.visit_enum_variant_field(i, offset, inner) { return false; } - self.inner.pop_ptr(); - true - } - - fn visit_leave_enum_variant(&mut self, variant: uint, - disr_val: Disr, - n_fields: uint, - name: &str) -> bool { - if ! self.inner.visit_leave_enum_variant(variant, disr_val, - n_fields, name) { - return false; - } - true - } - - fn visit_leave_enum(&mut self, n_variants: uint, - get_disr: unsafe extern fn(ptr: *Opaque) -> Disr, - sz: uint, align: uint) -> bool { - if ! self.inner.visit_leave_enum(n_variants, get_disr, sz, align) { - return false; - } - self.bump(sz); - true - } - - fn visit_trait(&mut self, name: &str) -> bool { - self.align_to::<Box<TyVisitor>>(); - if ! self.inner.visit_trait(name) { return false; } - self.bump_past::<Box<TyVisitor>>(); - true - } - - fn visit_param(&mut self, i: uint) -> bool { - if ! self.inner.visit_param(i) { return false; } - true - } - - fn visit_self(&mut self) -> bool { - self.align_to::<&'static u8>(); - if ! self.inner.visit_self() { return false; } - self.align_to::<&'static u8>(); - true - } -} diff --git a/src/libstd/repr.rs b/src/libstd/repr.rs deleted file mode 100644 index 0621cbf35fe..00000000000 --- a/src/libstd/repr.rs +++ /dev/null @@ -1,663 +0,0 @@ -// 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. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -/*! - -More runtime type reflection - -*/ - -#![allow(missing_doc)] - -use char; -use container::Container; -use intrinsics::{Disr, Opaque, TyDesc, TyVisitor, get_tydesc, visit_tydesc}; -use io; -use iter::Iterator; -use mem::transmute; -use option::{Some, None, Option}; -use ptr::RawPtr; -use raw; -use reflect::{MovePtr, align}; -use reflect; -use result::{Ok, Err}; -use slice::Vector; -use str::{Str, StrSlice}; -use string::String; -use to_str::ToStr; -use vec::Vec; - -macro_rules! try( ($me:expr, $e:expr) => ( - match $e { - Ok(()) => {}, - Err(e) => { $me.last_err = Some(e); return false; } - } -) ) - -/// Representations - -trait Repr { - fn write_repr(&self, writer: &mut io::Writer) -> io::IoResult<()>; -} - -impl Repr for () { - fn write_repr(&self, writer: &mut io::Writer) -> io::IoResult<()> { - writer.write("()".as_bytes()) - } -} - -impl Repr for bool { - fn write_repr(&self, writer: &mut io::Writer) -> io::IoResult<()> { - let s = if *self { "true" } else { "false" }; - writer.write(s.as_bytes()) - } -} - -impl Repr for int { - fn write_repr(&self, writer: &mut io::Writer) -> io::IoResult<()> { - write!(writer, "{}", *self) - } -} - -macro_rules! int_repr(($ty:ident, $suffix:expr) => (impl Repr for $ty { - fn write_repr(&self, writer: &mut io::Writer) -> io::IoResult<()> { - write!(writer, "{}{}", *self, $suffix) - } -})) - -int_repr!(i8, "i8") -int_repr!(i16, "i16") -int_repr!(i32, "i32") -int_repr!(i64, "i64") -int_repr!(uint, "u") -int_repr!(u8, "u8") -int_repr!(u16, "u16") -int_repr!(u32, "u32") -int_repr!(u64, "u64") - -macro_rules! num_repr(($ty:ident, $suffix:expr) => (impl Repr for $ty { - fn write_repr(&self, writer: &mut io::Writer) -> io::IoResult<()> { - let s = self.to_str(); - writer.write(s.as_bytes()).and_then(|()| { - writer.write(bytes!($suffix)) - }) - } -})) - -num_repr!(f32, "f32") -num_repr!(f64, "f64") - -// New implementation using reflect::MovePtr - -enum VariantState { - SearchingFor(Disr), - Matched, - AlreadyFound -} - -pub struct ReprVisitor<'a> { - ptr: *u8, - ptr_stk: Vec<*u8>, - var_stk: Vec<VariantState>, - writer: &'a mut io::Writer, - last_err: Option<io::IoError>, -} - -impl<'a> MovePtr for ReprVisitor<'a> { - #[inline] - fn move_ptr(&mut self, adjustment: |*u8| -> *u8) { - self.ptr = adjustment(self.ptr); - } - fn push_ptr(&mut self) { - self.ptr_stk.push(self.ptr); - } - fn pop_ptr(&mut self) { - self.ptr = self.ptr_stk.pop().unwrap(); - } -} - -impl<'a> ReprVisitor<'a> { - // Various helpers for the TyVisitor impl - pub fn new(ptr: *u8, writer: &'a mut io::Writer) -> ReprVisitor<'a> { - ReprVisitor { - ptr: ptr, - ptr_stk: vec!(), - var_stk: vec!(), - writer: writer, - last_err: None, - } - } - - #[inline] - pub fn get<T>(&mut self, f: |&mut ReprVisitor, &T| -> bool) -> bool { - unsafe { - f(self, transmute::<*u8,&T>(self.ptr)) - } - } - - #[inline] - pub fn visit_inner(&mut self, inner: *TyDesc) -> bool { - self.visit_ptr_inner(self.ptr, inner) - } - - #[inline] - pub fn visit_ptr_inner(&mut self, ptr: *u8, inner: *TyDesc) -> bool { - unsafe { - let u = ReprVisitor::new(ptr, ::mem::transmute_copy(&self.writer)); - let mut v = reflect::MovePtrAdaptor::new(u); - // Obviously this should not be a thing, but blame #8401 for now - visit_tydesc(inner, &mut v as &mut TyVisitor); - match v.unwrap().last_err { - Some(e) => { - self.last_err = Some(e); - false - } - None => true, - } - } - } - - #[inline] - pub fn write<T:Repr>(&mut self) -> bool { - self.get(|this, v:&T| { - try!(this, v.write_repr(this.writer)); - true - }) - } - - pub fn write_escaped_slice(&mut self, slice: &str) -> bool { - try!(self, self.writer.write(['"' as u8])); - for ch in slice.chars() { - if !self.write_escaped_char(ch, true) { return false } - } - try!(self, self.writer.write(['"' as u8])); - true - } - - pub fn write_mut_qualifier(&mut self, mtbl: uint) -> bool { - if mtbl == 0 { - try!(self, self.writer.write("mut ".as_bytes())); - } else if mtbl == 1 { - // skip, this is ast::m_imm - } else { - fail!("invalid mutability value"); - } - true - } - - pub fn write_vec_range(&mut self, ptr: *(), len: uint, inner: *TyDesc) -> bool { - let mut p = ptr as *u8; - let (sz, al) = unsafe { ((*inner).size, (*inner).align) }; - try!(self, self.writer.write(['[' as u8])); - let mut first = true; - let mut left = len; - // unit structs have 0 size, and don't loop forever. - let dec = if sz == 0 {1} else {sz}; - while left > 0 { - if first { - first = false; - } else { - try!(self, self.writer.write(", ".as_bytes())); - } - self.visit_ptr_inner(p as *u8, inner); - p = align(unsafe { p.offset(sz as int) as uint }, al) as *u8; - left -= dec; - } - try!(self, self.writer.write([']' as u8])); - true - } - - pub fn write_unboxed_vec_repr(&mut self, _: uint, v: &raw::Vec<()>, inner: *TyDesc) -> bool { - self.write_vec_range(&v.data, v.fill, inner) - } - - fn write_escaped_char(&mut self, ch: char, is_str: bool) -> bool { - try!(self, match ch { - '\t' => self.writer.write("\\t".as_bytes()), - '\r' => self.writer.write("\\r".as_bytes()), - '\n' => self.writer.write("\\n".as_bytes()), - '\\' => self.writer.write("\\\\".as_bytes()), - '\'' => { - if is_str { - self.writer.write("'".as_bytes()) - } else { - self.writer.write("\\'".as_bytes()) - } - } - '"' => { - if is_str { - self.writer.write("\\\"".as_bytes()) - } else { - self.writer.write("\"".as_bytes()) - } - } - '\x20'..'\x7e' => self.writer.write([ch as u8]), - _ => { - char::escape_unicode(ch, |c| { - let _ = self.writer.write([c as u8]); - }); - Ok(()) - } - }); - return true; - } -} - -impl<'a> TyVisitor for ReprVisitor<'a> { - fn visit_bot(&mut self) -> bool { - try!(self, self.writer.write("!".as_bytes())); - true - } - fn visit_nil(&mut self) -> bool { self.write::<()>() } - fn visit_bool(&mut self) -> bool { self.write::<bool>() } - fn visit_int(&mut self) -> bool { self.write::<int>() } - fn visit_i8(&mut self) -> bool { self.write::<i8>() } - fn visit_i16(&mut self) -> bool { self.write::<i16>() } - fn visit_i32(&mut self) -> bool { self.write::<i32>() } - fn visit_i64(&mut self) -> bool { self.write::<i64>() } - - fn visit_uint(&mut self) -> bool { self.write::<uint>() } - fn visit_u8(&mut self) -> bool { self.write::<u8>() } - fn visit_u16(&mut self) -> bool { self.write::<u16>() } - fn visit_u32(&mut self) -> bool { self.write::<u32>() } - fn visit_u64(&mut self) -> bool { self.write::<u64>() } - - fn visit_f32(&mut self) -> bool { self.write::<f32>() } - fn visit_f64(&mut self) -> bool { self.write::<f64>() } - fn visit_f128(&mut self) -> bool { fail!("not implemented") } - - fn visit_char(&mut self) -> bool { - self.get::<char>(|this, &ch| { - try!(this, this.writer.write(['\'' as u8])); - if !this.write_escaped_char(ch, false) { return false } - try!(this, this.writer.write(['\'' as u8])); - true - }) - } - - fn visit_estr_box(&mut self) -> bool { - true - } - - fn visit_estr_uniq(&mut self) -> bool { - true - } - - fn visit_estr_slice(&mut self) -> bool { - self.get::<&str>(|this, s| this.write_escaped_slice(*s)) - } - - // Type no longer exists, vestigial function. - fn visit_estr_fixed(&mut self, _n: uint, _sz: uint, - _align: uint) -> bool { fail!(); } - - fn visit_box(&mut self, mtbl: uint, inner: *TyDesc) -> bool { - try!(self, self.writer.write(['@' as u8])); - self.write_mut_qualifier(mtbl); - self.get::<&raw::Box<()>>(|this, b| { - let p = &b.data as *() as *u8; - this.visit_ptr_inner(p, inner) - }) - } - - fn visit_uniq(&mut self, _mtbl: uint, inner: *TyDesc) -> bool { - try!(self, self.writer.write("box ".as_bytes())); - self.get::<*u8>(|this, b| { - this.visit_ptr_inner(*b, inner) - }) - } - - fn visit_ptr(&mut self, mtbl: uint, _inner: *TyDesc) -> bool { - self.get::<*u8>(|this, p| { - try!(this, write!(this.writer, "({} as *", *p)); - this.write_mut_qualifier(mtbl); - try!(this, this.writer.write("())".as_bytes())); - true - }) - } - - fn visit_rptr(&mut self, mtbl: uint, inner: *TyDesc) -> bool { - try!(self, self.writer.write(['&' as u8])); - self.write_mut_qualifier(mtbl); - self.get::<*u8>(|this, p| { - this.visit_ptr_inner(*p, inner) - }) - } - - fn visit_evec_box(&mut self, mtbl: uint, inner: *TyDesc) -> bool { - self.get::<&raw::Box<raw::Vec<()>>>(|this, b| { - try!(this, this.writer.write(['@' as u8])); - this.write_mut_qualifier(mtbl); - this.write_unboxed_vec_repr(mtbl, &b.data, inner) - }) - } - - fn visit_evec_uniq(&mut self, mtbl: uint, inner: *TyDesc) -> bool { - self.get::<&raw::Vec<()>>(|this, b| { - try!(this, this.writer.write("box ".as_bytes())); - this.write_unboxed_vec_repr(mtbl, *b, inner) - }) - } - - fn visit_evec_slice(&mut self, mtbl: uint, inner: *TyDesc) -> bool { - self.get::<raw::Slice<()>>(|this, s| { - try!(this, this.writer.write(['&' as u8])); - this.write_mut_qualifier(mtbl); - let size = unsafe { - if (*inner).size == 0 { 1 } else { (*inner).size } - }; - this.write_vec_range(s.data, s.len * size, inner) - }) - } - - fn visit_evec_fixed(&mut self, n: uint, sz: uint, _align: uint, - _: uint, inner: *TyDesc) -> bool { - let assumed_size = if sz == 0 { n } else { sz }; - self.get::<()>(|this, b| { - this.write_vec_range(b, assumed_size, inner) - }) - } - - fn visit_enter_rec(&mut self, _n_fields: uint, - _sz: uint, _align: uint) -> bool { - try!(self, self.writer.write(['{' as u8])); - true - } - - fn visit_rec_field(&mut self, i: uint, name: &str, - mtbl: uint, inner: *TyDesc) -> bool { - if i != 0 { - try!(self, self.writer.write(", ".as_bytes())); - } - self.write_mut_qualifier(mtbl); - try!(self, self.writer.write(name.as_bytes())); - try!(self, self.writer.write(": ".as_bytes())); - self.visit_inner(inner); - true - } - - fn visit_leave_rec(&mut self, _n_fields: uint, - _sz: uint, _align: uint) -> bool { - try!(self, self.writer.write(['}' as u8])); - true - } - - fn visit_enter_class(&mut self, name: &str, named_fields: bool, n_fields: uint, - _sz: uint, _align: uint) -> bool { - try!(self, self.writer.write(name.as_bytes())); - if n_fields != 0 { - if named_fields { - try!(self, self.writer.write(['{' as u8])); - } else { - try!(self, self.writer.write(['(' as u8])); - } - } - true - } - - fn visit_class_field(&mut self, i: uint, name: &str, named: bool, - _mtbl: uint, inner: *TyDesc) -> bool { - if i != 0 { - try!(self, self.writer.write(", ".as_bytes())); - } - if named { - try!(self, self.writer.write(name.as_bytes())); - try!(self, self.writer.write(": ".as_bytes())); - } - self.visit_inner(inner); - true - } - - fn visit_leave_class(&mut self, _name: &str, named_fields: bool, n_fields: uint, - _sz: uint, _align: uint) -> bool { - if n_fields != 0 { - if named_fields { - try!(self, self.writer.write(['}' as u8])); - } else { - try!(self, self.writer.write([')' as u8])); - } - } - true - } - - fn visit_enter_tup(&mut self, _n_fields: uint, - _sz: uint, _align: uint) -> bool { - try!(self, self.writer.write(['(' as u8])); - true - } - - fn visit_tup_field(&mut self, i: uint, inner: *TyDesc) -> bool { - if i != 0 { - try!(self, self.writer.write(", ".as_bytes())); - } - self.visit_inner(inner); - true - } - - fn visit_leave_tup(&mut self, _n_fields: uint, - _sz: uint, _align: uint) -> bool { - if _n_fields == 1 { - try!(self, self.writer.write([',' as u8])); - } - try!(self, self.writer.write([')' as u8])); - true - } - - fn visit_enter_enum(&mut self, - _n_variants: uint, - get_disr: unsafe extern fn(ptr: *Opaque) -> Disr, - _sz: uint, - _align: uint) -> bool { - let disr = unsafe { - get_disr(transmute(self.ptr)) - }; - self.var_stk.push(SearchingFor(disr)); - true - } - - fn visit_enter_enum_variant(&mut self, _variant: uint, - disr_val: Disr, - n_fields: uint, - name: &str) -> bool { - let mut write = false; - match self.var_stk.pop().unwrap() { - SearchingFor(sought) => { - if disr_val == sought { - self.var_stk.push(Matched); - write = true; - } else { - self.var_stk.push(SearchingFor(sought)); - } - } - Matched | AlreadyFound => { - self.var_stk.push(AlreadyFound); - } - } - - if write { - try!(self, self.writer.write(name.as_bytes())); - if n_fields > 0 { - try!(self, self.writer.write(['(' as u8])); - } - } - true - } - - fn visit_enum_variant_field(&mut self, - i: uint, - _offset: uint, - inner: *TyDesc) - -> bool { - match *self.var_stk.get(self.var_stk.len() - 1) { - Matched => { - if i != 0 { - try!(self, self.writer.write(", ".as_bytes())); - } - if ! self.visit_inner(inner) { - return false; - } - } - _ => () - } - true - } - - fn visit_leave_enum_variant(&mut self, _variant: uint, - _disr_val: Disr, - n_fields: uint, - _name: &str) -> bool { - match *self.var_stk.get(self.var_stk.len() - 1) { - Matched => { - if n_fields > 0 { - try!(self, self.writer.write([')' as u8])); - } - } - _ => () - } - true - } - - fn visit_leave_enum(&mut self, - _n_variants: uint, - _get_disr: unsafe extern fn(ptr: *Opaque) -> Disr, - _sz: uint, - _align: uint) - -> bool { - match self.var_stk.pop().unwrap() { - SearchingFor(..) => fail!("enum value matched no variant"), - _ => true - } - } - - fn visit_enter_fn(&mut self, _purity: uint, _proto: uint, - _n_inputs: uint, _retstyle: uint) -> bool { - try!(self, self.writer.write("fn(".as_bytes())); - true - } - - fn visit_fn_input(&mut self, i: uint, _mode: uint, inner: *TyDesc) -> bool { - if i != 0 { - try!(self, self.writer.write(", ".as_bytes())); - } - let name = unsafe { (*inner).name }; - try!(self, self.writer.write(name.as_bytes())); - true - } - - fn visit_fn_output(&mut self, _retstyle: uint, variadic: bool, - inner: *TyDesc) -> bool { - if variadic { - try!(self, self.writer.write(", ...".as_bytes())); - } - try!(self, self.writer.write(")".as_bytes())); - let name = unsafe { (*inner).name }; - if name != "()" { - try!(self, self.writer.write(" -> ".as_bytes())); - try!(self, self.writer.write(name.as_bytes())); - } - true - } - - fn visit_leave_fn(&mut self, _purity: uint, _proto: uint, - _n_inputs: uint, _retstyle: uint) -> bool { true } - - - fn visit_trait(&mut self, name: &str) -> bool { - try!(self, self.writer.write(name.as_bytes())); - true - } - - fn visit_param(&mut self, _i: uint) -> bool { true } - fn visit_self(&mut self) -> bool { true } -} - -pub fn write_repr<T>(writer: &mut io::Writer, object: &T) -> io::IoResult<()> { - unsafe { - let ptr = object as *T as *u8; - let tydesc = get_tydesc::<T>(); - let u = ReprVisitor::new(ptr, writer); - let mut v = reflect::MovePtrAdaptor::new(u); - visit_tydesc(tydesc, &mut v as &mut TyVisitor); - match v.unwrap().last_err { - Some(e) => Err(e), - None => Ok(()), - } - } -} - -pub fn repr_to_str<T>(t: &T) -> String { - use str; - use str::StrAllocating; - use io; - - let mut result = io::MemWriter::new(); - write_repr(&mut result as &mut io::Writer, t).unwrap(); - str::from_utf8(result.unwrap().as_slice()).unwrap().to_string() -} - -#[cfg(test)] -struct P {a: int, b: f64} - -#[test] -fn test_repr() { - use prelude::*; - use str; - use str::Str; - use io::stdio::println; - use char::is_alphabetic; - use mem::swap; - - fn exact_test<T>(t: &T, e:&str) { - let mut m = io::MemWriter::new(); - write_repr(&mut m as &mut io::Writer, t).unwrap(); - let s = str::from_utf8(m.unwrap().as_slice()).unwrap().to_owned(); - assert_eq!(s.as_slice(), e); - } - - exact_test(&10, "10"); - exact_test(&true, "true"); - exact_test(&false, "false"); - exact_test(&1.234, "1.234f64"); - exact_test(&("hello"), "\"hello\""); - - exact_test(&(@10), "@10"); - exact_test(&(box 10), "box 10"); - exact_test(&(&10), "&10"); - let mut x = 10; - exact_test(&(&mut x), "&mut 10"); - - exact_test(&(0 as *()), "(0x0 as *())"); - exact_test(&(0 as *mut ()), "(0x0 as *mut ())"); - - exact_test(&(1,), "(1,)"); - exact_test(&(&["hi", "there"]), - "&[\"hi\", \"there\"]"); - exact_test(&(P{a:10, b:1.234}), - "repr::P{a: 10, b: 1.234f64}"); - exact_test(&(@P{a:10, b:1.234}), - "@repr::P{a: 10, b: 1.234f64}"); - exact_test(&(box P{a:10, b:1.234}), - "box repr::P{a: 10, b: 1.234f64}"); - - exact_test(&(&[1, 2]), "&[1, 2]"); - exact_test(&(&mut [1, 2]), "&mut [1, 2]"); - - exact_test(&'\'', "'\\''"); - exact_test(&'"', "'\"'"); - exact_test(&("'"), "\"'\""); - exact_test(&("\""), "\"\\\"\""); - - exact_test(&println, "fn(&str)"); - exact_test(&swap::<int>, "fn(&mut int, &mut int)"); - exact_test(&is_alphabetic, "fn(char) -> bool"); - - struct Bar(int, int); - exact_test(&(Bar(2, 2)), "repr::test_repr::Bar(2, 2)"); -} diff --git a/src/libstd/rt/stack.rs b/src/libstd/rt/stack.rs index b3be742e1ed..dc6ab494d64 100644 --- a/src/libstd/rt/stack.rs +++ b/src/libstd/rt/stack.rs @@ -30,7 +30,7 @@ pub static RED_ZONE: uint = 20 * 1024; /// stacks are currently not enabled as segmented stacks, but rather one giant /// stack segment. This means that whenever we run out of stack, we want to /// truly consider it to be stack overflow rather than allocating a new stack. -#[cfg(not(test), not(stage0))] // in testing, use the original libstd's version +#[cfg(not(test))] // in testing, use the original libstd's version #[lang = "stack_exhausted"] extern fn stack_exhausted() { use option::{Option, None, Some}; @@ -103,35 +103,6 @@ extern fn stack_exhausted() { } } -#[no_mangle] // - this is called from C code -#[no_split_stack] // - it would be sad for this function to trigger __morestack -#[doc(hidden)] // - Function must be `pub` to get exported, but it's - // irrelevant for documentation purposes. -#[cfg(stage0, not(test))] // in testing, use the original libstd's version -pub extern "C" fn rust_stack_exhausted() { - use option::{Option, None, Some}; - use owned::Box; - use rt::local::Local; - use rt::task::Task; - use str::Str; - use intrinsics; - - unsafe { - let limit = get_sp_limit(); - record_sp_limit(limit - RED_ZONE / 2); - let task: Option<Box<Task>> = Local::try_take(); - let name = match task { - Some(ref task) => { - task.name.as_ref().map(|n| n.as_slice()) - } - None => None - }; - let name = name.unwrap_or("<unknown>"); - rterrln!("task '{}' has overflowed its stack", name); - intrinsics::abort(); - } -} - #[inline(always)] pub unsafe fn record_stack_bounds(stack_lo: uint, stack_hi: uint) { // When the old runtime had segmented stacks, it used a calculation that was diff --git a/src/libstd/rt/unwind.rs b/src/libstd/rt/unwind.rs index f34dcaaa427..dc2646102d2 100644 --- a/src/libstd/rt/unwind.rs +++ b/src/libstd/rt/unwind.rs @@ -213,7 +213,6 @@ pub mod eabi { } #[lang="eh_personality"] - #[cfg(not(stage0))] extern fn eh_personality( version: c_int, actions: uw::_Unwind_Action, @@ -227,22 +226,6 @@ pub mod eabi { context) } } - #[lang="eh_personality"] - #[no_mangle] // so we can reference it by name from middle/trans/base.rs - #[cfg(stage0)] - pub extern "C" fn rust_eh_personality( - version: c_int, - actions: uw::_Unwind_Action, - exception_class: uw::_Unwind_Exception_Class, - ue_header: *uw::_Unwind_Exception, - context: *uw::_Unwind_Context - ) -> uw::_Unwind_Reason_Code - { - unsafe { - __gcc_personality_v0(version, actions, exception_class, ue_header, - context) - } - } #[no_mangle] // referenced from rust_try.ll pub extern "C" fn rust_eh_personality_catch( @@ -281,7 +264,6 @@ pub mod eabi { } #[lang="eh_personality"] - #[cfg(not(stage0))] extern "C" fn eh_personality( state: uw::_Unwind_State, ue_header: *uw::_Unwind_Exception, @@ -293,20 +275,6 @@ pub mod eabi { } } - #[lang="eh_personality"] - #[no_mangle] // so we can reference it by name from middle/trans/base.rs - #[cfg(stage0)] - pub extern "C" fn rust_eh_personality( - state: uw::_Unwind_State, - ue_header: *uw::_Unwind_Exception, - context: *uw::_Unwind_Context - ) -> uw::_Unwind_Reason_Code - { - unsafe { - __gcc_personality_v0(state, ue_header, context) - } - } - #[no_mangle] // referenced from rust_try.ll pub extern "C" fn rust_eh_personality_catch( state: uw::_Unwind_State, @@ -327,20 +295,13 @@ pub mod eabi { } // Entry point of failure from the libcore crate -#[cfg(not(test), not(stage0))] +#[cfg(not(test))] #[lang = "begin_unwind"] pub extern fn rust_begin_unwind(msg: &fmt::Arguments, file: &'static str, line: uint) -> ! { begin_unwind_fmt(msg, file, line) } -#[no_mangle] -#[cfg(not(test), stage0)] -pub extern fn rust_begin_unwind(msg: &fmt::Arguments, - file: &'static str, line: uint) -> ! { - begin_unwind_fmt(msg, file, line) -} - /// The entry point for unwinding with a formatted message. /// /// This is designed to reduce the amount of code required at the call diff --git a/src/libstd/slice.rs b/src/libstd/slice.rs index 55bea068641..1433270346e 100644 --- a/src/libstd/slice.rs +++ b/src/libstd/slice.rs @@ -1916,7 +1916,7 @@ mod tests { assert!(values == [2, 3, 5, 6, 7]); } - #[deriving(Clone, Eq)] + #[deriving(Clone, PartialEq)] struct Foo; #[test] diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 6538809c8f1..a35b4e7a151 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -68,7 +68,7 @@ is the same as `&[u8]`. use char::Char; use char; use clone::Clone; -use cmp::{Eq, TotalEq, Ord, TotalOrd, Equiv, Ordering}; +use cmp::{PartialEq, TotalEq, PartialOrd, TotalOrd, Equiv, Ordering}; use container::Container; use default::Default; use fmt; @@ -566,7 +566,7 @@ impl<'a> IntoMaybeOwned<'a> for MaybeOwned<'a> { fn into_maybe_owned(self) -> MaybeOwned<'a> { self } } -impl<'a> Eq for MaybeOwned<'a> { +impl<'a> PartialEq for MaybeOwned<'a> { #[inline] fn eq(&self, other: &MaybeOwned) -> bool { self.as_slice() == other.as_slice() @@ -575,7 +575,7 @@ impl<'a> Eq for MaybeOwned<'a> { impl<'a> TotalEq for MaybeOwned<'a> {} -impl<'a> Ord for MaybeOwned<'a> { +impl<'a> PartialOrd for MaybeOwned<'a> { #[inline] fn lt(&self, other: &MaybeOwned) -> bool { self.as_slice().lt(&other.as_slice()) diff --git a/src/libstd/string.rs b/src/libstd/string.rs index 0edbaf99210..29d3c718682 100644 --- a/src/libstd/string.rs +++ b/src/libstd/string.rs @@ -30,7 +30,7 @@ use str; use vec::Vec; /// A growable string stored as a UTF-8 encoded buffer. -#[deriving(Clone, Eq, Ord, TotalEq, TotalOrd)] +#[deriving(Clone, PartialEq, PartialOrd, TotalEq, TotalOrd)] pub struct String { vec: Vec<u8>, } diff --git a/src/libstd/sync/deque.rs b/src/libstd/sync/deque.rs index 46d6129ded8..ea4c12f4401 100644 --- a/src/libstd/sync/deque.rs +++ b/src/libstd/sync/deque.rs @@ -102,7 +102,7 @@ pub struct Stealer<T> { } /// When stealing some data, this is an enumeration of the possible outcomes. -#[deriving(Eq, Show)] +#[deriving(PartialEq, Show)] pub enum Stolen<T> { /// The deque was empty at the time of stealing Empty, diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 81f6c7c7c9b..3cac6fadb94 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -12,7 +12,7 @@ use RawVec = raw::Vec; use clone::Clone; -use cmp::{Ord, Eq, Ordering, TotalEq, TotalOrd, max}; +use cmp::{PartialOrd, PartialEq, Ordering, TotalEq, TotalOrd, max}; use container::{Container, Mutable}; use default::Default; use fmt; @@ -374,14 +374,14 @@ impl<T> Extendable<T> for Vec<T> { } } -impl<T: Eq> Eq for Vec<T> { +impl<T: PartialEq> PartialEq for Vec<T> { #[inline] fn eq(&self, other: &Vec<T>) -> bool { self.as_slice() == other.as_slice() } } -impl<T: Ord> Ord for Vec<T> { +impl<T: PartialOrd> PartialOrd for Vec<T> { #[inline] fn lt(&self, other: &Vec<T>) -> bool { self.as_slice() < other.as_slice() @@ -1288,7 +1288,7 @@ impl<T> Mutable for Vec<T> { } } -impl<T:Eq> Vec<T> { +impl<T:PartialEq> Vec<T> { /// Return true if a vector contains an element with the given value /// /// # Example @@ -1315,7 +1315,7 @@ impl<T:Eq> Vec<T> { pub fn dedup(&mut self) { unsafe { // Although we have a mutable reference to `self`, we cannot make - // *arbitrary* changes. The `Eq` comparisons could fail, so we + // *arbitrary* changes. The `PartialEq` comparisons could fail, so we // must ensure that the vector is in a valid state at all time. // // The way that we handle this is by using swaps; we iterate |
