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;
21 use graphviz::RenderOption;
22 use std::collections::{HashMap,HashSet};
23 use std::cell::RefCell;
27 use sub::sub2 as msalias;
29 use sub::sub2::nested_struct as sub_struct;
31 use std::mem::size_of;
33 use std::char::from_u32;
35 static uni: &'static str = "Les Miséééééééérables";
36 static yy: usize = 25;
38 static bob: Option<graphviz::RenderOption> = 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<_> = from_u32(45);
54 let x = (3isize, 4usize);
59 const LUT_BITS: usize = 3;
60 pub struct HuffmanTable {
61 ac_lut: Option<[(i16, u8); 1 << LUT_BITS]>,
64 struct TupStruct(isize, isize, Box<str>);
66 fn test_tup_struct(x: TupStruct) -> isize {
71 std::io::stdout().write_all(s.as_bytes());
80 ::println("hello from module 3");
84 ::println("hello from a module");
87 pub struct nested_struct {
91 pub enum nested_enum {
101 #[path = "SameDir3.rs"]
111 type SF = some_fields;
114 fn qux(&self) { panic!(); }
117 trait SomeTrait: SuperTrait {
118 fn Method(&self, x: u32) -> u32;
120 fn prov(&self, x: u32) -> u32 {
121 println(&x.to_string());
124 fn provided_method(&self) -> u32 {
129 trait SubTrait: SomeTrait {
130 fn stat2(x: &Self) -> u32 {
135 trait SizedTrait: Sized {}
137 fn error(s: &SizedTrait) {
139 println!("Hello world! {}", foo);
142 impl SomeTrait for some_fields {
143 fn Method(&self, x: u32) -> u32 {
144 println(&x.to_string());
149 impl SuperTrait for some_fields {
152 impl SubTrait for some_fields {}
155 fn stat(x: u32) -> u32 {
156 println(&x.to_string());
159 fn stat2(x: &some_fields) -> u32 {
163 fn align_to<T>(&mut self) {
168 self.align_to::<bool>();
172 impl SuperTrait for nofields {
174 impl SomeTrait for nofields {
175 fn Method(&self, x: u32) -> u32 {
180 fn provided_method(&self) -> u32 {
185 impl SubTrait for nofields {}
187 impl SuperTrait for (Box<nofields>, Box<some_fields>) {}
189 fn f_with_params<T: SomeTrait>(x: &T) {
193 type MyType = Box<some_fields>;
198 Strings(&'a str, &'a str, &'a str),
199 MyTypes(MyType, MyType)
202 #[derive(Copy, Clone)]
209 enum SomeStructEnum {
210 EnumStruct{a:isize, b:isize},
211 EnumStruct2{f1:MyType, f2:MyType},
212 EnumStruct3{f1:MyType, f2:MyType, f3:SomeEnum<'static>}
215 fn matchSomeEnum(val: SomeEnum) {
217 SomeEnum::Ints(int1, int2) => { println(&(int1+int2).to_string()); }
218 SomeEnum::Floats(float1, float2) => { println(&(float2*float1).to_string()); }
219 SomeEnum::Strings(.., s3) => { println(s3); }
220 SomeEnum::MyTypes(mt1, mt2) => { println(&(mt1.field1 - mt2.field1).to_string()); }
224 fn matchSomeStructEnum(se: SomeStructEnum) {
226 SomeStructEnum::EnumStruct{a:a, ..} => println(&a.to_string()),
227 SomeStructEnum::EnumStruct2{f1:f1, f2:f_2} => println(&f_2.field1.to_string()),
228 SomeStructEnum::EnumStruct3{f1, ..} => println(&f1.field1.to_string()),
233 fn matchSomeStructEnum2(se: SomeStructEnum) {
234 use SomeStructEnum::*;
236 EnumStruct{a: ref aaa, ..} => println(&aaa.to_string()),
237 EnumStruct2{f1, f2: f2} => println(&f1.field1.to_string()),
238 EnumStruct3{f1, f3: SomeEnum::Ints(..), f2} => println(&f1.field1.to_string()),
243 fn matchSomeOtherEnum(val: SomeOtherEnum) {
244 use SomeOtherEnum::{SomeConst2, SomeConst3};
246 SomeOtherEnum::SomeConst1 => { println("I'm const1."); }
247 SomeConst2 | SomeConst3 => { println("I'm const2 or const3."); }
251 fn hello<X: SomeTrait>((z, a) : (u32, String), ex: X) {
254 println(&yy.to_string());
255 let (x, y): (u32, u32) = (5, 3);
256 println(&x.to_string());
257 println(&z.to_string());
259 println(&x.to_string());
264 let _ = (x + ((x * x) + 1.0).sqrt()).ln();
266 let s: Box<SomeTrait> = box some_fields {field1: 43};
267 let s2: Box<some_fields> = box some_fields {field1: 43};
268 let s3 = box nofields;
277 // static method on struct
278 let r = some_fields::stat(y);
279 // trait static method, calls default
280 let r = SubTrait::stat2(&*s3);
282 let s4 = s3 as Box<SomeTrait>;
285 s4.provided_method();
288 let closure = |x: u32, s: &SomeTrait| {
293 let z = closure(10, &*s);
297 used_link_args: RefCell<[&'static str; 0]>,
302 macro_rules! test_rec {
303 (q, $src: expr) => {{
312 macro_rules! internal_vars {
321 let s = box some_fields {field1: 43};
322 hello((43, "a".to_string()), *s);
326 let h = sub2::sub3::hello;
330 let ut = "Les Miséééééééérables";
332 // For some reason, this pattern of macro_rules foiled our generated code
333 // avoiding strategy.
334 macro_rules! variable_str(($name:expr) => (
339 let vs = variable_str!(32);
341 let mut candidates: RefCell<HashMap<&'static str, &'static str>> = RefCell::new(HashMap::new());
343 used_link_args: RefCell::new([]),
346 let s2 = SF { field1: 55};
347 let s3: some_fields = some_fields{ field1: 55};
348 let s4: msalias::nested_struct = sub::sub2::nested_struct{ field2: 55};
349 let s4: msalias::nested_struct = sub2::nested_struct{ field2: 55};
350 println(&s2.field1.to_string());
351 let s5: MyType = box some_fields{ field1: 55};
352 let s = SameDir::SameStruct{name: "Bob".to_string()};
353 let s = SubDir::SubStruct{name:"Bob".to_string()};
354 let s6: SomeEnum = SomeEnum::MyTypes(box s2.clone(), s5);
355 let s7: SomeEnum = SomeEnum::Strings("one", "two", "three");
358 let s8: SomeOtherEnum = SomeOtherEnum::SomeConst2;
359 matchSomeOtherEnum(s8);
360 let s9: SomeStructEnum = SomeStructEnum::EnumStruct2{ f1: box some_fields{ field1:10 },
362 matchSomeStructEnum(s9);
364 for x in &vec![1, 2, 3] {
368 let s7: SomeEnum = SomeEnum::Strings("one", "two", "three");
369 if let SomeEnum::Strings(..) = s7 {
377 if let Some(x) = None {
382 } else if let Some(y) = None {
386 while let Some(z) = None {
391 test_rec!(q, "Hello");
396 fn foo_foo(_: i32) {}
398 impl Iterator for nofields {
399 type Item = (usize, usize);
401 fn next(&mut self) -> Option<(usize, usize)> {
405 fn size_hint(&self) -> (usize, Option<usize>) {
414 struct CharEqPattern;
416 impl<'a> Pattern<'a> for CharEqPattern {
417 type Searcher = CharEqPattern;
420 struct CharSearcher<'a>(<CharEqPattern as Pattern<'a>>::Searcher);
425 impl Error + 'static {
426 pub fn is<T: Error + 'static>(&self) -> bool {
431 impl Error + 'static + Send {
432 pub fn is<T: Error + 'static>(&self) -> bool {
433 <Error + 'static>::is::<T>(self)
436 extern crate serialize;
437 #[derive(Clone, Copy, Hash, Encodable, Decodable, PartialEq, Eq, PartialOrd, Ord, Debug, Default)]
438 struct AllDerives(i32);
440 fn test_format_args() {
443 let name = "Joe Blogg";
444 println!("Hello {}", name);
445 print!("Hello {0}", name);
446 print!("{0} + {} = {}", x, y);
447 print!("x is {}, y is {1}, name is {n}", x, y, n = name);
451 static EXTERN_FOO: u8;
452 fn extern_foo(a: u8, b: i32) -> String;
459 fn new(f: u32) -> Rls699 {