summaryrefslogtreecommitdiffstats
path: root/tests/ui/definition-reachable
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/definition-reachable
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/definition-reachable')
-rw-r--r--tests/ui/definition-reachable/auxiliary/field-method-macro.rs23
-rw-r--r--tests/ui/definition-reachable/auxiliary/nested-fn-macro.rs11
-rw-r--r--tests/ui/definition-reachable/auxiliary/private-use-macro.rs11
-rw-r--r--tests/ui/definition-reachable/field-method.rs11
-rw-r--r--tests/ui/definition-reachable/nested-fn.rs11
-rw-r--r--tests/ui/definition-reachable/private-non-types.rs21
-rw-r--r--tests/ui/definition-reachable/private-types.rs19
-rw-r--r--tests/ui/definition-reachable/private-use.rs10
8 files changed, 117 insertions, 0 deletions
diff --git a/tests/ui/definition-reachable/auxiliary/field-method-macro.rs b/tests/ui/definition-reachable/auxiliary/field-method-macro.rs
new file mode 100644
index 000000000..30ba70bdf
--- /dev/null
+++ b/tests/ui/definition-reachable/auxiliary/field-method-macro.rs
@@ -0,0 +1,23 @@
+#![feature(decl_macro)]
+
+mod n {
+ pub struct B(pub(crate) p::C);
+ impl B {
+ pub fn new() -> Self {
+ B(p::C)
+ }
+ }
+ mod p {
+ pub struct C;
+
+ impl C {
+ pub fn foo(&self) -> i32 {
+ 33
+ }
+ }
+ }
+}
+
+pub macro m() {
+ n::B::new().0.foo()
+}
diff --git a/tests/ui/definition-reachable/auxiliary/nested-fn-macro.rs b/tests/ui/definition-reachable/auxiliary/nested-fn-macro.rs
new file mode 100644
index 000000000..a39e8c986
--- /dev/null
+++ b/tests/ui/definition-reachable/auxiliary/nested-fn-macro.rs
@@ -0,0 +1,11 @@
+#![feature(decl_macro)]
+
+mod n {
+ pub(crate) mod p {
+ pub fn f() -> i32 { 12 }
+ }
+}
+
+pub macro m() {
+ n::p::f()
+}
diff --git a/tests/ui/definition-reachable/auxiliary/private-use-macro.rs b/tests/ui/definition-reachable/auxiliary/private-use-macro.rs
new file mode 100644
index 000000000..4f283d9c1
--- /dev/null
+++ b/tests/ui/definition-reachable/auxiliary/private-use-macro.rs
@@ -0,0 +1,11 @@
+#![feature(decl_macro)]
+
+mod n {
+ pub static S: i32 = 57;
+}
+
+use n::S;
+
+pub macro m() {
+ S
+}
diff --git a/tests/ui/definition-reachable/field-method.rs b/tests/ui/definition-reachable/field-method.rs
new file mode 100644
index 000000000..60e895a2f
--- /dev/null
+++ b/tests/ui/definition-reachable/field-method.rs
@@ -0,0 +1,11 @@
+// Check that functions accessible through a field visible to a macro are
+// considered reachable
+
+// aux-build:nested-fn-macro.rs
+// run-pass
+
+extern crate nested_fn_macro;
+
+fn main() {
+ assert_eq!(nested_fn_macro::m!(), 12);
+}
diff --git a/tests/ui/definition-reachable/nested-fn.rs b/tests/ui/definition-reachable/nested-fn.rs
new file mode 100644
index 000000000..b665b049f
--- /dev/null
+++ b/tests/ui/definition-reachable/nested-fn.rs
@@ -0,0 +1,11 @@
+// Check that functions visible to macros through paths with >2 segments are
+// considered reachable
+
+// aux-build:field-method-macro.rs
+// run-pass
+
+extern crate field_method_macro;
+
+fn main() {
+ assert_eq!(field_method_macro::m!(), 33);
+}
diff --git a/tests/ui/definition-reachable/private-non-types.rs b/tests/ui/definition-reachable/private-non-types.rs
new file mode 100644
index 000000000..a601dabcb
--- /dev/null
+++ b/tests/ui/definition-reachable/private-non-types.rs
@@ -0,0 +1,21 @@
+// Check that we don't require stability annotations for private modules,
+// imports and fields that are accessible to opaque macros.
+
+// check-pass
+
+#![feature(decl_macro, staged_api)]
+#![stable(feature = "test", since = "1.0.0")]
+
+extern crate std as local_std;
+use local_std::marker::Copy as LocalCopy;
+mod private_mod {
+ #[stable(feature = "test", since = "1.0.0")]
+ pub struct A {
+ pub(crate) f: i32,
+ }
+}
+
+#[stable(feature = "test", since = "1.0.0")]
+pub macro m() {}
+
+fn main() {}
diff --git a/tests/ui/definition-reachable/private-types.rs b/tests/ui/definition-reachable/private-types.rs
new file mode 100644
index 000000000..02c1224f4
--- /dev/null
+++ b/tests/ui/definition-reachable/private-types.rs
@@ -0,0 +1,19 @@
+// Check that type privacy is taken into account when considering reachability
+
+// check-pass
+
+#![feature(decl_macro, staged_api)]
+#![stable(feature = "test", since = "1.0.0")]
+
+// Type privacy should prevent use of these in other crates, so we shouldn't
+// need a stability annotation.
+fn private_function() {}
+struct PrivateStruct { f: () }
+enum PrivateEnum { V }
+union PrivateUnion { g: () }
+trait PrivateTrait {}
+
+#[stable(feature = "test", since = "1.0.0")]
+pub macro m() {}
+
+fn main() {}
diff --git a/tests/ui/definition-reachable/private-use.rs b/tests/ui/definition-reachable/private-use.rs
new file mode 100644
index 000000000..02cff0475
--- /dev/null
+++ b/tests/ui/definition-reachable/private-use.rs
@@ -0,0 +1,10 @@
+// Check that private use statements can be used by
+
+// run-pass
+// aux-build:private-use-macro.rs
+
+extern crate private_use_macro;
+
+fn main() {
+ assert_eq!(private_use_macro::m!(), 57);
+}