diff --git a/src/test/run-pass/module-polymorphism-files/inst_f32.rs b/src/test/run-pass/module-polymorphism-files/inst_f32.rs new file mode 100644 index 00000000000..ea7d8fd77a0 --- /dev/null +++ b/src/test/run-pass/module-polymorphism-files/inst_f32.rs @@ -0,0 +1 @@ +type T = f32; \ No newline at end of file diff --git a/src/test/run-pass/module-polymorphism-files/inst_f64.rs b/src/test/run-pass/module-polymorphism-files/inst_f64.rs new file mode 100644 index 00000000000..8811863b27c --- /dev/null +++ b/src/test/run-pass/module-polymorphism-files/inst_f64.rs @@ -0,0 +1 @@ +type T = f64; \ No newline at end of file diff --git a/src/test/run-pass/module-polymorphism-files/inst_float.rs b/src/test/run-pass/module-polymorphism-files/inst_float.rs new file mode 100644 index 00000000000..5726ccf7ad0 --- /dev/null +++ b/src/test/run-pass/module-polymorphism-files/inst_float.rs @@ -0,0 +1 @@ +type T = float; \ No newline at end of file diff --git a/src/test/run-pass/module-polymorphism-files/template.rs b/src/test/run-pass/module-polymorphism-files/template.rs new file mode 100644 index 00000000000..c8d52145cab --- /dev/null +++ b/src/test/run-pass/module-polymorphism-files/template.rs @@ -0,0 +1,3 @@ +fn plus(x: T, y: T) -> T { + x + y +} \ No newline at end of file diff --git a/src/test/run-pass/module-polymorphism.rc b/src/test/run-pass/module-polymorphism.rc new file mode 100644 index 00000000000..ed8e8be283e --- /dev/null +++ b/src/test/run-pass/module-polymorphism.rc @@ -0,0 +1,45 @@ +#[no_core]; + + +#[path = "module-polymorphism-files"] +mod float { + + // The type of the float + import inst::T; + + // Define T as float + #[path = "inst_float.rs"] + mod inst; + + // Add in the implementation from a single source file + #[path = "template.rs"] + mod template; + +} + +#[path = "module-polymorphism-files"] +mod f64 { + + import inst::T; + + // Define T as f64 + #[path = "inst_f64.rs"] + mod inst; + + // Use the implementation for the same source file! + #[path = "template.rs"] + mod template; + +} + +#[path = "module-polymorphism-files"] +mod f32 { + import inst::T; + + #[path = "inst_f32.rs"] + mod inst; + + #[path = "template.rs"] + mod template; + +} \ No newline at end of file diff --git a/src/test/run-pass/module-polymorphism.rs b/src/test/run-pass/module-polymorphism.rs new file mode 100644 index 00000000000..e2f8350ef72 --- /dev/null +++ b/src/test/run-pass/module-polymorphism.rs @@ -0,0 +1,11 @@ +// This isn't really xfailed; it's used by the +// module-polymorphism.rc test +// xfail-test + +fn main() { + // All of these functions are defined by a single module + // source file but instantiated for different types + assert float::template::plus(1.0f, 2.0f) == 3.0f; + assert f64::template::plus(1.0f64, 2.0f64) == 3.0f64; + assert f32::template::plus(1.0f32, 2.0f32) == 3.0f32; +} \ No newline at end of file diff --git a/src/test/run-pass/module-polymorphism2-files/float-template/inst_f32.rs b/src/test/run-pass/module-polymorphism2-files/float-template/inst_f32.rs new file mode 100644 index 00000000000..ea7d8fd77a0 --- /dev/null +++ b/src/test/run-pass/module-polymorphism2-files/float-template/inst_f32.rs @@ -0,0 +1 @@ +type T = f32; \ No newline at end of file diff --git a/src/test/run-pass/module-polymorphism2-files/float-template/inst_f64.rs b/src/test/run-pass/module-polymorphism2-files/float-template/inst_f64.rs new file mode 100644 index 00000000000..8811863b27c --- /dev/null +++ b/src/test/run-pass/module-polymorphism2-files/float-template/inst_f64.rs @@ -0,0 +1 @@ +type T = f64; \ No newline at end of file diff --git a/src/test/run-pass/module-polymorphism2-files/float-template/inst_float.rs b/src/test/run-pass/module-polymorphism2-files/float-template/inst_float.rs new file mode 100644 index 00000000000..5726ccf7ad0 --- /dev/null +++ b/src/test/run-pass/module-polymorphism2-files/float-template/inst_float.rs @@ -0,0 +1 @@ +type T = float; \ No newline at end of file diff --git a/src/test/run-pass/module-polymorphism2-files/float-template/template.rs b/src/test/run-pass/module-polymorphism2-files/float-template/template.rs new file mode 100644 index 00000000000..c8d52145cab --- /dev/null +++ b/src/test/run-pass/module-polymorphism2-files/float-template/template.rs @@ -0,0 +1,3 @@ +fn plus(x: T, y: T) -> T { + x + y +} \ No newline at end of file diff --git a/src/test/run-pass/module-polymorphism2.rc b/src/test/run-pass/module-polymorphism2.rc new file mode 100644 index 00000000000..0d64cb46a26 --- /dev/null +++ b/src/test/run-pass/module-polymorphism2.rc @@ -0,0 +1,61 @@ +#[no_core]; + + +#[path = "module-polymorphism2-files"] +mod mystd { + + #[path = "float-template"] + mod float { + // The type of the float + import inst::T; + + // Unfortunate + import template::*; + export plus; + + // Define T as float + #[path = "inst_float.rs"] + mod inst; + + // Add in the implementation from a single source file + #[path = "template.rs"] + mod template; + } + + + #[path = "float-template"] + mod f64 { + + import inst::T; + + // Unfortunate + import template::*; + export plus; + + // Define T as f64 + #[path = "inst_f64.rs"] + mod inst; + + // Use the implementation for the same source file! + #[path = "template.rs"] + mod template; + + } + + #[path = "float-template"] + mod f32 { + import inst::T; + + // Unfortunate + import template::*; + export plus; + + #[path = "inst_f32.rs"] + mod inst; + + #[path = "template.rs"] + mod template; + + } + +} \ No newline at end of file diff --git a/src/test/run-pass/module-polymorphism2.rs b/src/test/run-pass/module-polymorphism2.rs new file mode 100644 index 00000000000..7bb55c45430 --- /dev/null +++ b/src/test/run-pass/module-polymorphism2.rs @@ -0,0 +1,11 @@ +// This isn't really xfailed; it's used by the +// module-polymorphism.rc test +// xfail-test + +fn main() { + // All of these functions are defined by a single module + // source file but instantiated for different types + assert mystd::float::plus(1.0f, 2.0f) == 3.0f; + assert mystd::f64::plus(1.0f64, 2.0f64) == 3.0f64; + assert mystd::f32::plus(1.0f32, 2.0f32) == 3.0f32; +} \ No newline at end of file diff --git a/src/test/run-pass/module-polymorphism3-files/float-template.rs b/src/test/run-pass/module-polymorphism3-files/float-template.rs new file mode 100644 index 00000000000..c8d52145cab --- /dev/null +++ b/src/test/run-pass/module-polymorphism3-files/float-template.rs @@ -0,0 +1,3 @@ +fn plus(x: T, y: T) -> T { + x + y +} \ No newline at end of file diff --git a/src/test/run-pass/module-polymorphism3-files/float-template/inst_f32.rs b/src/test/run-pass/module-polymorphism3-files/float-template/inst_f32.rs new file mode 100644 index 00000000000..ea7d8fd77a0 --- /dev/null +++ b/src/test/run-pass/module-polymorphism3-files/float-template/inst_f32.rs @@ -0,0 +1 @@ +type T = f32; \ No newline at end of file diff --git a/src/test/run-pass/module-polymorphism3-files/float-template/inst_f64.rs b/src/test/run-pass/module-polymorphism3-files/float-template/inst_f64.rs new file mode 100644 index 00000000000..8811863b27c --- /dev/null +++ b/src/test/run-pass/module-polymorphism3-files/float-template/inst_f64.rs @@ -0,0 +1 @@ +type T = f64; \ No newline at end of file diff --git a/src/test/run-pass/module-polymorphism3-files/float-template/inst_float.rs b/src/test/run-pass/module-polymorphism3-files/float-template/inst_float.rs new file mode 100644 index 00000000000..5726ccf7ad0 --- /dev/null +++ b/src/test/run-pass/module-polymorphism3-files/float-template/inst_float.rs @@ -0,0 +1 @@ +type T = float; \ No newline at end of file diff --git a/src/test/run-pass/module-polymorphism3.rc b/src/test/run-pass/module-polymorphism3.rc new file mode 100644 index 00000000000..34dc9000e32 --- /dev/null +++ b/src/test/run-pass/module-polymorphism3.rc @@ -0,0 +1,39 @@ +#[no_core]; + +// Use one template module to specify in a single file the implementation +// of functions for multiple types + +#[path = "module-polymorphism3-files"] +mod mystd { + + // The template is specified in float-template.rs + #[path = "float-template"] + mod float { + // The type of the float + import inst::T; + + // Define T as appropriate for platform + #[path = "inst_float.rs"] + mod inst; + } + + // Use the same template + #[path = "float-template"] + mod f64 { + + import inst::T; + + // Define T as f64 + #[path = "inst_f64.rs"] + mod inst; + } + + #[path = "float-template"] + mod f32 { + import inst::T; + + #[path = "inst_f32.rs"] + mod inst; + } + +} \ No newline at end of file diff --git a/src/test/run-pass/module-polymorphism3.rs b/src/test/run-pass/module-polymorphism3.rs new file mode 100644 index 00000000000..7bb55c45430 --- /dev/null +++ b/src/test/run-pass/module-polymorphism3.rs @@ -0,0 +1,11 @@ +// This isn't really xfailed; it's used by the +// module-polymorphism.rc test +// xfail-test + +fn main() { + // All of these functions are defined by a single module + // source file but instantiated for different types + assert mystd::float::plus(1.0f, 2.0f) == 3.0f; + assert mystd::f64::plus(1.0f64, 2.0f64) == 3.0f64; + assert mystd::f32::plus(1.0f32, 2.0f32) == 3.0f32; +} \ No newline at end of file