1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use std
::borrow
::{Cow, ToOwned}
;
12 use std
::default::Default
;
13 use std
::iter
::FromIterator
;
15 use std
::option
::IntoIter
as OptionIter
;
17 pub struct XorShiftRng
;
18 use XorShiftRng
as DummyRng
;
19 impl Rng
for XorShiftRng {}
21 pub trait Rand
: Default
+ Sized
{
22 fn rand
<R
: Rng
>(_rng
: &mut R
) -> Self { Default::default() }
26 pub trait IntoCow
<'a
, B
: ?Sized
> where B
: ToOwned
{
27 fn into_cow(self) -> Cow
<'a
, B
>;
30 impl<'a
> IntoCow
<'a
, str> for String
{
31 fn into_cow(self) -> Cow
<'a
, str> {
36 #[derive(PartialEq, Eq)]
39 fn id
<T
>(x
: T
) -> T { x }
40 fn eq
<T
: Eq
>(a
: T
, b
: T
) -> bool { a == b }
41 fn u8_as_i8(x
: u8) -> i8 { x as i8 }
42 fn odd(x
: usize) -> bool { x % 2 == 1 }
43 fn dummy_rng() -> DummyRng { XorShiftRng }
46 fn size() -> usize { std::mem::size_of::<Self>() }
50 #[derive(PartialEq, Eq)]
54 fn from_fn
<F
>(_
: usize, _
: F
) -> BitVec
where F
: FnMut(usize) -> bool
{
59 #[derive(PartialEq, Eq)]
63 fn map_in_place
<U
, F
>(self, mut f
: F
) -> Foo
<U
> where F
: FnMut(T
) -> U
{
70 ($
($expr
:expr
, $ty
:ty
, ($
($test
:expr
),*);)+) => (pub fn main() {$
({
72 static S
: $ty
= $expr
;
73 assert
!(eq(C($
($test
),*), $
expr($
($test
),*)));
74 assert
!(eq(S($
($test
),*), $
expr($
($test
),*)));
75 assert
!(eq(C($
($test
),*), S($
($test
),*)));
81 id
, fn(i32) -> i32, (5);
82 id
::<i32>, fn(i32) -> i32, (5);
84 // Enum variant constructor.
85 Some
, fn(i32) -> Option
<i32>, (5);
86 Some
::<i32>, fn(i32) -> Option
<i32>, (5);
88 // Tuple struct constructor.
89 Newt
, fn(i32) -> Newt
<i32>, (5);
90 Newt
::<i32>, fn(i32) -> Newt
<i32>, (5);
92 // Inherent static methods.
93 Vec
::new
, fn() -> Vec
<()>, ();
94 Vec
::<()>::new
, fn() -> Vec
<()>, ();
95 <Vec
<()>>::new
, fn() -> Vec
<()>, ();
96 Vec
::with_capacity
, fn(usize) -> Vec
<()>, (5);
97 Vec
::<()>::with_capacity
, fn(usize) -> Vec
<()>, (5);
98 <Vec
<()>>::with_capacity
, fn(usize) -> Vec
<()>, (5);
99 BitVec
::from_fn
, fn(usize, fn(usize) -> bool
) -> BitVec
, (5, odd
);
100 BitVec
::from_fn
::<fn(usize) -> bool
>, fn(usize, fn(usize) -> bool
) -> BitVec
, (5, odd
);
102 // Inherent non-static method.
103 Foo
::map_in_place
, fn(Foo
<u8>, fn(u8) -> i8) -> Foo
<i8>, (Foo(b'f'
), u8_as_i8
);
104 Foo
::map_in_place
::<i8, fn(u8) -> i8>, fn(Foo
<u8>, fn(u8) -> i8) -> Foo
<i8>,
105 (Foo(b'f'
), u8_as_i8
);
106 Foo
::<u8>::map_in_place
, fn(Foo
<u8>, fn(u8) -> i8) -> Foo
<i8>
107 , (Foo(b'f'
), u8_as_i8
);
108 Foo
::<u8>::map_in_place
::<i8, fn(u8) -> i8>, fn(Foo
<u8>, fn(u8) -> i8) -> Foo
<i8>
109 , (Foo(b'f'
), u8_as_i8
);
111 // Trait static methods.
112 bool
::size
, fn() -> usize, ();
113 <bool
>::size
, fn() -> usize, ();
114 <bool
as Size
>::size
, fn() -> usize, ();
116 Default
::default, fn() -> i32, ();
117 i32::default, fn() -> i32, ();
118 <i32>::default, fn() -> i32, ();
119 <i32 as Default
>::default, fn() -> i32, ();
121 Rand
::rand
, fn(&mut DummyRng
) -> i32, (&mut dummy_rng());
122 i32::rand
, fn(&mut DummyRng
) -> i32, (&mut dummy_rng());
123 <i32>::rand
, fn(&mut DummyRng
) -> i32, (&mut dummy_rng());
124 <i32 as Rand
>::rand
, fn(&mut DummyRng
) -> i32, (&mut dummy_rng());
125 Rand
::rand
::<DummyRng
>, fn(&mut DummyRng
) -> i32, (&mut dummy_rng());
126 i32::rand
::<DummyRng
>, fn(&mut DummyRng
) -> i32, (&mut dummy_rng());
127 <i32>::rand
::<DummyRng
>, fn(&mut DummyRng
) -> i32, (&mut dummy_rng());
128 <i32 as Rand
>::rand
::<DummyRng
>, fn(&mut DummyRng
) -> i32, (&mut dummy_rng());
130 // Trait non-static methods.
131 Clone
::clone
, fn(&i32) -> i32, (&5);
132 i32::clone
, fn(&i32) -> i32, (&5);
133 <i32>::clone
, fn(&i32) -> i32, (&5);
134 <i32 as Clone
>::clone
, fn(&i32) -> i32, (&5);
136 FromIterator
::from_iter
, fn(OptionIter
<i32>) -> Vec
<i32>, (Some(5).into_iter());
137 Vec
::from_iter
, fn(OptionIter
<i32>) -> Vec
<i32>, (Some(5).into_iter());
138 <Vec
<_
>>::from_iter
, fn(OptionIter
<i32>) -> Vec
<i32>, (Some(5).into_iter());
139 <Vec
<_
> as FromIterator
<_
>>::from_iter
, fn(OptionIter
<i32>) -> Vec
<i32>,
140 (Some(5).into_iter());
141 <Vec
<i32> as FromIterator
<_
>>::from_iter
, fn(OptionIter
<i32>) -> Vec
<i32>,
142 (Some(5).into_iter());
143 FromIterator
::from_iter
::<OptionIter
<i32>>, fn(OptionIter
<i32>) -> Vec
<i32>,
144 (Some(5).into_iter());
145 <Vec
<i32> as FromIterator
<_
>>::from_iter
::<OptionIter
<i32>>, fn(OptionIter
<i32>) -> Vec
<i32>,
146 (Some(5).into_iter());
148 Add
::add
, fn(i32, i32) -> i32, (5, 6);
149 i32::add
, fn(i32, i32) -> i32, (5, 6);
150 <i32>::add
, fn(i32, i32) -> i32, (5, 6);
151 <i32 as Add
<_
>>::add
, fn(i32, i32) -> i32, (5, 6);
152 <i32 as Add
<i32>>::add
, fn(i32, i32) -> i32, (5, 6);
154 String
::into_cow
, fn(String
) -> Cow
<'
static, str>,
156 <String
>::into_cow
, fn(String
) -> Cow
<'
static, str>,
158 <String
as IntoCow
<_
>>::into_cow
, fn(String
) -> Cow
<'
static, str>,
160 <String
as IntoCow
<'
static, _
>>::into_cow
, fn(String
) -> Cow
<'
static, str>,