]> git.lizzy.rs Git - rust.git/commitdiff
Add more tests for unnameable reachable items
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Tue, 16 Feb 2016 20:38:41 +0000 (23:38 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Wed, 17 Feb 2016 22:04:28 +0000 (01:04 +0300)
src/test/auxiliary/issue-16734.rs [deleted file]
src/test/auxiliary/reachable-unnameable-items.rs [new file with mode: 0644]
src/test/run-pass/issue-16734.rs [deleted file]
src/test/run-pass/reachable-unnameable-items.rs [new file with mode: 0644]
src/test/run-pass/reachable-unnameable-type-alias.rs [new file with mode: 0644]

diff --git a/src/test/auxiliary/issue-16734.rs b/src/test/auxiliary/issue-16734.rs
deleted file mode 100644 (file)
index 9b1635c..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-mod inner_private_module {
-    pub struct Unnameable;
-
-    impl Unnameable {
-        pub fn method_of_unnameable_type(&self) -> &'static str {
-            "Hello!"
-        }
-    }
-}
-
-pub fn public_function_returning_unnameable_type() -> inner_private_module::Unnameable {
-    inner_private_module::Unnameable
-}
diff --git a/src/test/auxiliary/reachable-unnameable-items.rs b/src/test/auxiliary/reachable-unnameable-items.rs
new file mode 100644 (file)
index 0000000..7ec2bb9
--- /dev/null
@@ -0,0 +1,116 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use inner_private_module::*;
+
+mod inner_private_module {
+    pub struct Unnameable1;
+    pub struct Unnameable2;
+    #[derive(Clone, Copy)]
+    pub struct Unnameable3;
+    pub struct Unnameable4;
+    pub struct Unnameable5;
+    pub struct Unnameable6;
+    pub struct Unnameable7;
+    #[derive(Default)]
+    pub struct Unnameable8;
+    pub enum UnnameableEnum {
+        NameableVariant
+    }
+    pub trait UnnameableTrait {
+        type Alias: Default;
+    }
+
+    impl Unnameable1 {
+        pub fn method_of_unnameable_type1(&self) -> &'static str {
+            "Hello1"
+        }
+    }
+    impl Unnameable2 {
+        pub fn method_of_unnameable_type2(&self) -> &'static str {
+            "Hello2"
+        }
+    }
+    impl Unnameable3 {
+        pub fn method_of_unnameable_type3(&self) -> &'static str {
+            "Hello3"
+        }
+    }
+    impl Unnameable4 {
+        pub fn method_of_unnameable_type4(&self) -> &'static str {
+            "Hello4"
+        }
+    }
+    impl Unnameable5 {
+        pub fn method_of_unnameable_type5(&self) -> &'static str {
+            "Hello5"
+        }
+    }
+    impl Unnameable6 {
+        pub fn method_of_unnameable_type6(&self) -> &'static str {
+            "Hello6"
+        }
+    }
+    impl Unnameable7 {
+        pub fn method_of_unnameable_type7(&self) -> &'static str {
+            "Hello7"
+        }
+    }
+    impl Unnameable8 {
+        pub fn method_of_unnameable_type8(&self) -> &'static str {
+            "Hello8"
+        }
+    }
+    impl UnnameableEnum {
+        pub fn method_of_unnameable_enum(&self) -> &'static str {
+            "HelloEnum"
+        }
+    }
+}
+
+pub fn function_returning_unnameable_type() -> Unnameable1 {
+    Unnameable1
+}
+
+pub const CONSTANT_OF_UNNAMEABLE_TYPE: Unnameable2 =
+                                            Unnameable2;
+
+pub fn function_accepting_unnameable_type(_: Option<Unnameable3>) {}
+
+pub type AliasOfUnnameableType = Unnameable4;
+
+impl Unnameable1 {
+    pub fn inherent_method_returning_unnameable_type(&self) -> Unnameable5 {
+        Unnameable5
+    }
+}
+
+pub trait Tr {
+    fn trait_method_returning_unnameable_type(&self) -> Unnameable6 {
+        Unnameable6
+    }
+}
+impl Tr for Unnameable1 {}
+
+pub use inner_private_module::UnnameableEnum::NameableVariant;
+
+pub struct Struct {
+    pub field_of_unnameable_type: Unnameable7
+}
+
+pub static STATIC: Struct = Struct { field_of_unnameable_type: Unnameable7 } ;
+
+impl UnnameableTrait for AliasOfUnnameableType {
+    type Alias = Unnameable8;
+}
+
+pub fn generic_function<T: UnnameableTrait>() -> T::Alias {
+    Default::default()
+}
diff --git a/src/test/run-pass/issue-16734.rs b/src/test/run-pass/issue-16734.rs
deleted file mode 100644 (file)
index 80225c9..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// aux-build:issue-16734.rs
-
-extern crate issue_16734;
-
-fn main() {
-    let res = issue_16734::public_function_returning_unnameable_type()
-                                .method_of_unnameable_type();
-    assert_eq!(res, "Hello!");
-}
diff --git a/src/test/run-pass/reachable-unnameable-items.rs b/src/test/run-pass/reachable-unnameable-items.rs
new file mode 100644 (file)
index 0000000..88d3f16
--- /dev/null
@@ -0,0 +1,42 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:reachable-unnameable-items.rs
+
+#![feature(braced_empty_structs)]
+#![feature(recover)]
+
+extern crate reachable_unnameable_items;
+use reachable_unnameable_items::*;
+
+fn main() {
+    let res1 = function_returning_unnameable_type().method_of_unnameable_type1();
+    let res2 = CONSTANT_OF_UNNAMEABLE_TYPE.method_of_unnameable_type2();
+    let res4 = AliasOfUnnameableType{}.method_of_unnameable_type4();
+    let res5 = function_returning_unnameable_type().inherent_method_returning_unnameable_type().
+                                                    method_of_unnameable_type5();
+    let res6 = function_returning_unnameable_type().trait_method_returning_unnameable_type().
+                                                    method_of_unnameable_type6();
+    let res7 = STATIC.field_of_unnameable_type.method_of_unnameable_type7();
+    let res8 = generic_function::<AliasOfUnnameableType>().method_of_unnameable_type8();
+    let res_enum = NameableVariant.method_of_unnameable_enum();
+    assert_eq!(res1, "Hello1");
+    assert_eq!(res2, "Hello2");
+    assert_eq!(res4, "Hello4");
+    assert_eq!(res5, "Hello5");
+    assert_eq!(res6, "Hello6");
+    assert_eq!(res7, "Hello7");
+    assert_eq!(res8, "Hello8");
+    assert_eq!(res_enum, "HelloEnum");
+
+    let none = None;
+    function_accepting_unnameable_type(none);
+    let _guard = std::panic::recover(|| none.unwrap().method_of_unnameable_type3());
+}
diff --git a/src/test/run-pass/reachable-unnameable-type-alias.rs b/src/test/run-pass/reachable-unnameable-type-alias.rs
new file mode 100644 (file)
index 0000000..5d0c6df
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(staged_api)]
+#![stable(feature = "a", since = "b")]
+
+mod inner_private_module {
+    // UnnameableTypeAlias isn't marked as reachable, so no stability annotation is required here
+    pub type UnnameableTypeAlias = u8;
+}
+
+#[stable(feature = "a", since = "b")]
+pub fn f() -> inner_private_module::UnnameableTypeAlias {
+    0
+}
+
+fn main() {}