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 std::collections::{HashMap,HashSet};
21 use std::cell::RefCell;
22 use std::old_io::stdio::println;
25 use sub::sub2 as msalias;
27 use sub::sub2::nested_struct as sub_struct;
30 use std::num::{from_int,from_i8,from_i32};
32 use std::mem::size_of;
34 static uni: &'static str = "Les Miséééééééérables";
35 static yy: usize = 25us;
37 static bob: Option<std::vec::CowVec<'static, isize>> = None;
39 // buglink test - see issue #1337.
41 fn test_alias<I: Iterator>(i: Option<<I as Iterator>::Item>) {
42 let s = sub_struct{ field2: 45u32, };
46 let _: Option<u8> = from_i32(45);
50 myflate::deflate_bytes(&[]);
56 struct TupStruct(int, int, Box<str>);
58 fn test_tup_struct(x: TupStruct) -> int {
64 use std::old_io::stdio::println;
66 use std::old_io::stdio::println;
68 println("hello from module 3");
72 println("hello from a module");
75 pub struct nested_struct {
79 pub enum nested_enum {
89 #[path = "SameDir3.rs"]
99 type SF = some_fields;
104 trait SomeTrait: SuperTrait {
105 fn Method(&self, x: u32) -> u32;
107 fn prov(&self, x: u32) -> u32 {
108 println(&x.to_string());
111 fn provided_method(&self) -> u32 {
116 trait SubTrait: SomeTrait {
117 fn stat2(x: &Self) -> u32 {
122 impl SomeTrait for some_fields {
123 fn Method(&self, x: u32) -> u32 {
124 println(&x.to_string());
129 impl SuperTrait for some_fields {
132 impl SubTrait for some_fields {}
135 fn stat(x: u32) -> u32 {
136 println(&x.to_string());
139 fn stat2(x: &some_fields) -> u32 {
143 fn align_to<T>(&mut self) {
147 self.align_to::<bool>();
151 impl SuperTrait for nofields {
153 impl SomeTrait for nofields {
154 fn Method(&self, x: u32) -> u32 {
159 fn provided_method(&self) -> u32 {
164 impl SubTrait for nofields {}
166 impl SuperTrait for (Box<nofields>, Box<some_fields>) {}
168 fn f_with_params<T: SomeTrait>(x: &T) {
172 type MyType = Box<some_fields>;
177 Strings(&'a str, &'a str, &'a str),
178 MyTypes(MyType, MyType)
188 enum SomeStructEnum {
189 EnumStruct{a:isize, b:isize},
190 EnumStruct2{f1:MyType, f2:MyType},
191 EnumStruct3{f1:MyType, f2:MyType, f3:SomeEnum<'static>}
194 fn matchSomeEnum(val: SomeEnum) {
196 SomeEnum::Ints(int1, int2) => { println(&(int1+int2).to_string()); }
197 SomeEnum::Floats(float1, float2) => { println(&(float2*float1).to_string()); }
198 SomeEnum::Strings(_, _, s3) => { println(s3); }
199 SomeEnum::MyTypes(mt1, mt2) => {
200 println(&(mt1.field1 - mt2.field1).to_string());
205 fn matchSomeStructEnum(se: SomeStructEnum) {
207 SomeStructEnum::EnumStruct{a:a, ..} => println(&a.to_string()),
208 SomeStructEnum::EnumStruct2{f1:f1, f2:f_2} => println(&f_2.field1.to_string()),
209 SomeStructEnum::EnumStruct3{f1, ..} => println(&f1.field1.to_string()),
214 fn matchSomeStructEnum2(se: SomeStructEnum) {
215 use SomeStructEnum::*;
217 EnumStruct{a: ref aaa, ..} => println(&aaa.to_string()),
218 EnumStruct2{f1, f2: f2} => println(&f1.field1.to_string()),
219 EnumStruct3{f1, f3: SomeEnum::Ints(_, _), f2} => println(&f1.field1.to_string()),
224 fn matchSomeOtherEnum(val: SomeOtherEnum) {
225 use SomeOtherEnum::{SomeConst2, SomeConst3};
227 SomeOtherEnum::SomeConst1 => { println("I'm const1."); }
228 SomeConst2 | SomeConst3 => { println("I'm const2 or const3."); }
232 fn hello<X: SomeTrait>((z, a) : (u32, String), ex: X) {
235 println(&yy.to_string());
236 let (x, y): (u32, u32) = (5, 3);
237 println(&x.to_string());
238 println(&z.to_string());
240 println(&x.to_string());
245 let _ = (x + ((x * x) + 1.0).sqrt()).ln();
247 let s: Box<SomeTrait> = box some_fields {field1: 43};
248 let s2: Box<some_fields> = box some_fields {field1: 43};
249 let s3 = box nofields;
258 // static method on struct
259 let r = some_fields::stat(y);
260 // trait static method, calls override
261 let r = SubTrait::stat2(&*s2);
262 // trait static method, calls default
263 let r = SubTrait::stat2(&*s3);
265 let s4 = s3 as Box<SomeTrait>;
268 s4.provided_method();
271 let closure = |x: u32, s: &SomeTrait| {
276 let z = closure(10, &*s);
280 used_link_args: RefCell<[&'static str; 0]>,
284 let s = box some_fields {field1: 43};
285 hello((43, "a".to_string()), *s);
289 let h = sub2::sub3::hello;
293 let ut = "Les Miséééééééérables";
295 // For some reason, this pattern of macro_rules foiled our generated code
296 // avoiding strategy.
297 macro_rules! variable_str(($name:expr) => (
302 let vs = variable_str!(32);
304 let mut candidates: RefCell<HashMap<&'static str, &'static str>> = RefCell::new(HashMap::new());
306 used_link_args: RefCell::new([]),
309 let s2 = SF { field1: 55};
310 let s3: some_fields = some_fields{ field1: 55};
311 let s4: msalias::nested_struct = sub::sub2::nested_struct{ field2: 55};
312 let s4: msalias::nested_struct = sub2::nested_struct{ field2: 55};
313 println(&s2.field1.to_string());
314 let s5: MyType = box some_fields{ field1: 55};
315 let s = SameDir::SameStruct{name: "Bob".to_string()};
316 let s = SubDir::SubStruct{name:"Bob".to_string()};
317 let s6: SomeEnum = SomeEnum::MyTypes(box s2.clone(), s5);
318 let s7: SomeEnum = SomeEnum::Strings("one", "two", "three");
321 let s8: SomeOtherEnum = SomeOtherEnum::SomeConst2;
322 matchSomeOtherEnum(s8);
323 let s9: SomeStructEnum =
324 SomeStructEnum::EnumStruct2{f1: box some_fields{field1:10}, f2: box s2};
325 matchSomeStructEnum(s9);
328 impl Iterator for nofields {
329 type Item = (usize, usize);
331 fn next(&mut self) -> Option<(usize, usize)> {
335 fn size_hint(&self) -> (usize, Option<usize>) {