1 // Copyright 2015 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 #![ crate_name = "test" ]
13 #![feature(box_syntax)]
15 extern crate graphviz;
16 // A simple rust project
18 extern crate "flate" as myflate;
20 use graphviz::maybe_owned_vec::MaybeOwnedVector;
21 use std::collections::{HashMap,HashSet};
22 use std::cell::RefCell;
23 use std::old_io::stdio::println;
26 use sub::sub2 as msalias;
28 use sub::sub2::nested_struct as sub_struct;
31 use std::num::{from_int,from_i8,from_i32};
33 use std::mem::size_of;
35 static uni: &'static str = "Les Miséééééééérables";
36 static yy: usize = 25us;
38 static bob: Option<graphviz::maybe_owned_vec::MaybeOwnedVector<'static, isize>> = None;
40 // buglink test - see issue #1337.
42 fn test_alias<I: Iterator>(i: Option<<I as Iterator>::Item>) {
43 let s = sub_struct{ field2: 45u32, };
47 let _: Option<u8> = from_i32(45);
51 myflate::deflate_bytes(&[]);
57 struct TupStruct(int, int, Box<str>);
59 fn test_tup_struct(x: TupStruct) -> int {
65 use std::old_io::stdio::println;
67 use std::old_io::stdio::println;
69 println("hello from module 3");
73 println("hello from a module");
76 pub struct nested_struct {
80 pub enum nested_enum {
90 #[path = "SameDir3.rs"]
100 type SF = some_fields;
105 trait SomeTrait: SuperTrait {
106 fn Method(&self, x: u32) -> u32;
108 fn prov(&self, x: u32) -> u32 {
109 println(&x.to_string());
112 fn provided_method(&self) -> u32 {
117 trait SubTrait: SomeTrait {
118 fn stat2(x: &Self) -> u32 {
123 impl SomeTrait for some_fields {
124 fn Method(&self, x: u32) -> u32 {
125 println(&x.to_string());
130 impl SuperTrait for some_fields {
133 impl SubTrait for some_fields {}
136 fn stat(x: u32) -> u32 {
137 println(&x.to_string());
140 fn stat2(x: &some_fields) -> u32 {
144 fn align_to<T>(&mut self) {
148 self.align_to::<bool>();
152 impl SuperTrait for nofields {
154 impl SomeTrait for nofields {
155 fn Method(&self, x: u32) -> u32 {
160 fn provided_method(&self) -> u32 {
165 impl SubTrait for nofields {}
167 impl SuperTrait for (Box<nofields>, Box<some_fields>) {}
169 fn f_with_params<T: SomeTrait>(x: &T) {
173 type MyType = Box<some_fields>;
178 Strings(&'a str, &'a str, &'a str),
179 MyTypes(MyType, MyType)
189 enum SomeStructEnum {
190 EnumStruct{a:isize, b:isize},
191 EnumStruct2{f1:MyType, f2:MyType},
192 EnumStruct3{f1:MyType, f2:MyType, f3:SomeEnum<'static>}
195 fn matchSomeEnum(val: SomeEnum) {
197 SomeEnum::Ints(int1, int2) => { println(&(int1+int2).to_string()); }
198 SomeEnum::Floats(float1, float2) => { println(&(float2*float1).to_string()); }
199 SomeEnum::Strings(_, _, s3) => { println(s3); }
200 SomeEnum::MyTypes(mt1, mt2) => {
201 println(&(mt1.field1 - mt2.field1).to_string());
206 fn matchSomeStructEnum(se: SomeStructEnum) {
208 SomeStructEnum::EnumStruct{a:a, ..} => println(&a.to_string()),
209 SomeStructEnum::EnumStruct2{f1:f1, f2:f_2} => println(&f_2.field1.to_string()),
210 SomeStructEnum::EnumStruct3{f1, ..} => println(&f1.field1.to_string()),
215 fn matchSomeStructEnum2(se: SomeStructEnum) {
216 use SomeStructEnum::*;
218 EnumStruct{a: ref aaa, ..} => println(&aaa.to_string()),
219 EnumStruct2{f1, f2: f2} => println(&f1.field1.to_string()),
220 EnumStruct3{f1, f3: SomeEnum::Ints(_, _), f2} => println(&f1.field1.to_string()),
225 fn matchSomeOtherEnum(val: SomeOtherEnum) {
226 use SomeOtherEnum::{SomeConst2, SomeConst3};
228 SomeOtherEnum::SomeConst1 => { println("I'm const1."); }
229 SomeConst2 | SomeConst3 => { println("I'm const2 or const3."); }
233 fn hello<X: SomeTrait>((z, a) : (u32, String), ex: X) {
236 println(&yy.to_string());
237 let (x, y): (u32, u32) = (5, 3);
238 println(&x.to_string());
239 println(&z.to_string());
241 println(&x.to_string());
246 let _ = (x + ((x * x) + 1.0).sqrt()).ln();
248 let s: Box<SomeTrait> = box some_fields {field1: 43};
249 let s2: Box<some_fields> = box some_fields {field1: 43};
250 let s3 = box nofields;
259 // static method on struct
260 let r = some_fields::stat(y);
261 // trait static method, calls override
262 let r = SubTrait::stat2(&*s2);
263 // trait static method, calls default
264 let r = SubTrait::stat2(&*s3);
266 let s4 = s3 as Box<SomeTrait>;
269 s4.provided_method();
272 let closure = |x: u32, s: &SomeTrait| {
277 let z = closure(10, &*s);
281 used_link_args: RefCell<[&'static str; 0]>,
285 let s = box some_fields {field1: 43};
286 hello((43, "a".to_string()), *s);
290 let h = sub2::sub3::hello;
294 let ut = "Les Miséééééééérables";
296 // For some reason, this pattern of macro_rules foiled our generated code
297 // avoiding strategy.
298 macro_rules! variable_str(($name:expr) => (
303 let vs = variable_str!(32);
305 let mut candidates: RefCell<HashMap<&'static str, &'static str>> = RefCell::new(HashMap::new());
307 used_link_args: RefCell::new([]),
310 let s2 = SF { field1: 55};
311 let s3: some_fields = some_fields{ field1: 55};
312 let s4: msalias::nested_struct = sub::sub2::nested_struct{ field2: 55};
313 let s4: msalias::nested_struct = sub2::nested_struct{ field2: 55};
314 println(&s2.field1.to_string());
315 let s5: MyType = box some_fields{ field1: 55};
316 let s = SameDir::SameStruct{name: "Bob".to_string()};
317 let s = SubDir::SubStruct{name:"Bob".to_string()};
318 let s6: SomeEnum = SomeEnum::MyTypes(box s2.clone(), s5);
319 let s7: SomeEnum = SomeEnum::Strings("one", "two", "three");
322 let s8: SomeOtherEnum = SomeOtherEnum::SomeConst2;
323 matchSomeOtherEnum(s8);
324 let s9: SomeStructEnum =
325 SomeStructEnum::EnumStruct2{f1: box some_fields{field1:10}, f2: box s2};
326 matchSomeStructEnum(s9);
329 impl Iterator for nofields {
330 type Item = (usize, usize);
332 fn next(&mut self) -> Option<(usize, usize)> {
336 fn size_hint(&self) -> (usize, Option<usize>) {