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 #![feature(macro_rules)]
13 use std::collections::Bitv;
14 use std::default::Default;
15 use std::iter::FromIterator;
16 use std::option::IntoIter as OptionIter;
18 use std::rand::XorShiftRng as DummyRng;
19 // FIXME the glob std::prelude::*; import of Vec is missing non-static inherent methods.
22 #[derive(PartialEq, Eq)]
25 fn id<T>(x: T) -> T { x }
26 fn eq<T: Eq>(a: T, b: T) -> bool { a == b }
27 fn u8_as_i8(x: u8) -> i8 { x as i8 }
28 fn odd(x: uint) -> bool { x % 2 == 1 }
29 fn dummy_rng() -> DummyRng { DummyRng::new_unseeded() }
32 ($($expr:expr: $ty:ty /($($test:expr),*);)+) => (pub fn main() {$({
34 static S: $ty = $expr;
35 assert!(eq(C($($test),*), $expr($($test),*)));
36 assert!(eq(S($($test),*), $expr($($test),*)));
37 assert!(eq(C($($test),*), S($($test),*)));
43 id: fn(int) -> int /(5);
44 id::<int>: fn(int) -> int /(5);
46 // Enum variant constructor.
47 Some: fn(int) -> Option<int> /(5);
48 Some::<int>: fn(int) -> Option<int> /(5);
50 // Tuple struct constructor.
51 Newt: fn(int) -> Newt<int> /(5);
52 Newt::<int>: fn(int) -> Newt<int> /(5);
54 // Inherent static methods.
55 Vec::new: fn() -> Vec<()> /();
56 Vec::<()>::new: fn() -> Vec<()> /();
57 Vec::with_capacity: fn(uint) -> Vec<()> /(5);
58 Vec::<()>::with_capacity: fn(uint) -> Vec<()> /(5);
59 Bitv::from_fn: fn(uint, fn(uint) -> bool) -> Bitv /(5, odd);
60 Bitv::from_fn::<fn(uint) -> bool>: fn(uint, fn(uint) -> bool) -> Bitv /(5, odd);
62 // Inherent non-static method.
63 Vec::map_in_place: fn(Vec<u8>, fn(u8) -> i8) -> Vec<i8>
64 /(vec![b'f', b'o', b'o'], u8_as_i8);
65 Vec::map_in_place::<i8, fn(u8) -> i8>: fn(Vec<u8>, fn(u8) -> i8) -> Vec<i8>
66 /(vec![b'f', b'o', b'o'], u8_as_i8);
67 // FIXME these break with "type parameter might not appear here pointing at `<u8>`.
68 // Vec::<u8>::map_in_place: fn(Vec<u8>, fn(u8) -> i8) -> Vec<i8>
69 // /(vec![b'f', b'o', b'o'], u8_as_i8);
70 // Vec::<u8>::map_in_place::<i8, fn(u8) -> i8>: fn(Vec<u8>, fn(u8) -> i8) -> Vec<i8>
71 // /(vec![b'f', b'o', b'o'], u8_as_i8);
73 // Trait static methods.
74 // FIXME qualified path expressions aka UFCS i.e. <T as Trait>::method.
75 Default::default: fn() -> int /();
76 Rand::rand: fn(&mut DummyRng) -> int /(&mut dummy_rng());
77 Rand::rand::<DummyRng>: fn(&mut DummyRng) -> int /(&mut dummy_rng());
79 // Trait non-static methods.
80 Clone::clone: fn(&int) -> int /(&5);
81 FromIterator::from_iter: fn(OptionIter<int>) -> Vec<int> /(Some(5).into_iter());
82 FromIterator::from_iter::<OptionIter<int>>: fn(OptionIter<int>) -> Vec<int>
83 /(Some(5).into_iter());