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)]
15 extern crate graphviz;
16 // A simple rust project
19 extern crate krate2 as krate3;
20 extern crate flate as myflate;
22 use graphviz::RenderOption;
23 use std::collections::{HashMap,HashSet};
24 use std::cell::RefCell;
28 use sub::sub2 as msalias;
30 use sub::sub2::nested_struct as sub_struct;
32 use std::mem::size_of;
34 use std::char::from_u32;
36 static uni: &'static str = "Les Miséééééééérables";
37 static yy: usize = 25;
39 static bob: Option<graphviz::RenderOption> = None;
41 // buglink test - see issue #1337.
43 fn test_alias<I: Iterator>(i: Option<<I as Iterator>::Item>) {
44 let s = sub_struct{ field2: 45u32, };
48 let _: Option<_> = from_u32(45);
54 myflate::deflate_bytes(&[]);
56 let x = (3isize, 4usize);
60 struct TupStruct(isize, isize, Box<str>);
62 fn test_tup_struct(x: TupStruct) -> isize {
67 std::io::stdout().write_all(s.as_bytes());
76 ::println("hello from module 3");
80 ::println("hello from a module");
83 pub struct nested_struct {
87 pub enum nested_enum {
97 #[path = "SameDir3.rs"]
107 type SF = some_fields;
110 fn qux(&self) { panic!(); }
113 trait SomeTrait: SuperTrait {
114 fn Method(&self, x: u32) -> u32;
116 fn prov(&self, x: u32) -> u32 {
117 println(&x.to_string());
120 fn provided_method(&self) -> u32 {
125 trait SubTrait: SomeTrait {
126 fn stat2(x: &Self) -> u32 {
131 impl SomeTrait for some_fields {
132 fn Method(&self, x: u32) -> u32 {
133 println(&x.to_string());
138 impl SuperTrait for some_fields {
141 impl SubTrait for some_fields {}
144 fn stat(x: u32) -> u32 {
145 println(&x.to_string());
148 fn stat2(x: &some_fields) -> u32 {
152 fn align_to<T>(&mut self) {
157 self.align_to::<bool>();
161 impl SuperTrait for nofields {
163 impl SomeTrait for nofields {
164 fn Method(&self, x: u32) -> u32 {
169 fn provided_method(&self) -> u32 {
174 impl SubTrait for nofields {}
176 impl SuperTrait for (Box<nofields>, Box<some_fields>) {}
178 fn f_with_params<T: SomeTrait>(x: &T) {
182 type MyType = Box<some_fields>;
187 Strings(&'a str, &'a str, &'a str),
188 MyTypes(MyType, MyType)
191 #[derive(Copy, Clone)]
198 enum SomeStructEnum {
199 EnumStruct{a:isize, b:isize},
200 EnumStruct2{f1:MyType, f2:MyType},
201 EnumStruct3{f1:MyType, f2:MyType, f3:SomeEnum<'static>}
204 fn matchSomeEnum(val: SomeEnum) {
206 SomeEnum::Ints(int1, int2) => { println(&(int1+int2).to_string()); }
207 SomeEnum::Floats(float1, float2) => { println(&(float2*float1).to_string()); }
208 SomeEnum::Strings(.., s3) => { println(s3); }
209 SomeEnum::MyTypes(mt1, mt2) => { println(&(mt1.field1 - mt2.field1).to_string()); }
213 fn matchSomeStructEnum(se: SomeStructEnum) {
215 SomeStructEnum::EnumStruct{a:a, ..} => println(&a.to_string()),
216 SomeStructEnum::EnumStruct2{f1:f1, f2:f_2} => println(&f_2.field1.to_string()),
217 SomeStructEnum::EnumStruct3{f1, ..} => println(&f1.field1.to_string()),
222 fn matchSomeStructEnum2(se: SomeStructEnum) {
223 use SomeStructEnum::*;
225 EnumStruct{a: ref aaa, ..} => println(&aaa.to_string()),
226 EnumStruct2{f1, f2: f2} => println(&f1.field1.to_string()),
227 EnumStruct3{f1, f3: SomeEnum::Ints(..), f2} => println(&f1.field1.to_string()),
232 fn matchSomeOtherEnum(val: SomeOtherEnum) {
233 use SomeOtherEnum::{SomeConst2, SomeConst3};
235 SomeOtherEnum::SomeConst1 => { println("I'm const1."); }
236 SomeConst2 | SomeConst3 => { println("I'm const2 or const3."); }
240 fn hello<X: SomeTrait>((z, a) : (u32, String), ex: X) {
243 println(&yy.to_string());
244 let (x, y): (u32, u32) = (5, 3);
245 println(&x.to_string());
246 println(&z.to_string());
248 println(&x.to_string());
253 let _ = (x + ((x * x) + 1.0).sqrt()).ln();
255 let s: Box<SomeTrait> = box some_fields {field1: 43};
256 let s2: Box<some_fields> = box some_fields {field1: 43};
257 let s3 = box nofields;
266 // static method on struct
267 let r = some_fields::stat(y);
268 // trait static method, calls default
269 let r = SubTrait::stat2(&*s3);
271 let s4 = s3 as Box<SomeTrait>;
274 s4.provided_method();
277 let closure = |x: u32, s: &SomeTrait| {
282 let z = closure(10, &*s);
286 used_link_args: RefCell<[&'static str; 0]>,
291 macro_rules! test_rec {
292 (q, $src: expr) => {{
301 macro_rules! internal_vars {
310 let s = box some_fields {field1: 43};
311 hello((43, "a".to_string()), *s);
315 let h = sub2::sub3::hello;
319 let ut = "Les Miséééééééérables";
321 // For some reason, this pattern of macro_rules foiled our generated code
322 // avoiding strategy.
323 macro_rules! variable_str(($name:expr) => (
328 let vs = variable_str!(32);
330 let mut candidates: RefCell<HashMap<&'static str, &'static str>> = RefCell::new(HashMap::new());
332 used_link_args: RefCell::new([]),
335 let s2 = SF { field1: 55};
336 let s3: some_fields = some_fields{ field1: 55};
337 let s4: msalias::nested_struct = sub::sub2::nested_struct{ field2: 55};
338 let s4: msalias::nested_struct = sub2::nested_struct{ field2: 55};
339 println(&s2.field1.to_string());
340 let s5: MyType = box some_fields{ field1: 55};
341 let s = SameDir::SameStruct{name: "Bob".to_string()};
342 let s = SubDir::SubStruct{name:"Bob".to_string()};
343 let s6: SomeEnum = SomeEnum::MyTypes(box s2.clone(), s5);
344 let s7: SomeEnum = SomeEnum::Strings("one", "two", "three");
347 let s8: SomeOtherEnum = SomeOtherEnum::SomeConst2;
348 matchSomeOtherEnum(s8);
349 let s9: SomeStructEnum = SomeStructEnum::EnumStruct2{ f1: box some_fields{ field1:10 },
351 matchSomeStructEnum(s9);
353 for x in &vec![1, 2, 3] {
357 let s7: SomeEnum = SomeEnum::Strings("one", "two", "three");
358 if let SomeEnum::Strings(..) = s7 {
366 if let Some(x) = None {
371 } else if let Some(y) = None {
375 while let Some(z) = None {
380 test_rec!(q, "Hello");
385 fn foo_foo(_: i32) {}
387 impl Iterator for nofields {
388 type Item = (usize, usize);
390 fn next(&mut self) -> Option<(usize, usize)> {
394 fn size_hint(&self) -> (usize, Option<usize>) {
403 struct CharEqPattern;
405 impl<'a> Pattern<'a> for CharEqPattern {
406 type Searcher = CharEqPattern;
409 struct CharSearcher<'a>(<CharEqPattern as Pattern<'a>>::Searcher);
414 impl Error + 'static {
415 pub fn is<T: Error + 'static>(&self) -> bool {
420 impl Error + 'static + Send {
421 pub fn is<T: Error + 'static>(&self) -> bool {
422 <Error + 'static>::is::<T>(self)
425 extern crate serialize;
426 #[derive(Clone, Copy, Hash, Encodable, Decodable, PartialEq, Eq, PartialOrd, Ord, Debug, Default)]
427 struct AllDerives(i32);
429 fn test_format_args() {
432 let name = "Joe Blogg";
433 println!("Hello {}", name);
434 print!("Hello {0}", name);
435 print!("{0} + {} = {}", x, y);
436 print!("x is {}, y is {1}, name is {n}", x, y, n = name);