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" ]
12 #![feature(box_syntax)]
13 #![feature(rustc_private)]
16 extern crate graphviz;
17 // A simple rust project
20 extern crate krate2 as krate3;
21 extern crate flate as myflate;
23 use graphviz::RenderOption;
24 use std::collections::{HashMap,HashSet};
25 use std::cell::RefCell;
29 use sub::sub2 as msalias;
31 use sub::sub2::nested_struct as sub_struct;
33 use std::mem::size_of;
35 use std::char::from_u32;
37 static uni: &'static str = "Les Miséééééééérables";
38 static yy: usize = 25;
40 static bob: Option<graphviz::RenderOption> = None;
42 // buglink test - see issue #1337.
44 fn test_alias<I: Iterator>(i: Option<<I as Iterator>::Item>) {
45 let s = sub_struct{ field2: 45u32, };
49 let _: Option<_> = from_u32(45);
55 myflate::deflate_bytes(&[]);
57 let x = (3isize, 4usize);
61 struct TupStruct(isize, isize, Box<str>);
63 fn test_tup_struct(x: TupStruct) -> isize {
68 std::io::stdout().write_all(s.as_bytes());
77 ::println("hello from module 3");
81 ::println("hello from a module");
84 pub struct nested_struct {
88 pub enum nested_enum {
98 #[path = "SameDir3.rs"]
108 type SF = some_fields;
111 fn qux(&self) { panic!(); }
114 trait SomeTrait: SuperTrait {
115 fn Method(&self, x: u32) -> u32;
117 fn prov(&self, x: u32) -> u32 {
118 println(&x.to_string());
121 fn provided_method(&self) -> u32 {
126 trait SubTrait: SomeTrait {
127 fn stat2(x: &Self) -> u32 {
132 impl SomeTrait for some_fields {
133 fn Method(&self, x: u32) -> u32 {
134 println(&x.to_string());
139 impl SuperTrait for some_fields {
142 impl SubTrait for some_fields {}
145 fn stat(x: u32) -> u32 {
146 println(&x.to_string());
149 fn stat2(x: &some_fields) -> u32 {
153 fn align_to<T>(&mut self) {
158 self.align_to::<bool>();
162 impl SuperTrait for nofields {
164 impl SomeTrait for nofields {
165 fn Method(&self, x: u32) -> u32 {
170 fn provided_method(&self) -> u32 {
175 impl SubTrait for nofields {}
177 impl SuperTrait for (Box<nofields>, Box<some_fields>) {}
179 fn f_with_params<T: SomeTrait>(x: &T) {
183 type MyType = Box<some_fields>;
188 Strings(&'a str, &'a str, &'a str),
189 MyTypes(MyType, MyType)
192 #[derive(Copy, Clone)]
199 enum SomeStructEnum {
200 EnumStruct{a:isize, b:isize},
201 EnumStruct2{f1:MyType, f2:MyType},
202 EnumStruct3{f1:MyType, f2:MyType, f3:SomeEnum<'static>}
205 fn matchSomeEnum(val: SomeEnum) {
207 SomeEnum::Ints(int1, int2) => { println(&(int1+int2).to_string()); }
208 SomeEnum::Floats(float1, float2) => { println(&(float2*float1).to_string()); }
209 SomeEnum::Strings(_, _, s3) => { println(s3); }
210 SomeEnum::MyTypes(mt1, mt2) => { println(&(mt1.field1 - mt2.field1).to_string()); }
214 fn matchSomeStructEnum(se: SomeStructEnum) {
216 SomeStructEnum::EnumStruct{a:a, ..} => println(&a.to_string()),
217 SomeStructEnum::EnumStruct2{f1:f1, f2:f_2} => println(&f_2.field1.to_string()),
218 SomeStructEnum::EnumStruct3{f1, ..} => println(&f1.field1.to_string()),
223 fn matchSomeStructEnum2(se: SomeStructEnum) {
224 use SomeStructEnum::*;
226 EnumStruct{a: ref aaa, ..} => println(&aaa.to_string()),
227 EnumStruct2{f1, f2: f2} => println(&f1.field1.to_string()),
228 EnumStruct3{f1, f3: SomeEnum::Ints(_, _), f2} => println(&f1.field1.to_string()),
233 fn matchSomeOtherEnum(val: SomeOtherEnum) {
234 use SomeOtherEnum::{SomeConst2, SomeConst3};
236 SomeOtherEnum::SomeConst1 => { println("I'm const1."); }
237 SomeConst2 | SomeConst3 => { println("I'm const2 or const3."); }
241 fn hello<X: SomeTrait>((z, a) : (u32, String), ex: X) {
244 println(&yy.to_string());
245 let (x, y): (u32, u32) = (5, 3);
246 println(&x.to_string());
247 println(&z.to_string());
249 println(&x.to_string());
254 let _ = (x + ((x * x) + 1.0).sqrt()).ln();
256 let s: Box<SomeTrait> = box some_fields {field1: 43};
257 let s2: Box<some_fields> = box some_fields {field1: 43};
258 let s3 = box nofields;
267 // static method on struct
268 let r = some_fields::stat(y);
269 // trait static method, calls default
270 let r = SubTrait::stat2(&*s3);
272 let s4 = s3 as Box<SomeTrait>;
275 s4.provided_method();
278 let closure = |x: u32, s: &SomeTrait| {
283 let z = closure(10, &*s);
287 used_link_args: RefCell<[&'static str; 0]>,
291 let s = box some_fields {field1: 43};
292 hello((43, "a".to_string()), *s);
296 let h = sub2::sub3::hello;
300 let ut = "Les Miséééééééérables";
302 // For some reason, this pattern of macro_rules foiled our generated code
303 // avoiding strategy.
304 macro_rules! variable_str(($name:expr) => (
309 let vs = variable_str!(32);
311 let mut candidates: RefCell<HashMap<&'static str, &'static str>> = RefCell::new(HashMap::new());
313 used_link_args: RefCell::new([]),
316 let s2 = SF { field1: 55};
317 let s3: some_fields = some_fields{ field1: 55};
318 let s4: msalias::nested_struct = sub::sub2::nested_struct{ field2: 55};
319 let s4: msalias::nested_struct = sub2::nested_struct{ field2: 55};
320 println(&s2.field1.to_string());
321 let s5: MyType = box some_fields{ field1: 55};
322 let s = SameDir::SameStruct{name: "Bob".to_string()};
323 let s = SubDir::SubStruct{name:"Bob".to_string()};
324 let s6: SomeEnum = SomeEnum::MyTypes(box s2.clone(), s5);
325 let s7: SomeEnum = SomeEnum::Strings("one", "two", "three");
328 let s8: SomeOtherEnum = SomeOtherEnum::SomeConst2;
329 matchSomeOtherEnum(s8);
330 let s9: SomeStructEnum = SomeStructEnum::EnumStruct2{ f1: box some_fields{ field1:10 },
332 matchSomeStructEnum(s9);
334 for x in &vec![1, 2, 3] {
338 let s7: SomeEnum = SomeEnum::Strings("one", "two", "three");
339 if let SomeEnum::Strings(..) = s7 {
344 impl Iterator for nofields {
345 type Item = (usize, usize);
347 fn next(&mut self) -> Option<(usize, usize)> {
351 fn size_hint(&self) -> (usize, Option<usize>) {