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" ]
13 #![feature(box_syntax, rustc_private, core, zero_one)]
15 extern crate graphviz
;
16 // A simple rust project
18 extern crate flate
as myflate
;
20 use std
::collections
::{HashMap,HashSet}
;
21 use std
::cell
::RefCell
;
24 use sub
::sub2
as msalias
;
26 use sub
::sub2
::nested_struct
as sub_struct
;
29 use std
::mem
::size_of
;
31 static uni
: &'
static str = "Les Miséééééééérables";
32 static yy
: usize = 25;
34 static bob
: Option
<&'
static [isize]> = None
;
36 // buglink test - see issue #1337.
38 fn test_alias
<I
: Iterator
>(i
: Option
<<I
as Iterator
>::Item
>) {
39 let s
= sub_struct{ field2: 45, }
;
46 myflate
::deflate_bytes(&[]);
52 struct TupStruct(isize, isize, Box
<str>);
54 fn test_tup_struct(x
: TupStruct
) -> isize {
62 println
!("hello from module 3");
66 println
!("hello from a module");
69 pub struct nested_struct
{
73 pub enum nested_enum
{
83 #[path = "SameDir3.rs"]
93 type SF
= some_fields
;
99 trait SomeTrait
: SuperTrait
{
100 fn Method(&self, x
: u32) -> u32;
102 fn prov(&self, x
: u32) -> u32 {
103 println
!("{}", &x
.to_string());
106 fn provided_method(&self) -> u32 {
111 trait SubTrait
: SomeTrait
{
112 fn stat2(x
: &Self) -> u32 {
117 impl SomeTrait
for some_fields
{
118 fn Method(&self, x
: u32) -> u32 {
119 println
!("{}", &x
.to_string());
124 impl SuperTrait
for some_fields
{
127 impl SubTrait
for some_fields {}
130 fn stat(x
: u32) -> u32 {
131 println
!("{}", &x
.to_string());
134 fn stat2(x
: &some_fields
) -> u32 {
138 fn align_to
<T
>(&mut self) {
142 self.align_to
::<bool
>();
146 impl SuperTrait
for nofields
{
148 impl SomeTrait
for nofields
{
149 fn Method(&self, x
: u32) -> u32 {
154 fn provided_method(&self) -> u32 {
159 impl SubTrait
for nofields {}
161 impl SuperTrait
for (Box
<nofields
>, Box
<some_fields
>) {}
163 fn f_with_params
<T
: SomeTrait
>(x
: &T
) {
167 type MyType
= Box
<some_fields
>;
172 Strings(&'a
str, &'a
str, &'a
str),
173 MyTypes(MyType
, MyType
)
176 #[derive(Copy, Clone)]
183 enum SomeStructEnum
{
184 EnumStruct{a:isize, b:isize}
,
185 EnumStruct2{f1:MyType, f2:MyType}
,
186 EnumStruct3{f1:MyType, f2:MyType, f3:SomeEnum<'static>}
189 fn matchSomeEnum(val
: SomeEnum
) {
191 SomeEnum
::Ints(int1
, int2
) => { println!("{}
", &(int1+int2).to_string()); }
192 SomeEnum::Floats(float1, float2) => { println!("{}", &(float2
*float1
).to_string()); }
193 SomeEnum
::Strings(_
, _
, s3
) => { println!("{}
", s3); }
194 SomeEnum::MyTypes(mt1, mt2) => {
195 println!("{}
", &(mt1.field1 - mt2.field1).to_string());
200 fn matchSomeStructEnum(se: SomeStructEnum) {
202 SomeStructEnum::EnumStruct{a:a, ..} => println!("{}
", &a.to_string()),
203 SomeStructEnum::EnumStruct2{f1:f1, f2:f_2} => println!("{}
", &f_2.field1.to_string()),
204 SomeStructEnum::EnumStruct3{f1, ..} => println!("{}
", &f1.field1.to_string()),
209 fn matchSomeStructEnum2(se: SomeStructEnum) {
210 use SomeStructEnum::*;
212 EnumStruct{a: ref aaa, ..} => println!("{}
", &aaa.to_string()),
213 EnumStruct2{f1, f2: f2} => println!("{}
", &f1.field1.to_string()),
214 EnumStruct3{f1, f3: SomeEnum::Ints(_, _), f2} => println!("{}
", &f1.field1.to_string()),
219 fn matchSomeOtherEnum(val: SomeOtherEnum) {
220 use SomeOtherEnum::{SomeConst2, SomeConst3};
222 SomeOtherEnum::SomeConst1 => { println!("I'm const1."); }
223 SomeConst2 | SomeConst3 => { println!("I'm const2 or const3."); }
227 fn hello<X: SomeTrait>((z, a) : (u32, String), ex: X) {
230 println!("{}
", &yy.to_string());
231 let (x, y): (u32, u32) = (5, 3);
232 println!("{}
", &x.to_string());
233 println!("{}
", &z.to_string());
235 println!("{}
", &x.to_string());
240 let _ = (x + ((x * x) + 1.0).sqrt()).ln();
242 // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
243 let s: Box<SomeTrait> = Box::new(some_fields {field1: 43});
244 let s2: Box<some_fields> = box some_fields {field1: 43};
245 let s3: Box<_> = box nofields;
254 // static method on struct
255 let r = some_fields::stat(y);
256 // trait static method, calls override
257 let r = SubTrait::stat2(&*s2);
258 // trait static method, calls default
259 let r = SubTrait::stat2(&*s3);
261 let s4 = s3 as Box<SomeTrait>;
264 s4.provided_method();
267 let closure = |x: u32, s: &SomeTrait| {
272 let z = closure(10, &*s);
276 used_link_args: RefCell<[&'static str; 0]>,
280 let s: Box<_> = box some_fields {field1: 43};
281 hello((43, "a
".to_string()), *s);
285 let h = sub2::sub3::hello;
289 let ut = "Les Miséééééééérables
";
291 // For some reason, this pattern of macro_rules foiled our generated code
292 // avoiding strategy.
293 macro_rules! variable_str(($name:expr) => (
298 let vs = variable_str!(32);
300 let mut candidates: RefCell<HashMap<&'static str, &'static str>> = RefCell::new(HashMap::new());
302 used_link_args: RefCell::new([]),
305 let s2 = SF { field1: 55};
306 let s3: some_fields = some_fields{ field1: 55};
307 let s4: msalias::nested_struct = sub::sub2::nested_struct{ field2: 55};
308 let s4: msalias::nested_struct = sub2::nested_struct{ field2: 55};
309 println!("{}
", &s2.field1.to_string());
310 let s5: MyType = box some_fields{ field1: 55};
311 let s = SameDir::SameStruct{name: "Bob".to_string()};
312 let s = SubDir::SubStruct{name:"Bob".to_string()};
313 let s6: SomeEnum = SomeEnum::MyTypes(box s2.clone(), s5);
314 let s7: SomeEnum = SomeEnum::Strings("one
", "two
", "three
");
317 let s8: SomeOtherEnum = SomeOtherEnum::SomeConst2;
318 matchSomeOtherEnum(s8);
319 let s9: SomeStructEnum =
320 SomeStructEnum::EnumStruct2{f1: box some_fields{field1:10}, f2: box s2};
321 matchSomeStructEnum(s9);
324 impl Iterator for nofields {
325 type Item = (usize, usize);
327 fn next(&mut self) -> Option<(usize, usize)> {
331 fn size_hint(&self) -> (usize, Option<usize>) {