1 #![ crate_name = "test" ]
2 #![feature(box_syntax)]
3 #![feature(rustc_private)]
4 #![feature(associated_type_defaults)]
5 #![feature(external_doc)]
8 // A simple rust project
11 extern crate krate2 as krate3;
13 use graphviz::RenderOption;
14 use std::collections::{HashMap,HashSet};
15 use std::cell::RefCell;
19 use sub::sub2 as msalias;
21 use sub::sub2::nested_struct as sub_struct;
23 use std::mem::size_of;
25 use std::char::from_u32;
27 static uni: &'static str = "Les Miséééééééérables";
28 static yy: usize = 25;
30 static bob: Option<graphviz::RenderOption> = None;
32 // buglink test - see issue #1337.
34 fn test_alias<I: Iterator>(i: Option<<I as Iterator>::Item>) {
35 let s = sub_struct{ field2: 45u32, };
39 let _: Option<_> = from_u32(45);
46 let x = (3isize, 4usize);
51 const LUT_BITS: usize = 3;
52 pub struct HuffmanTable {
53 ac_lut: Option<[(i16, u8); 1 << LUT_BITS]>,
56 struct TupStruct(isize, isize, Box<str>);
58 fn test_tup_struct(x: TupStruct) -> isize {
63 std::io::stdout().write_all(s.as_bytes());
72 ::println("hello from module 3");
76 ::println("hello from a module");
79 pub struct nested_struct {
83 pub enum nested_enum {
93 #[path = "SameDir3.rs"]
103 type SF = some_fields;
106 fn qux(&self) { panic!(); }
109 trait SomeTrait: SuperTrait {
110 fn Method(&self, x: u32) -> u32;
112 fn prov(&self, x: u32) -> u32 {
113 println(&x.to_string());
116 fn provided_method(&self) -> u32 {
121 trait SubTrait: SomeTrait {
122 fn stat2(x: &Self) -> u32 {
127 impl SomeTrait for some_fields {
128 fn Method(&self, x: u32) -> u32 {
129 println(&x.to_string());
134 impl SuperTrait for some_fields {
137 impl SubTrait for some_fields {}
140 fn stat(x: u32) -> u32 {
141 println(&x.to_string());
144 fn stat2(x: &some_fields) -> u32 {
148 fn align_to<T>(&mut self) {
153 self.align_to::<bool>();
157 impl SuperTrait for nofields {
159 impl SomeTrait for nofields {
160 fn Method(&self, x: u32) -> u32 {
165 fn provided_method(&self) -> u32 {
170 impl SubTrait for nofields {}
172 impl SuperTrait for (Box<nofields>, Box<some_fields>) {}
174 fn f_with_params<T: SomeTrait>(x: &T) {
178 type MyType = Box<some_fields>;
183 Strings(&'a str, &'a str, &'a str),
184 MyTypes(MyType, MyType)
187 #[derive(Copy, Clone)]
194 enum SomeStructEnum {
195 EnumStruct{a:isize, b:isize},
196 EnumStruct2{f1:MyType, f2:MyType},
197 EnumStruct3{f1:MyType, f2:MyType, f3:SomeEnum<'static>}
200 fn matchSomeEnum(val: SomeEnum) {
202 SomeEnum::Ints(int1, int2) => { println(&(int1+int2).to_string()); }
203 SomeEnum::Floats(float1, float2) => { println(&(float2*float1).to_string()); }
204 SomeEnum::Strings(.., s3) => { println(s3); }
205 SomeEnum::MyTypes(mt1, mt2) => { println(&(mt1.field1 - mt2.field1).to_string()); }
209 fn matchSomeStructEnum(se: SomeStructEnum) {
211 SomeStructEnum::EnumStruct{a:a, ..} => println(&a.to_string()),
212 SomeStructEnum::EnumStruct2{f1:f1, f2:f_2} => println(&f_2.field1.to_string()),
213 SomeStructEnum::EnumStruct3{f1, ..} => println(&f1.field1.to_string()),
218 fn matchSomeStructEnum2(se: SomeStructEnum) {
219 use SomeStructEnum::*;
221 EnumStruct{a: ref aaa, ..} => println(&aaa.to_string()),
222 EnumStruct2{f1, f2: f2} => println(&f1.field1.to_string()),
223 EnumStruct3{f1, f3: SomeEnum::Ints(..), f2} => println(&f1.field1.to_string()),
228 fn matchSomeOtherEnum(val: SomeOtherEnum) {
229 use SomeOtherEnum::{SomeConst2, SomeConst3};
231 SomeOtherEnum::SomeConst1 => { println("I'm const1."); }
232 SomeConst2 | SomeConst3 => { println("I'm const2 or const3."); }
236 fn hello<X: SomeTrait>((z, a) : (u32, String), ex: X) {
239 println(&yy.to_string());
240 let (x, y): (u32, u32) = (5, 3);
241 println(&x.to_string());
242 println(&z.to_string());
244 println(&x.to_string());
249 let _ = (x + ((x * x) + 1.0).sqrt()).ln();
251 let s: Box<SomeTrait> = box some_fields {field1: 43};
252 let s2: Box<some_fields> = box some_fields {field1: 43};
253 let s3 = box nofields;
262 // static method on struct
263 let r = some_fields::stat(y);
264 // trait static method, calls default
265 let r = SubTrait::stat2(&*s3);
267 let s4 = s3 as Box<SomeTrait>;
270 s4.provided_method();
273 let closure = |x: u32, s: &SomeTrait| {
278 let z = closure(10, &*s);
282 used_link_args: RefCell<[&'static str; 0]>,
287 macro_rules! test_rec {
288 (q, $src: expr) => {{
297 macro_rules! internal_vars {
306 let s = box some_fields {field1: 43};
307 hello((43, "a".to_string()), *s);
311 let h = sub2::sub3::hello;
315 let ut = "Les Miséééééééérables";
317 // For some reason, this pattern of macro_rules foiled our generated code
318 // avoiding strategy.
319 macro_rules! variable_str(($name:expr) => (
324 let vs = variable_str!(32);
326 let mut candidates: RefCell<HashMap<&'static str, &'static str>> = RefCell::new(HashMap::new());
328 used_link_args: RefCell::new([]),
331 let s2 = SF { field1: 55};
332 let s3: some_fields = some_fields{ field1: 55};
333 let s4: msalias::nested_struct = sub::sub2::nested_struct{ field2: 55};
334 let s4: msalias::nested_struct = sub2::nested_struct{ field2: 55};
335 println(&s2.field1.to_string());
336 let s5: MyType = box some_fields{ field1: 55};
337 let s = SameDir::SameStruct{name: "Bob".to_string()};
338 let s = SubDir::SubStruct{name:"Bob".to_string()};
339 let s6: SomeEnum = SomeEnum::MyTypes(box s2.clone(), s5);
340 let s7: SomeEnum = SomeEnum::Strings("one", "two", "three");
343 let s8: SomeOtherEnum = SomeOtherEnum::SomeConst2;
344 matchSomeOtherEnum(s8);
345 let s9: SomeStructEnum = SomeStructEnum::EnumStruct2{ f1: box some_fields{ field1:10 },
347 matchSomeStructEnum(s9);
349 for x in &vec![1, 2, 3] {
353 let s7: SomeEnum = SomeEnum::Strings("one", "two", "three");
354 if let SomeEnum::Strings(..) = s7 {
362 if let Some(x) = None {
367 } else if let Some(y) = None {
371 while let Some(z) = None {
376 test_rec!(q, "Hello");
381 fn foo_foo(_: i32) {}
383 impl Iterator for nofields {
384 type Item = (usize, usize);
386 fn next(&mut self) -> Option<(usize, usize)> {
390 fn size_hint(&self) -> (usize, Option<usize>) {
399 struct CharEqPattern;
401 impl<'a> Pattern<'a> for CharEqPattern {
402 type Searcher = CharEqPattern;
405 struct CharSearcher<'a>(<CharEqPattern as Pattern<'a>>::Searcher);
410 impl Error + 'static {
411 pub fn is<T: Error + 'static>(&self) -> bool {
416 impl Error + 'static + Send {
417 pub fn is<T: Error + 'static>(&self) -> bool {
418 <Error + 'static>::is::<T>(self)
421 extern crate serialize as rustc_serialize;
422 #[derive(Clone, Copy, Hash, RustcEncodable, RustcDecodable,
423 PartialEq, Eq, PartialOrd, Ord, Debug, Default)]
424 struct AllDerives(i32);
426 fn test_format_args() {
429 let name = "Joe Blogg";
430 println!("Hello {}", name);
431 print!("Hello {0}", name);
432 print!("{0} + {} = {}", x, y);
433 print!("x is {}, y is {1}, name is {n}", x, y, n = name);
443 struct SilenceGenerator;
445 impl Iterator for SilenceGenerator {
446 type Item = FrameBuffer;
448 fn next(&mut self) -> Option<Self::Item> {
454 type Bar = FrameBuffer;
457 #[doc(include="extra-docs.md")]
458 struct StructWithDocs;