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);
61 const LUT_BITS: usize = 3;
62 pub struct HuffmanTable {
63 ac_lut: Option<[(i16, u8); 1 << LUT_BITS]>,
66 struct TupStruct(isize, isize, Box<str>);
68 fn test_tup_struct(x: TupStruct) -> isize {
73 std::io::stdout().write_all(s.as_bytes());
82 ::println("hello from module 3");
86 ::println("hello from a module");
89 pub struct nested_struct {
93 pub enum nested_enum {
103 #[path = "SameDir3.rs"]
113 type SF = some_fields;
116 fn qux(&self) { panic!(); }
119 trait SomeTrait: SuperTrait {
120 fn Method(&self, x: u32) -> u32;
122 fn prov(&self, x: u32) -> u32 {
123 println(&x.to_string());
126 fn provided_method(&self) -> u32 {
131 trait SubTrait: SomeTrait {
132 fn stat2(x: &Self) -> u32 {
137 trait SizedTrait: Sized {}
139 fn error(s: &SizedTrait) {
141 println!("Hello world! {}", foo);
144 impl SomeTrait for some_fields {
145 fn Method(&self, x: u32) -> u32 {
146 println(&x.to_string());
151 impl SuperTrait for some_fields {
154 impl SubTrait for some_fields {}
157 fn stat(x: u32) -> u32 {
158 println(&x.to_string());
161 fn stat2(x: &some_fields) -> u32 {
165 fn align_to<T>(&mut self) {
170 self.align_to::<bool>();
174 impl SuperTrait for nofields {
176 impl SomeTrait for nofields {
177 fn Method(&self, x: u32) -> u32 {
182 fn provided_method(&self) -> u32 {
187 impl SubTrait for nofields {}
189 impl SuperTrait for (Box<nofields>, Box<some_fields>) {}
191 fn f_with_params<T: SomeTrait>(x: &T) {
195 type MyType = Box<some_fields>;
200 Strings(&'a str, &'a str, &'a str),
201 MyTypes(MyType, MyType)
204 #[derive(Copy, Clone)]
211 enum SomeStructEnum {
212 EnumStruct{a:isize, b:isize},
213 EnumStruct2{f1:MyType, f2:MyType},
214 EnumStruct3{f1:MyType, f2:MyType, f3:SomeEnum<'static>}
217 fn matchSomeEnum(val: SomeEnum) {
219 SomeEnum::Ints(int1, int2) => { println(&(int1+int2).to_string()); }
220 SomeEnum::Floats(float1, float2) => { println(&(float2*float1).to_string()); }
221 SomeEnum::Strings(.., s3) => { println(s3); }
222 SomeEnum::MyTypes(mt1, mt2) => { println(&(mt1.field1 - mt2.field1).to_string()); }
226 fn matchSomeStructEnum(se: SomeStructEnum) {
228 SomeStructEnum::EnumStruct{a:a, ..} => println(&a.to_string()),
229 SomeStructEnum::EnumStruct2{f1:f1, f2:f_2} => println(&f_2.field1.to_string()),
230 SomeStructEnum::EnumStruct3{f1, ..} => println(&f1.field1.to_string()),
235 fn matchSomeStructEnum2(se: SomeStructEnum) {
236 use SomeStructEnum::*;
238 EnumStruct{a: ref aaa, ..} => println(&aaa.to_string()),
239 EnumStruct2{f1, f2: f2} => println(&f1.field1.to_string()),
240 EnumStruct3{f1, f3: SomeEnum::Ints(..), f2} => println(&f1.field1.to_string()),
245 fn matchSomeOtherEnum(val: SomeOtherEnum) {
246 use SomeOtherEnum::{SomeConst2, SomeConst3};
248 SomeOtherEnum::SomeConst1 => { println("I'm const1."); }
249 SomeConst2 | SomeConst3 => { println("I'm const2 or const3."); }
253 fn hello<X: SomeTrait>((z, a) : (u32, String), ex: X) {
256 println(&yy.to_string());
257 let (x, y): (u32, u32) = (5, 3);
258 println(&x.to_string());
259 println(&z.to_string());
261 println(&x.to_string());
266 let _ = (x + ((x * x) + 1.0).sqrt()).ln();
268 let s: Box<SomeTrait> = box some_fields {field1: 43};
269 let s2: Box<some_fields> = box some_fields {field1: 43};
270 let s3 = box nofields;
279 // static method on struct
280 let r = some_fields::stat(y);
281 // trait static method, calls default
282 let r = SubTrait::stat2(&*s3);
284 let s4 = s3 as Box<SomeTrait>;
287 s4.provided_method();
290 let closure = |x: u32, s: &SomeTrait| {
295 let z = closure(10, &*s);
299 used_link_args: RefCell<[&'static str; 0]>,
304 macro_rules! test_rec {
305 (q, $src: expr) => {{
314 macro_rules! internal_vars {
323 let s = box some_fields {field1: 43};
324 hello((43, "a".to_string()), *s);
328 let h = sub2::sub3::hello;
332 let ut = "Les Miséééééééérables";
334 // For some reason, this pattern of macro_rules foiled our generated code
335 // avoiding strategy.
336 macro_rules! variable_str(($name:expr) => (
341 let vs = variable_str!(32);
343 let mut candidates: RefCell<HashMap<&'static str, &'static str>> = RefCell::new(HashMap::new());
345 used_link_args: RefCell::new([]),
348 let s2 = SF { field1: 55};
349 let s3: some_fields = some_fields{ field1: 55};
350 let s4: msalias::nested_struct = sub::sub2::nested_struct{ field2: 55};
351 let s4: msalias::nested_struct = sub2::nested_struct{ field2: 55};
352 println(&s2.field1.to_string());
353 let s5: MyType = box some_fields{ field1: 55};
354 let s = SameDir::SameStruct{name: "Bob".to_string()};
355 let s = SubDir::SubStruct{name:"Bob".to_string()};
356 let s6: SomeEnum = SomeEnum::MyTypes(box s2.clone(), s5);
357 let s7: SomeEnum = SomeEnum::Strings("one", "two", "three");
360 let s8: SomeOtherEnum = SomeOtherEnum::SomeConst2;
361 matchSomeOtherEnum(s8);
362 let s9: SomeStructEnum = SomeStructEnum::EnumStruct2{ f1: box some_fields{ field1:10 },
364 matchSomeStructEnum(s9);
366 for x in &vec![1, 2, 3] {
370 let s7: SomeEnum = SomeEnum::Strings("one", "two", "three");
371 if let SomeEnum::Strings(..) = s7 {
379 if let Some(x) = None {
384 } else if let Some(y) = None {
388 while let Some(z) = None {
393 test_rec!(q, "Hello");
398 fn foo_foo(_: i32) {}
400 impl Iterator for nofields {
401 type Item = (usize, usize);
403 fn next(&mut self) -> Option<(usize, usize)> {
407 fn size_hint(&self) -> (usize, Option<usize>) {
416 struct CharEqPattern;
418 impl<'a> Pattern<'a> for CharEqPattern {
419 type Searcher = CharEqPattern;
422 struct CharSearcher<'a>(<CharEqPattern as Pattern<'a>>::Searcher);
427 impl Error + 'static {
428 pub fn is<T: Error + 'static>(&self) -> bool {
433 impl Error + 'static + Send {
434 pub fn is<T: Error + 'static>(&self) -> bool {
435 <Error + 'static>::is::<T>(self)
438 extern crate serialize;
439 #[derive(Clone, Copy, Hash, Encodable, Decodable, PartialEq, Eq, PartialOrd, Ord, Debug, Default)]
440 struct AllDerives(i32);
442 fn test_format_args() {
445 let name = "Joe Blogg";
446 println!("Hello {}", name);
447 print!("Hello {0}", name);
448 print!("{0} + {} = {}", x, y);
449 print!("x is {}, y is {1}, name is {n}", x, y, n = name);