1 #![crate_name = "test"]
2 #![feature(rustc_private)]
3 #![feature(associated_type_defaults)]
5 extern crate rustc_graphviz;
6 // A simple rust project
9 extern crate krate2 as krate3;
11 use rustc_graphviz::RenderOption;
12 use std::cell::RefCell;
13 use std::collections::{HashMap, HashSet};
16 use sub::sub2 as msalias;
18 use sub::sub2::nested_struct as sub_struct;
20 use std::mem::size_of;
22 use std::char::from_u32;
24 static uni: &'static str = "Les Miséééééééérables";
25 static yy: usize = 25;
27 static bob: Option<rustc_graphviz::RenderOption> = None;
29 // buglink test - see issue #1337.
31 fn test_alias<I: Iterator>(i: Option<<I as Iterator>::Item>) {
32 let s = sub_struct { field2: 45u32 };
36 let _: Option<_> = from_u32(45);
43 let x = (3isize, 4usize);
48 const LUT_BITS: usize = 3;
49 pub struct HuffmanTable {
50 ac_lut: Option<[(i16, u8); 1 << LUT_BITS]>,
53 struct TupStruct(isize, isize, Box<str>);
55 fn test_tup_struct(x: TupStruct) -> isize {
60 std::io::stdout().write_all(s.as_bytes());
69 ::println("hello from module 3");
73 ::println("hello from a module");
76 pub struct nested_struct {
80 pub enum nested_enum {
90 #[path = "SameDir3.rs"]
100 type SF = some_fields;
108 trait SomeTrait: SuperTrait {
109 fn Method(&self, x: u32) -> u32;
111 fn prov(&self, x: u32) -> u32 {
112 println(&x.to_string());
115 fn provided_method(&self) -> u32 {
120 trait SubTrait: SomeTrait {
121 fn stat2(x: &Self) -> u32 {
126 impl SomeTrait for some_fields {
127 fn Method(&self, x: u32) -> u32 {
128 println(&x.to_string());
133 impl SuperTrait for some_fields {}
135 impl SubTrait for some_fields {}
138 fn stat(x: u32) -> u32 {
139 println(&x.to_string());
142 fn stat2(x: &some_fields) -> u32 {
146 fn align_to<T>(&mut self) {}
149 self.align_to::<bool>();
153 impl SuperTrait for nofields {}
154 impl SomeTrait for nofields {
155 fn Method(&self, x: u32) -> u32 {
160 fn provided_method(&self) -> u32 {
165 impl SubTrait for nofields {}
167 impl SuperTrait for (Box<nofields>, Box<some_fields>) {}
169 fn f_with_params<T: SomeTrait>(x: &T) {
173 type MyType = Box<some_fields>;
178 Strings(&'a str, &'a str, &'a str),
179 MyTypes(MyType, MyType),
182 #[derive(Copy, Clone)]
189 enum SomeStructEnum {
190 EnumStruct { a: isize, b: isize },
191 EnumStruct2 { f1: MyType, f2: MyType },
192 EnumStruct3 { f1: MyType, f2: MyType, f3: SomeEnum<'static> },
195 fn matchSomeEnum(val: SomeEnum) {
197 SomeEnum::Ints(int1, int2) => {
198 println(&(int1 + int2).to_string());
200 SomeEnum::Floats(float1, float2) => {
201 println(&(float2 * float1).to_string());
203 SomeEnum::Strings(.., s3) => {
206 SomeEnum::MyTypes(mt1, mt2) => {
207 println(&(mt1.field1 - mt2.field1).to_string());
212 fn matchSomeStructEnum(se: SomeStructEnum) {
214 SomeStructEnum::EnumStruct { a: a, .. } => println(&a.to_string()),
215 SomeStructEnum::EnumStruct2 { f1: f1, f2: f_2 } => println(&f_2.field1.to_string()),
216 SomeStructEnum::EnumStruct3 { f1, .. } => println(&f1.field1.to_string()),
220 fn matchSomeStructEnum2(se: SomeStructEnum) {
221 use SomeStructEnum::*;
223 EnumStruct { a: ref aaa, .. } => println(&aaa.to_string()),
224 EnumStruct2 { f1, f2: f2 } => println(&f1.field1.to_string()),
225 EnumStruct3 { f1, f3: SomeEnum::Ints(..), f2 } => println(&f1.field1.to_string()),
230 fn matchSomeOtherEnum(val: SomeOtherEnum) {
231 use SomeOtherEnum::{SomeConst2, SomeConst3};
233 SomeOtherEnum::SomeConst1 => {
234 println("I'm const1.");
236 SomeConst2 | SomeConst3 => {
237 println("I'm const2 or const3.");
242 fn hello<X: SomeTrait>((z, a): (u32, String), ex: X) {
245 println(&yy.to_string());
246 let (x, y): (u32, u32) = (5, 3);
247 println(&x.to_string());
248 println(&z.to_string());
250 println(&x.to_string());
255 let _ = (x + ((x * x) + 1.0).sqrt()).ln();
257 let s: Box<SomeTrait> = Box::new(some_fields { field1: 43 });
258 let s2: Box<some_fields> = Box::new(some_fields { field1: 43 });
259 let s3 = Box::new(nofields);
268 // static method on struct
269 let r = some_fields::stat(y);
270 // trait static method, calls default
271 let r = SubTrait::stat2(&*s3);
273 let s4 = s3 as Box<SomeTrait>;
276 s4.provided_method();
279 let closure = |x: u32, s: &SomeTrait| {
284 let z = closure(10, &*s);
288 used_link_args: RefCell<[&'static str; 0]>,
293 macro_rules! test_rec {
294 (q, $src: expr) => {{
303 macro_rules! internal_vars {
313 let s = Box::new(some_fields { field1: 43 });
314 hello((43, "a".to_string()), *s);
318 let h = sub2::sub3::hello;
322 let ut = "Les Miséééééééérables";
324 // For some reason, this pattern of macro_rules foiled our generated code
325 // avoiding strategy.
326 macro_rules! variable_str(($name:expr) => (
331 let vs = variable_str!(32);
333 let mut candidates: RefCell<HashMap<&'static str, &'static str>> = RefCell::new(HashMap::new());
334 let _ = blah { used_link_args: RefCell::new([]) };
336 let s2 = SF { field1: 55 };
337 let s3: some_fields = some_fields { field1: 55 };
338 let s4: msalias::nested_struct = sub::sub2::nested_struct { field2: 55 };
339 let s4: msalias::nested_struct = sub2::nested_struct { field2: 55 };
340 println(&s2.field1.to_string());
341 let s5: MyType = Box::new(some_fields { field1: 55 });
342 let s = SameDir::SameStruct { name: "Bob".to_string() };
343 let s = SubDir::SubStruct { name: "Bob".to_string() };
344 let s6: SomeEnum = SomeEnum::MyTypes(Box::new(s2.clone()), s5);
345 let s7: SomeEnum = SomeEnum::Strings("one", "two", "three");
348 let s8: SomeOtherEnum = SomeOtherEnum::SomeConst2;
349 matchSomeOtherEnum(s8);
350 let s9: SomeStructEnum =
351 SomeStructEnum::EnumStruct2 { f1: Box::new(some_fields { field1: 10 }), f2: Box::new(s2) };
352 matchSomeStructEnum(s9);
354 for x in &vec![1, 2, 3] {
358 let s7: SomeEnum = SomeEnum::Strings("one", "two", "three");
359 if let SomeEnum::Strings(..) = s7 {
367 if let Some(x) = None {
372 } else if let Some(y) = None {
376 while let Some(z) = None {
381 test_rec!(q, "Hello");
386 fn foo_foo(_: i32) {}
388 impl Iterator for nofields {
389 type Item = (usize, usize);
391 fn next(&mut self) -> Option<(usize, usize)> {
395 fn size_hint(&self) -> (usize, Option<usize>) {
404 struct CharEqPattern;
406 impl<'a> Pattern<'a> for CharEqPattern {
407 type Searcher = CharEqPattern;
410 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 rustc_serialize;
426 #[derive(Clone, Copy, Hash, 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);
445 struct SilenceGenerator;
447 impl Iterator for SilenceGenerator {
448 type Item = FrameBuffer;
450 fn next(&mut self) -> Option<Self::Item> {
455 #[doc = include_str!("extra-docs.md")]
456 struct StructWithDocs;
459 type Bar = FrameBuffer;