/// ```
/// use std::ops::Add;
///
-/// #[derive(Copy)]
+/// #[derive(Copy, Clone)]
/// struct Foo;
///
/// impl Add for Foo {
/// ```
/// use std::ops::Sub;
///
-/// #[derive(Copy)]
+/// #[derive(Copy, Clone)]
/// struct Foo;
///
/// impl Sub for Foo {
/// ```
/// use std::ops::Mul;
///
-/// #[derive(Copy)]
+/// #[derive(Copy, Clone)]
/// struct Foo;
///
/// impl Mul for Foo {
/// ```
/// use std::ops::Div;
///
-/// #[derive(Copy)]
+/// #[derive(Copy, Clone)]
/// struct Foo;
///
/// impl Div for Foo {
/// ```
/// use std::ops::Rem;
///
-/// #[derive(Copy)]
+/// #[derive(Copy, Clone)]
/// struct Foo;
///
/// impl Rem for Foo {
/// ```
/// use std::ops::Neg;
///
-/// #[derive(Copy)]
+/// #[derive(Copy, Clone)]
/// struct Foo;
///
/// impl Neg for Foo {
fn neg(self) -> Self::Output;
}
-macro_rules! neg_impl {
- ($($t:ty)*) => ($(
+
+
+macro_rules! neg_impl_core {
+ ($id:ident => $body:expr, $($t:ty)*) => ($(
#[stable(feature = "rust1", since = "1.0.0")]
#[allow(unsigned_negation)]
impl Neg for $t {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
- fn neg(self) -> $t { -self }
+ fn neg(self) -> $t { let $id = self; $body }
}
forward_ref_unop! { impl Neg, neg for $t }
)*)
}
-neg_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
+macro_rules! neg_impl_numeric {
+ ($($t:ty)*) => { neg_impl_core!{ x => -x, $($t)*} }
+}
+
+macro_rules! neg_impl_unsigned {
+ ($($t:ty)*) => {
+ neg_impl_core!{ x => {
+ #[cfg(stage0)]
+ use ::num::wrapping::WrappingOps;
+ !x.wrapping_add(1)
+ }, $($t)*} }
+}
+
+// neg_impl_unsigned! { usize u8 u16 u32 u64 }
+neg_impl_numeric! { isize i8 i16 i32 i64 f32 f64 }
/// The `Not` trait is used to specify the functionality of unary `!`.
///
/// ```
/// use std::ops::Not;
///
-/// #[derive(Copy)]
+/// #[derive(Copy, Clone)]
/// struct Foo;
///
/// impl Not for Foo {
/// ```
/// use std::ops::BitAnd;
///
-/// #[derive(Copy)]
+/// #[derive(Copy, Clone)]
/// struct Foo;
///
/// impl BitAnd for Foo {
/// ```
/// use std::ops::BitOr;
///
-/// #[derive(Copy)]
+/// #[derive(Copy, Clone)]
/// struct Foo;
///
/// impl BitOr for Foo {
/// ```
/// use std::ops::BitXor;
///
-/// #[derive(Copy)]
+/// #[derive(Copy, Clone)]
/// struct Foo;
///
/// impl BitXor for Foo {
/// ```
/// use std::ops::Shl;
///
-/// #[derive(Copy)]
+/// #[derive(Copy, Clone)]
/// struct Foo;
///
/// impl Shl<Foo> for Foo {
/// ```
/// use std::ops::Shr;
///
-/// #[derive(Copy)]
+/// #[derive(Copy, Clone)]
/// struct Foo;
///
/// impl Shr<Foo> for Foo {
/// ```
/// use std::ops::Index;
///
-/// #[derive(Copy)]
+/// #[derive(Copy, Clone)]
/// struct Foo;
/// struct Bar;
///
/// ```
/// use std::ops::{Index, IndexMut};
///
-/// #[derive(Copy)]
+/// #[derive(Copy, Clone)]
/// struct Foo;
/// struct Bar;
///
#[lang="fn"]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_paren_sugar]
+#[fundamental] // so that regex can rely that `&str: !FnMut`
pub trait Fn<Args> : FnMut<Args> {
/// This is called when the call operator is used.
extern "rust-call" fn call(&self, args: Args) -> Self::Output;
#[lang="fn_mut"]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_paren_sugar]
+#[fundamental] // so that regex can rely that `&str: !FnMut`
pub trait FnMut<Args> : FnOnce<Args> {
/// This is called when the call operator is used.
extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
#[lang="fn_once"]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_paren_sugar]
+#[fundamental] // so that regex can rely that `&str: !FnMut`
pub trait FnOnce<Args> {
/// The returned type after the call operator is used.
type Output;
/// This is called when the call operator is used.
extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
}
+
+#[cfg(not(stage0))]
+mod impls {
+ use marker::Sized;
+ use super::{Fn, FnMut, FnOnce};
+
+ impl<'a,A,F:?Sized> Fn<A> for &'a F
+ where F : Fn<A>
+ {
+ extern "rust-call" fn call(&self, args: A) -> F::Output {
+ (**self).call(args)
+ }
+ }
+
+ impl<'a,A,F:?Sized> FnMut<A> for &'a F
+ where F : Fn<A>
+ {
+ extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
+ (**self).call(args)
+ }
+ }
+
+ impl<'a,A,F:?Sized> FnOnce<A> for &'a F
+ where F : Fn<A>
+ {
+ type Output = F::Output;
+
+ extern "rust-call" fn call_once(self, args: A) -> F::Output {
+ (*self).call(args)
+ }
+ }
+
+ impl<'a,A,F:?Sized> FnMut<A> for &'a mut F
+ where F : FnMut<A>
+ {
+ extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
+ (*self).call_mut(args)
+ }
+ }
+
+ impl<'a,A,F:?Sized> FnOnce<A> for &'a mut F
+ where F : FnMut<A>
+ {
+ type Output = F::Output;
+ extern "rust-call" fn call_once(mut self, args: A) -> F::Output {
+ (*self).call_mut(args)
+ }
+ }
+}