1 #![crate_name = "test"]
2 #![feature(box_syntax)]
3 #![feature(rustc_private)]
4 #![feature(associated_type_defaults)]
6 extern crate rustc_graphviz;
7 // A simple rust project
10 extern crate krate2 as krate3;
12 use rustc_graphviz::RenderOption;
13 use std::cell::RefCell;
14 use std::collections::{HashMap, HashSet};
17 use sub::sub2 as msalias;
19 use sub::sub2::nested_struct as sub_struct;
21 use std::mem::size_of;
23 use std::char::from_u32;
25 static uni: &'static str = "Les Miséééééééérables";
26 static yy: usize = 25;
28 static bob: Option<rustc_graphviz::RenderOption> = None;
30 // buglink test - see issue #1337.
32 fn test_alias<I: Iterator>(i: Option<<I as Iterator>::Item>) {
33 let s = sub_struct { field2: 45u32 };
37 let _: Option<_> = from_u32(45);
44 let x = (3isize, 4usize);
49 const LUT_BITS: usize = 3;
50 pub struct HuffmanTable {
51 ac_lut: Option<[(i16, u8); 1 << LUT_BITS]>,
54 struct TupStruct(isize, isize, Box<str>);
56 fn test_tup_struct(x: TupStruct) -> isize {
61 std::io::stdout().write_all(s.as_bytes());
70 ::println("hello from module 3");
74 ::println("hello from a module");
77 pub struct nested_struct {
81 pub enum nested_enum {
91 #[path = "SameDir3.rs"]
101 type SF = some_fields;
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 {}
136 impl SubTrait for some_fields {}
139 fn stat(x: u32) -> u32 {
140 println(&x.to_string());
143 fn stat2(x: &some_fields) -> u32 {
147 fn align_to<T>(&mut self) {}
150 self.align_to::<bool>();
154 impl SuperTrait for nofields {}
155 impl SomeTrait for nofields {
156 fn Method(&self, x: u32) -> u32 {
161 fn provided_method(&self) -> u32 {
166 impl SubTrait for nofields {}
168 impl SuperTrait for (Box<nofields>, Box<some_fields>) {}
170 fn f_with_params<T: SomeTrait>(x: &T) {
174 type MyType = Box<some_fields>;
179 Strings(&'a str, &'a str, &'a str),
180 MyTypes(MyType, MyType),
183 #[derive(Copy, Clone)]
190 enum SomeStructEnum {
191 EnumStruct { a: isize, b: isize },
192 EnumStruct2 { f1: MyType, f2: MyType },
193 EnumStruct3 { f1: MyType, f2: MyType, f3: SomeEnum<'static> },
196 fn matchSomeEnum(val: SomeEnum) {
198 SomeEnum::Ints(int1, int2) => {
199 println(&(int1 + int2).to_string());
201 SomeEnum::Floats(float1, float2) => {
202 println(&(float2 * float1).to_string());
204 SomeEnum::Strings(.., s3) => {
207 SomeEnum::MyTypes(mt1, mt2) => {
208 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()),
221 fn matchSomeStructEnum2(se: SomeStructEnum) {
222 use SomeStructEnum::*;
224 EnumStruct { a: ref aaa, .. } => println(&aaa.to_string()),
225 EnumStruct2 { f1, f2: f2 } => println(&f1.field1.to_string()),
226 EnumStruct3 { f1, f3: SomeEnum::Ints(..), f2 } => println(&f1.field1.to_string()),
231 fn matchSomeOtherEnum(val: SomeOtherEnum) {
232 use SomeOtherEnum::{SomeConst2, SomeConst3};
234 SomeOtherEnum::SomeConst1 => {
235 println("I'm const1.");
237 SomeConst2 | SomeConst3 => {
238 println("I'm const2 or const3.");
243 fn hello<X: SomeTrait>((z, a): (u32, String), ex: X) {
246 println(&yy.to_string());
247 let (x, y): (u32, u32) = (5, 3);
248 println(&x.to_string());
249 println(&z.to_string());
251 println(&x.to_string());
256 let _ = (x + ((x * x) + 1.0).sqrt()).ln();
258 let s: Box<SomeTrait> = box some_fields { field1: 43 };
259 let s2: Box<some_fields> = box some_fields { field1: 43 };
260 let s3 = box nofields;
269 // static method on struct
270 let r = some_fields::stat(y);
271 // trait static method, calls default
272 let r = SubTrait::stat2(&*s3);
274 let s4 = s3 as Box<SomeTrait>;
277 s4.provided_method();
280 let closure = |x: u32, s: &SomeTrait| {
285 let z = closure(10, &*s);
289 used_link_args: RefCell<[&'static str; 0]>,
294 macro_rules! test_rec {
295 (q, $src: expr) => {{
304 macro_rules! internal_vars {
314 let s = box some_fields { field1: 43 };
315 hello((43, "a".to_string()), *s);
319 let h = sub2::sub3::hello;
323 let ut = "Les Miséééééééérables";
325 // For some reason, this pattern of macro_rules foiled our generated code
326 // avoiding strategy.
327 macro_rules! variable_str(($name:expr) => (
332 let vs = variable_str!(32);
334 let mut candidates: RefCell<HashMap<&'static str, &'static str>> = RefCell::new(HashMap::new());
335 let _ = blah { used_link_args: RefCell::new([]) };
337 let s2 = SF { field1: 55 };
338 let s3: some_fields = some_fields { field1: 55 };
339 let s4: msalias::nested_struct = sub::sub2::nested_struct { field2: 55 };
340 let s4: msalias::nested_struct = sub2::nested_struct { field2: 55 };
341 println(&s2.field1.to_string());
342 let s5: MyType = box some_fields { field1: 55 };
343 let s = SameDir::SameStruct { name: "Bob".to_string() };
344 let s = SubDir::SubStruct { name: "Bob".to_string() };
345 let s6: SomeEnum = SomeEnum::MyTypes(box s2.clone(), s5);
346 let s7: SomeEnum = SomeEnum::Strings("one", "two", "three");
349 let s8: SomeOtherEnum = SomeOtherEnum::SomeConst2;
350 matchSomeOtherEnum(s8);
351 let s9: SomeStructEnum =
352 SomeStructEnum::EnumStruct2 { f1: box some_fields { field1: 10 }, f2: box s2 };
353 matchSomeStructEnum(s9);
355 for x in &vec![1, 2, 3] {
359 let s7: SomeEnum = SomeEnum::Strings("one", "two", "three");
360 if let SomeEnum::Strings(..) = s7 {
368 if let Some(x) = None {
373 } else if let Some(y) = None {
377 while let Some(z) = None {
382 test_rec!(q, "Hello");
387 fn foo_foo(_: i32) {}
389 impl Iterator for nofields {
390 type Item = (usize, usize);
392 fn next(&mut self) -> Option<(usize, usize)> {
396 fn size_hint(&self) -> (usize, Option<usize>) {
405 struct CharEqPattern;
407 impl<'a> Pattern<'a> for CharEqPattern {
408 type Searcher = CharEqPattern;
411 struct CharSearcher<'a>(<CharEqPattern as Pattern<'a>>::Searcher);
415 impl Error + 'static {
416 pub fn is<T: Error + 'static>(&self) -> bool {
421 impl Error + 'static + Send {
422 pub fn is<T: Error + 'static>(&self) -> bool {
423 <Error + 'static>::is::<T>(self)
426 extern crate rustc_serialize;
427 #[derive(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Debug, Default)]
428 struct AllDerives(i32);
430 fn test_format_args() {
433 let name = "Joe Blogg";
434 println!("Hello {}", name);
435 print!("Hello {0}", name);
436 print!("{0} + {} = {}", x, y);
437 print!("x is {}, y is {1}, name is {n}", x, y, n = name);
446 struct SilenceGenerator;
448 impl Iterator for SilenceGenerator {
449 type Item = FrameBuffer;
451 fn next(&mut self) -> Option<Self::Item> {
456 #[doc = include_str!("extra-docs.md")]
457 struct StructWithDocs;
460 type Bar = FrameBuffer;