// 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 or the MIT license // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. #![feature(macro_rules)] use std::borrow::{Cow, IntoCow}; use std::collections::Bitv; use std::default::Default; use std::iter::FromIterator; use std::ops::Add; 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); fn id(x: T) -> T { x } fn 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() } trait Size: Sized { fn size() -> uint { std::mem::size_of::() } } impl Size for T {} macro_rules! tests { ($($expr:expr, $ty:ty, ($($test:expr),*);)+) => (pub fn main() {$({ 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. id, fn(int) -> int, (5); id::, fn(int) -> int, (5); // Enum variant constructor. Some, fn(int) -> Option, (5); Some::, fn(int) -> Option, (5); // Tuple struct constructor. Newt, fn(int) -> Newt, (5); Newt::, fn(int) -> Newt, (5); // Inherent static methods. 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:: bool>, fn(uint, fn(uint) -> bool) -> Bitv, (5, odd); // Inherent non-static method. Vec::map_in_place, fn(Vec, fn(u8) -> i8) -> Vec, (vec![b'f', b'o', b'o'], u8_as_i8); Vec::map_in_place:: i8>, fn(Vec, fn(u8) -> i8) -> Vec, (vec![b'f', b'o', b'o'], u8_as_i8); // FIXME these break with "type parameter might not appear here pointing at ``. // Vec::::map_in_place: fn(Vec, fn(u8) -> i8) -> Vec // , (vec![b'f', b'o', b'o'], u8_as_i8); // Vec::::map_in_place:: i8>: fn(Vec, fn(u8) -> i8) -> Vec // , (vec![b'f', b'o', b'o'], u8_as_i8); // Trait static methods. ::size, fn() -> uint, (); Default::default, fn() -> int, (); ::default, fn() -> int, (); Rand::rand, fn(&mut DummyRng) -> int, (&mut dummy_rng()); ::rand, fn(&mut DummyRng) -> int, (&mut dummy_rng()); Rand::rand::, fn(&mut DummyRng) -> int, (&mut dummy_rng()); ::rand::, fn(&mut DummyRng) -> int, (&mut dummy_rng()); // Trait non-static methods. Clone::clone, fn(&int) -> int, (&5); ::clone, fn(&int) -> int, (&5); FromIterator::from_iter, fn(OptionIter) -> Vec, (Some(5).into_iter()); as FromIterator<_>>::from_iter, fn(OptionIter) -> Vec, (Some(5).into_iter()); as FromIterator<_>>::from_iter, fn(OptionIter) -> Vec, (Some(5).into_iter()); FromIterator::from_iter::>, fn(OptionIter) -> Vec, (Some(5).into_iter()); as FromIterator<_>>::from_iter::>, fn(OptionIter) -> Vec, (Some(5).into_iter()); Add::add, fn(i32, i32) -> i32, (5, 6); >::add, fn(i32, i32) -> i32, (5, 6); >::add, fn(i32, i32) -> i32, (5, 6); >::into_cow, fn(String) -> Cow<'static, String, str>, ("foo".to_string()); >::into_cow, fn(String) -> Cow<'static, String, str>, ("foo".to_string()); }