2015-01-04 18:47:58 +02:00
|
|
|
// Copyright 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.
|
|
|
|
|
|
|
|
#![feature(macro_rules)]
|
|
|
|
|
2015-01-15 09:46:12 +02:00
|
|
|
use std::borrow::{Cow, IntoCow};
|
2015-01-04 18:47:58 +02:00
|
|
|
use std::collections::Bitv;
|
|
|
|
use std::default::Default;
|
|
|
|
use std::iter::FromIterator;
|
2015-01-15 09:46:12 +02:00
|
|
|
use std::ops::Add;
|
2015-01-04 18:47:58 +02:00
|
|
|
use std::option::IntoIter as OptionIter;
|
|
|
|
use std::rand::Rand;
|
|
|
|
use std::rand::XorShiftRng as DummyRng;
|
|
|
|
// FIXME the glob std::prelude::*; import of Vec is missing non-static inherent methods.
|
|
|
|
use std::vec::Vec;
|
|
|
|
|
|
|
|
#[derive(PartialEq, Eq)]
|
|
|
|
struct Newt<T>(T);
|
|
|
|
|
|
|
|
fn id<T>(x: T) -> T { x }
|
|
|
|
fn eq<T: Eq>(a: T, b: T) -> bool { a == b }
|
|
|
|
fn u8_as_i8(x: u8) -> i8 { x as i8 }
|
|
|
|
fn odd(x: uint) -> bool { x % 2 == 1 }
|
|
|
|
fn dummy_rng() -> DummyRng { DummyRng::new_unseeded() }
|
|
|
|
|
2015-01-15 09:46:12 +02:00
|
|
|
trait Size: Sized {
|
|
|
|
fn size() -> uint { std::mem::size_of::<Self>() }
|
|
|
|
}
|
|
|
|
impl<T> Size for T {}
|
|
|
|
|
2015-01-04 18:47:58 +02:00
|
|
|
macro_rules! tests {
|
2015-01-05 01:51:03 -05:00
|
|
|
($($expr:expr, $ty:ty, ($($test:expr),*);)+) => (pub fn main() {$({
|
2015-01-04 18:47:58 +02:00
|
|
|
const C: $ty = $expr;
|
|
|
|
static S: $ty = $expr;
|
|
|
|
assert!(eq(C($($test),*), $expr($($test),*)));
|
|
|
|
assert!(eq(S($($test),*), $expr($($test),*)));
|
|
|
|
assert!(eq(C($($test),*), S($($test),*)));
|
|
|
|
})+})
|
|
|
|
}
|
|
|
|
|
|
|
|
tests! {
|
|
|
|
// Free function.
|
2015-01-05 01:51:03 -05:00
|
|
|
id, fn(int) -> int, (5);
|
|
|
|
id::<int>, fn(int) -> int, (5);
|
2015-01-04 18:47:58 +02:00
|
|
|
|
|
|
|
// Enum variant constructor.
|
2015-01-05 01:51:03 -05:00
|
|
|
Some, fn(int) -> Option<int>, (5);
|
|
|
|
Some::<int>, fn(int) -> Option<int>, (5);
|
2015-01-04 18:47:58 +02:00
|
|
|
|
|
|
|
// Tuple struct constructor.
|
2015-01-05 01:51:03 -05:00
|
|
|
Newt, fn(int) -> Newt<int>, (5);
|
|
|
|
Newt::<int>, fn(int) -> Newt<int>, (5);
|
2015-01-04 18:47:58 +02:00
|
|
|
|
|
|
|
// Inherent static methods.
|
2015-01-05 01:51:03 -05:00
|
|
|
Vec::new, fn() -> Vec<()>, ();
|
|
|
|
Vec::<()>::new, fn() -> Vec<()>, ();
|
|
|
|
Vec::with_capacity, fn(uint) -> Vec<()>, (5);
|
|
|
|
Vec::<()>::with_capacity, fn(uint) -> Vec<()>, (5);
|
|
|
|
Bitv::from_fn, fn(uint, fn(uint) -> bool) -> Bitv, (5, odd);
|
|
|
|
Bitv::from_fn::<fn(uint) -> bool>, fn(uint, fn(uint) -> bool) -> Bitv, (5, odd);
|
2015-01-04 18:47:58 +02:00
|
|
|
|
|
|
|
// Inherent non-static method.
|
2015-01-05 01:51:03 -05:00
|
|
|
Vec::map_in_place, fn(Vec<u8>, fn(u8) -> i8) -> Vec<i8>, (vec![b'f', b'o', b'o'], u8_as_i8);
|
|
|
|
Vec::map_in_place::<i8, fn(u8) -> i8>, fn(Vec<u8>, fn(u8) -> i8) -> Vec<i8>,
|
|
|
|
(vec![b'f', b'o', b'o'], u8_as_i8);
|
2015-01-04 18:47:58 +02:00
|
|
|
// FIXME these break with "type parameter might not appear here pointing at `<u8>`.
|
|
|
|
// Vec::<u8>::map_in_place: fn(Vec<u8>, fn(u8) -> i8) -> Vec<i8>
|
2015-01-05 01:51:03 -05:00
|
|
|
// , (vec![b'f', b'o', b'o'], u8_as_i8);
|
2015-01-04 18:47:58 +02:00
|
|
|
// Vec::<u8>::map_in_place::<i8, fn(u8) -> i8>: fn(Vec<u8>, fn(u8) -> i8) -> Vec<i8>
|
2015-01-05 01:51:03 -05:00
|
|
|
// , (vec![b'f', b'o', b'o'], u8_as_i8);
|
2015-01-04 18:47:58 +02:00
|
|
|
|
|
|
|
// Trait static methods.
|
2015-01-15 09:46:12 +02:00
|
|
|
<bool as Size>::size, fn() -> uint, ();
|
2015-01-05 01:51:03 -05:00
|
|
|
Default::default, fn() -> int, ();
|
2015-01-15 09:46:12 +02:00
|
|
|
<int as Default>::default, fn() -> int, ();
|
2015-01-05 01:51:03 -05:00
|
|
|
Rand::rand, fn(&mut DummyRng) -> int, (&mut dummy_rng());
|
2015-01-15 09:46:12 +02:00
|
|
|
<int as Rand>::rand, fn(&mut DummyRng) -> int, (&mut dummy_rng());
|
2015-01-05 01:51:03 -05:00
|
|
|
Rand::rand::<DummyRng>, fn(&mut DummyRng) -> int, (&mut dummy_rng());
|
2015-01-15 09:46:12 +02:00
|
|
|
<int as Rand>::rand::<DummyRng>, fn(&mut DummyRng) -> int, (&mut dummy_rng());
|
2015-01-04 18:47:58 +02:00
|
|
|
|
|
|
|
// Trait non-static methods.
|
2015-01-05 01:51:03 -05:00
|
|
|
Clone::clone, fn(&int) -> int, (&5);
|
2015-01-15 09:46:12 +02:00
|
|
|
<int as Clone>::clone, fn(&int) -> int, (&5);
|
2015-01-05 01:51:03 -05:00
|
|
|
FromIterator::from_iter, fn(OptionIter<int>) -> Vec<int>, (Some(5).into_iter());
|
2015-01-15 09:46:12 +02:00
|
|
|
<Vec<_> as FromIterator<_>>::from_iter, fn(OptionIter<int>) -> Vec<int>,
|
|
|
|
(Some(5).into_iter());
|
|
|
|
<Vec<int> as FromIterator<_>>::from_iter, fn(OptionIter<int>) -> Vec<int>,
|
|
|
|
(Some(5).into_iter());
|
|
|
|
FromIterator::from_iter::<OptionIter<int>>, fn(OptionIter<int>) -> Vec<int>,
|
|
|
|
(Some(5).into_iter());
|
|
|
|
<Vec<int> as FromIterator<_>>::from_iter::<OptionIter<int>>, fn(OptionIter<int>) -> Vec<int>,
|
|
|
|
(Some(5).into_iter());
|
|
|
|
Add::add, fn(i32, i32) -> i32, (5, 6);
|
|
|
|
<i32 as Add<_>>::add, fn(i32, i32) -> i32, (5, 6);
|
|
|
|
<i32 as Add<i32>>::add, fn(i32, i32) -> i32, (5, 6);
|
|
|
|
<String as IntoCow<_, _>>::into_cow, fn(String) -> Cow<'static, String, str>,
|
|
|
|
("foo".to_string());
|
|
|
|
<String as IntoCow<'static, _, _>>::into_cow, fn(String) -> Cow<'static, String, str>,
|
|
|
|
("foo".to_string());
|
2015-01-04 18:47:58 +02:00
|
|
|
}
|